我下载了用于处理的 OpenCV 库,但无法 运行 示例
I downloaded the OpenCV library for Processing, but can't run the examples
我根据我在这个 post 上提出的问题的建议下载了用于处理的 OpenCV 库:
但是,除了 "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++ 无关,因此您可能希望停止使用 c++ 标记来标记它们。
我根据我在这个 post 上提出的问题的建议下载了用于处理的 OpenCV 库:
但是,除了 "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 tosize()
with a variable. Alternately, thesettings()
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 usesettings()
to define thesize()
andsmooth()
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 useloadImage()
insidesettings()
. Thesettings()
method runs "passively" to set a few variables, compared to thesetup()
command that call commands in the Processing API.
顺便说一句,这些问题与 C++ 无关,因此您可能希望停止使用 c++ 标记来标记它们。