【问题标题】:I downloaded the OpenCV library for Processing, but can't run the examples我下载了用于处理的 OpenCV 库,但无法运行示例
【发布时间】:2016-04-27 00:14:25
【问题描述】:

我根据我在这篇文章中提出的问题的建议下载了用于处理的 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();
  }
}

我收到错误消息:无法从您的代码中确定此草图的大小。 谁能告诉我如何让这些例子发挥作用?谢谢。

【问题讨论】:

    标签: opencv processing


    【解决方案1】:

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

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

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

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

    settings() 函数是 Processing 3.0 的新功能。大多数草图都不需要它。仅当绝对需要使用变量将参数定义为size() 时才有用。或者,在处理开发环境 (PDE) 之外使用处理代码时,settings() 函数是必需的。例如,在使用 Eclipse 代码编辑器时,需要使用 settings() 来定义草图的 size()smooth() 值..

    settings() 方法在设置草图之前运行,因此此时无法使用其他处理功能。例如,不要在settings() 中使用loadImage()。与在处理 API 中调用命令的 setup() 命令相比,settings() 方法“被动地”运行以设置一些变量。

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-05-29
      • 1970-01-01
      • 1970-01-01
      • 2012-03-23
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多