代码之家  ›  专栏  ›  技术社区  ›  Bekbol

OpenCV+处理+Arduino(人脸跟踪)

  •  0
  • Bekbol  · 技术社区  · 6 年前

    我正在使用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 回复  |  直到 6 年前
        1
  •  1
  •   Pierre.Vriens Krzysztof J    6 年前

    代码截图:

    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和视频库的处理,可以使用网络摄像头实现人脸跟踪。编写此代码是为了实现该任务。