为什么face_detection处理示例不起作用?

时间:2015-08-22 15:40:12

标签: java opencv arduino processing

我目前正在尝试关注面部检测的this教程。 据我所知,我确信我的opencv依赖是正确的。 当我从opencv处理示例运行face_detection示例时,我收到以下错误消息:

Display -1 does not exist, using the default display instead.
Exception in thread "Animation Thread" java.lang.NoSuchMethodError: processing.core.PApplet.registerMethod(Ljava/lang/String;Ljava/lang/Object;)V
at hypermedia.video.OpenCV.<init>(OpenCV.java:297)
at face_detection.setup(face_detection.java:39)
at processing.core.PApplet.handleDraw(Unknown Source)
at processing.core.PApplet.run(Unknown Source)
at java.lang.Thread.run(Thread.java:662)

这只是我的网络摄像头无法识别吗?我不明白错误信息,而且几个小时试图落后于它并没有让我走得太远。 我正在使用opencv 1.0并处理1.5.1。

这里是face_detection示例代码:

import hypermedia.video.*;
import java.awt.Rectangle;


OpenCV opencv;

// contrast/brightness values
int contrast_value    = 0;
int brightness_value  = 0;



void setup() {

    size( 320, 240 );

    opencv = new OpenCV( this );
    opencv.capture( width, height );                   // open video stream
    opencv.cascade( OpenCV.CASCADE_FRONTALFACE_ALT );  // load detection description, here-> front face detection : "haarcascade_frontalface_alt.xml"


    // print usage
    println( "Drag mouse on X-axis inside this sketch window to change contrast" );
    println( "Drag mouse on Y-axis inside this sketch window to change brightness" );

}


public void stop() {
    opencv.stop();
    super.stop();
}



void draw() {

    // grab a new frame
    // and convert to gray
    opencv.read();
    opencv.convert( GRAY );
    opencv.contrast( contrast_value );
    opencv.brightness( brightness_value );

    // proceed detection
    Rectangle[] faces = opencv.detect( 1.2, 2, OpenCV.HAAR_DO_CANNY_PRUNING, 40, 40 );

    // display the image
    image( opencv.image(), 0, 0 );

    // draw face area(s)
    noFill();
    stroke(255,0,0);
    for( int i=0; i<faces.length; i++ ) {
        rect( faces[i].x, faces[i].y, faces[i].width, faces[i].height ); 
    }
}



/**
 * Changes contrast/brigthness values
 */
void mouseDragged() {
    contrast_value   = (int) map( mouseX, 0, width, -128, 128 );
    brightness_value = (int) map( mouseY, 0, width, -128, 128 );
}

1 个答案:

答案 0 :(得分:1)

让我们从错误开始:

  

线程“动画线程”中的异常java.lang.NoSuchMethodError:   processing.core.PApplet.registerMethod(Ljava /郎/字符串; Ljava /郎/对象;)V   在hypermedia.video.OpenCV。(OpenCV.java:297)

看起来这个OpenCV Processing包装器正在调用Processing的registerMethod()并且核心库没有它。与您正在使用的Processing版本和Hypermedia OpenCV包装器可能存在不兼容问题。请记住,这个包装器现在已经很老了。

我建议使用Greg Borenstein's OpenCV Processing library,您可以通过 Sketch&gt;轻松安装在Processing 2+中。导入库...&gt;添加库... 并搜索 OpenCV for Processing 。 库完成安装后,您应该能够运行FaceDetection示例。