gpt4 book ai didi

opencv - 我下载了用于处理的 OpenCV 库,但无法运行示例

转载 作者:太空宇宙 更新时间:2023-11-03 23:17:30 25 4
gpt4 key购买 nike

我根据我在这篇文章中提出的问题的建议下载了用于处理的 OpenCV 库:How do I install the openCV library for the Arduino IDE?

但是,除了“LiveCamTest”示例之外,我无法运行任何示例程序。在诸如此类的任何其他示例中:

import gab.opencv.*;

PImage src, dst;
OpenCV opencv;

ArrayList<Contour> contours;
ArrayList<Contour> polygons;

void setup() {
src = loadImage("test.jpg");
size(src.width, src.height/2);
opencv = new OpenCV(this, src);

opencv.gray();
opencv.threshold(70);
dst = opencv.getOutput();

contours = opencv.findContours();
println("found " + contours.size() + " contours");
}

void draw() {
scale(0.5);
image(src, 0, 0);
image(dst, src.width, 0);

noFill();
strokeWeight(3);

for (Contour contour : contours) {
stroke(0, 255, 0);
contour.draw();

stroke(255, 0, 0);
beginShape();
for (PVector point : contour.getPolygonApproximation().getPoints()) {
vertex(point.x, point.y);
}
endShape();
}
}

我收到错误消息:无法根据您的代码确定此草图的大小。谁能告诉我如何使这些示例起作用?谢谢。

最佳答案

您不能使用 setup() 函数中的变量调用 size() 函数。所以这行不通:

void setup() {
src = loadImage("test.jpg");
size(src.width, src.height/2);

您不能根据这样的图像尺寸绘制草图。您需要改用硬编码值。

您可能还想查看处理 3 中添加的 settings() 函数。来自 the reference :

The settings() function is new with Processing 3.0. It's not needed in most sketches. It's only useful when it's absolutely necessary to define the parameters to size() with a variable. Alternately, the settings() function is necessary when using Processing code outside of the Processing Development Environment (PDE). For example, when using the Eclipse code editor, it's necessary to use settings() to define the size() and smooth() values for a sketch..

The settings() method runs before the sketch has been set up, so other Processing functions cannot be used at that point. For instance, do not use loadImage() inside settings(). The settings() method runs "passively" to set a few variables, compared to the setup() command that call commands in the Processing API.

顺便说一下,这些问题与 C++ 无关,因此您可能希望停止使用 标记它们标签。

关于opencv - 我下载了用于处理的 OpenCV 库,但无法运行示例,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36878041/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com