Face Tracking Using OpenCV and Processing (Error) [SOLVED]

UPDATE: As i said guys, when the face tracking program is launched immediately on start-up, i don't get this error, otherwise i do. Now, the program has launched, without an error, but the display output is totally black. Any suggestions guys?

I also referred to CP's solution to this same problem, ON A LAPTOP, but to no avail. I installed quicktime, and a vdig driver, but no progress till now.


Hello guys,

So i am closing in on one whole week of getting the hand of face tracking using openCV, processing and arduino. Although CP's tutorials have proved helpful along the way, the same error is always keeping me within touching distance of my goal.


Here are some specifications:

Device : Laptop ( Dell Inspiron 1545 which has a really poor graphic card, but i also tried it on Dell Inspiron 15R which has a good graphic card ) I am suspecting the laptop to be the reason behind this. I have used the Laptop's in-built webcam and an external webcam on separate occasions, disabling the in-built webcam while using the external webcam, and unplugging the external one while using the in-built webcam.

OS: i was using windows 8, which i thought was the issue, but have downgraded to win 7, and nothing has changed.

Processing version : 1.5 ( Chickenparmi got it running with this version, so i didn't try out any upgrades)

OpenCV: 1.0

I installed OpenCV, installed the libraries as well. However, the program launches without any error on startup ( if executed immediately after restarting, but still, the display output is totally black )

Upon closing all Processing windows and executing the program again, i get the error as depicted in the picture above. If it's not clear, this is what it says :

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)

I haven't tried it on a desktop. But, i don't see a fair reason as to why it should not run on a laptop. I do feel that the internal webcam is the issue though.

I am also following the face tracking tutorial available on the sparkfun website.

It's been nearly a week i have been on to this, and am looking forward to puttting and end to this here at LMR.



Don’t use processing use

Don’t use processing use python much easier to set up, but a bit harder to program

This is the code i am using

Hi guys,

This is the processing code i am using. But, it’s pretty much the same face detection code from the OpenCV processing library.

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() {

void draw() {

    // grab a new frame
    // and convert to gray
    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)
    for( int i=0; ilength; 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 );




Hey Enigmerald,

I have had this same nightmare with OpenCV --I have fought it again and again and not once have I got all the files put in the right places etc. 

I personally use pFaceDetect instead and it works like a charm. Just do a quick google for “pFaceDetect” and you will find the zip and some tutorials. --Might be a bit less frustrating.

Hello Chris! Wow, this thing

Hello Chris! Wow, this thing didn’t leave you too?

I also went the same way for the past 2 weeks, until i finally got some results yesterday. Don’t know why, but i re-installed the webcam driver, and finally it’s working. Thanks for mentioning the pFaceDetect library, will try it out as well.


Thanks for the suggestions

Thanks for the suggestions robotmaster. I need to study some more on python before i can manage to integrate it with openCV and all. Anyways, got it running finally with Processing and OpenCV.


Hey guys,It had to come to

Hey guys,

It had to come to an end here on LMR. Yes, it’s all working now. \O/

I didn’t make any major changes. But for sure, the reason why the external webcam has started tracking my face is a change in OS. I started with Windows 8 ( loads of errors , couldn’t even open the internal webcam, let alone track with an external one! ), downgraded to Windows 7 ( tracking worked out with the internal webcam, with the external one still was a problem ), and then downgraded a bit more to Windows XP, and everything is working a charm. I’ll revisit my journey and re-collect errors I encountered along the way. Hopefully, will set it all up, and post how it all went and will go. Thanks everyone who helped me on this along the way, especially lukeyes, 6677, chickenparmi, Max, Bajdi and Chris. 

Thanks guys


LMR Rocks


This issue has been resolved.

This issue has been resolved.



Hey birdmun. For now, as I

Hey birdmun. For now, as I mentioned in the comment below, downgrading of operating systems solved this issue. As lukeyes suggested, it could have been a driver issue. And a few other fixes in the discussions below. I commented “This issue has been resolved” just to make this discussion active and let others know of the [SOLVED] at the end of the forum topic because it wasn’t there before. :slight_smile: