我正在使用face_detection
,OpenCV
,Arduino
和Processing
制作项目。不过,我也遇到了一些问题。
代码是正确的,但编译后,我的笔记本电脑的摄像头看不到任何脸,只有黑暗的窗口。
'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 );
}
输出是黑色窗口。为什么会这样?这是我的输出图像
发布于 2018-04-06 02:49:52
我从未在OpenCV
中使用过Processing
,但我认为您在opencv.capture
部分遗漏了一些东西,因为我看到您没有指定任何关于视频流源的内容。
这里是一个实时摄像头测试的代码.它通过了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();
}
我想这会有帮助的!
https://stackoverflow.com/questions/49690626
复制相似问题