【问题标题】:Web camera can't see any face in face_tracking project网络摄像头在 face_tracking 项目中看不到任何人脸
【发布时间】:2018-04-06 10:21:58
【问题描述】:

我正在使用OpenCVArduinoProcessing 制作项目face_detection。但是我遇到了一些问题。

代码编写正确,但编译后,我笔记本电脑的网络摄像头看不到任何人脸,只有黑窗。

'import hypermedia.video.*;
 import java.awt.Rectangle;
 import processing.video.*;
 OpenCV opencv;


 int contrast_value    = 0;
 int brightness_value  = 0;



 void setup() {

 size( 1000, 500 );

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




 void mouseDragged() {
contrast_value   = (int) map( mouseX, 0, width, -128, 128 );
brightness_value = (int) map( mouseY, 0, width, -128, 128 );
}

输出是黑色窗口。为什么会这样? Here's my output image

【问题讨论】:

  • 您能否正确格式化您的代码?没有适当的缩进很难阅读。

标签: opencv processing


【解决方案1】:

我从未将OpenCVProcessing 一起使用,但我认为您在opencv.capture 部分遗漏了一些内容,因为我看到您没有指定有关视频流来源的任何内容。

Here 是实时摄像机测试的代码...它通过了this,然后是其他内容。

我认为可以解决您的问题的代码摘录如下:

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

我认为这可能会有所帮助!

来源:OpenCV for Processing on GitHub

【讨论】:

  • 您能否在答案中包含相关的代码更改,而不是链接到其他网站?
  • 当然。顺便说一句,指向 GitHub 的代码链接对我来说似乎还不错
猜你喜欢
  • 2014-05-29
  • 2021-01-22
  • 2019-11-11
  • 2017-10-07
  • 1970-01-01
  • 2017-12-22
  • 2019-10-13
  • 2012-05-26
  • 2012-04-12
相关资源
最近更新 更多