{
if(verbose)printf("\t\tpoking\n");
reset_idle_time();
- system("gnome-screensaver-command --poke");
}
saw_last_time = 1;
}
return 0;
}
-void get_frames(CvCapture* capture, CvHaarClassifierCascade* cascade)
+int get_frames(CvCapture* capture, CvHaarClassifierCascade* cascade)
{
+ int got_null_frame = 0;
IplImage* frame = NULL;
get_one_frame(capture, frame);
IplImage* mirrored =
cvCreateImage(cvGetSize(frame), frame->depth, frame->nChannels);
// Show the image captured from the camera in the window and repeat
- while(1) {
- if(get_one_frame(capture, frame)) break;
-
- //flip the image so displayed right/left corresponds to physical right/left
- cvFlip(frame, mirrored, MIRROR);
+ while(!(got_null_frame = get_one_frame(capture, frame)))
+ {
+ //so displayed right/left corresponds to physical right/left:
+ cvFlip(frame, mirrored, MIRROR);
- detect_and_draw_objects(mirrored, cascade, 1);
- cvShowImage("mywindow", mirrored);
- // Do not release the frame!
- //screensave(t_current);
+ detect_and_draw_objects(mirrored, cascade, 1);
+ cvShowImage("mywindow", mirrored);
+ // Do not release the frame!
+ //screensave(t_current);
- //If ESC key pressed, Key=0x10001B under OpenCV 0.9.7(linux version),
- //remove higher bits using AND operator
- if((cvWaitKey(100) & 255) == 27) break;
- }
+ //If ESC key pressed, Key=0x10001B under OpenCV 0.9.7(linux version),
+ //remove higher bits using AND operator
+ if((cvWaitKey(100) & 255) == 27) break;
+ }
cvReleaseImage(&mirrored);
+ return got_null_frame;
}
int do_capture()
{
+ int got_null_capture = 0;
CvHaarClassifierCascade* cascade =
load_object_detector(cascade_filename.c_str());
CvCapture* capture = cvCaptureFromCAM(CV_CAP_ANY);
if(!capture) {
cerr << "ERROR: capture is NULL " << endl;
- getchar();
- return -1;
+ return 1;
}
// Create a window in which the captured images will be presented
cvNamedWindow("mywindow", CV_WINDOW_AUTOSIZE);
t_current = time(NULL);
- get_frames(capture, cascade);
+ while(get_frames(capture, cascade))
+ {
+ cerr << "resetting capture." << endl;
+ cvReleaseCapture( &capture );
+ capture = cvCaptureFromCAM( CV_CAP_ANY );
+ if(!capture)
+ {
+ got_null_capture = 1;
+ break;
+ }
+ }
// Release the capture device housekeeping
- cvReleaseCapture(&capture);
+ if(!got_null_capture)
+ {
+ cvReleaseCapture(&capture);
+ }
cvDestroyWindow("mywindow");
- return 0;
+ return got_null_capture;
}
int get_one_frame(CvCapture* capture, IplImage* &frame)
{
+ int got_null_frame = 0;
frame = cvQueryFrame(capture);
- if(!frame) {
- cerr << "ERROR: frame is null..." << endl;
- getchar();
- return 1;
- }
- return 0;
+ if(!frame)
+ {
+ cerr << "ERROR: frame is null..., trying again" << endl;
+ frame = cvQueryFrame(capture);
+ if(!frame)
+ {
+ cerr << "ERROR: frame is still null... maybe reset capture?" << endl;
+ got_null_frame = 1;
+ }
+ }
+ return got_null_frame;
}
// A Simple Camera Capture Framework.