OpenCV - NullPointerException: device error
in
Contributed Library Questions
•
2 years ago
Hi,
New to processing, new here...
It's probably a really stupid question but I read all the related topics in this forum and didn't found an answer.
I have just installed OpenCV library and I jus wanted to see how the face recognition works,
but I think something is wrong with my webcam recognition or compatibility.
When I open the example 'Face_detection' and run it without making any changes
the screen goes gray and the webcam led is still off.
Windows 7 64 bits, OpenCV 1, Processing 1.5, Webcam listed as [0] "Integrated Webcam-WDM"
So the face_detection original code is:
When I run the applet it shows the following message:
NullPointerException:
Error while starting capture : device 0
Drag mouse on X-axis inside this sketch window to change contrast
Drag mouse on Y-axis inside this sketch window to change brightness
OpenCV could not define source dimensions.
Exception in thread "Animation Thread" java.lang.NullPointerException
at processing.core.PGraphics.image(Unknown Source)
at processing.core.PApplet.image(Unknown Source)
at face_detection.draw(face_detection.java:71)
at processing.core.PApplet.handleDraw(Unknown Source)
at processing.core.PApplet.run(Unknown Source)
at java.lang.Thread.run(Thread.java:662)
Does any body know what I'm missing?
Thanks in advance!
New to processing, new here...
It's probably a really stupid question but I read all the related topics in this forum and didn't found an answer.
I have just installed OpenCV library and I jus wanted to see how the face recognition works,
but I think something is wrong with my webcam recognition or compatibility.
When I open the example 'Face_detection' and run it without making any changes
the screen goes gray and the webcam led is still off.
Windows 7 64 bits, OpenCV 1, Processing 1.5, Webcam listed as [0] "Integrated Webcam-WDM"
So the face_detection original code is:
- 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 );
}
When I run the applet it shows the following message:
NullPointerException:
Error while starting capture : device 0
Drag mouse on X-axis inside this sketch window to change contrast
Drag mouse on Y-axis inside this sketch window to change brightness
OpenCV could not define source dimensions.
Exception in thread "Animation Thread" java.lang.NullPointerException
at processing.core.PGraphics.image(Unknown Source)
at processing.core.PApplet.image(Unknown Source)
at face_detection.draw(face_detection.java:71)
at processing.core.PApplet.handleDraw(Unknown Source)
at processing.core.PApplet.run(Unknown Source)
at java.lang.Thread.run(Thread.java:662)
Does any body know what I'm missing?
Thanks in advance!
2