OpenCV + Processing + Arduino(面部追踪)

时间:2018-04-10 20:03:27

标签: opencv processing

我正在使用Processing,OpenCV和Arduino进行项目人脸跟踪。我遇到了一些问题。

以下是代码:

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_ALT2 );  // 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" );
}

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 ); 
    }
}

错误就在这里:

[opencv fatal error] library not loaded !
THIS VERSION OF OPENCV LIBRARY REQUIRE ADDITIONAL DEPENDENCIES.
READ THE INSTALLATION INSTRUCTIONS AT http://ubaa.net/shared/processing/opencv/

Verify that the '\path\to\OpenCV\bin' exists in your system PATH and the java.library.path property is correctly.

error message: C:\Users\User\Documents\Processing\libraries\OpenCV\library\OpenCV.dll: Can't find dependent libraries

A library relies on native code that's not available.
Or only works properly when the sketch is run as a 64-bit  application.

我做了正确的安装,添加到路径中,我编译了它处理32位应用程序和处理64位应用程序我得到的相同错误。

1 个答案:

答案 0 :(得分:1)

代码的屏幕截图:

enter image description here

尝试该代码:

import gab.opencv.*;
import processing.video.*;
import java.awt.*;

Capture video;
OpenCV opencv;

void setup() {
  size(640, 480);
  video = new Capture(this, 640/2, 480/2);
  opencv = new OpenCV(this, 640/2, 480/2);
  opencv.loadCascade(OpenCV.CASCADE_FRONTALFACE);  

  video.start();
}

void draw() {
  scale(2);
  opencv.loadImage(video);

  image(video, 0, 0 );

  noFill();
  stroke(0, 255, 0);
  strokeWeight(3);
  Rectangle[] faces = opencv.detect();
  println(faces.length);

  for (int i = 0; i < faces.length; i++) {
    println(faces[i].x + "," + faces[i].y);
    rect(faces[i].x, faces[i].y, faces[i].width, faces[i].height);
  }
}

void captureEvent(Capture c) {
  c.read();
}

注意:使用OpenCV和视频库的处理,您可以使用网络摄像头实现面部跟踪。编写此代码是为了完成该任务。