CvMemStorage* storage = cvCreateMemStorage(0);
CvSeq* faces;
int i, scale = 1;
- static int saw_last_time = 0;
/* if the flag is specified, down-scale the input image to get a
performance boost w/o loosing quality (perhaps) */
faces = cvHaarDetectObjects(small_image, cascade, storage, 1.2, 2,
CV_HAAR_DO_CANNY_PRUNING);
- if(0 < faces->total)
+ update_idle(faces->total);
+
+ /* draw all the rectangles */
+ for(i = 0; i < faces->total; i++)
+ {
+ /* extract the rectangles only */
+ CvRect face = *(CvRect*)cvGetSeqElem(faces, i);
+ CvPoint upperLeft = cvPoint(face.x * scale, face.y * scale);
+ CvPoint bottomRight = cvPoint((face.x + face.width) * scale,
+ (face.y + face.height) * scale);
+ cvRectangle(image, upperLeft, bottomRight, CV_RGB(255,0,0), 3);
+ }
+
+ if(small_image != image)
+ cvReleaseImage(&small_image);
+ cvReleaseMemStorage(&storage);
+}
+
+void update_idle(int faces_total)
+{
+ static int saw_last_time = 0;
+
+ if(0 < faces_total)
{
t_current = time(NULL);
if(verbose)
}
}
- /* draw all the rectangles */
- for(i = 0; i < faces->total; i++)
- {
- /* extract the rectangles only */
- CvRect face = *(CvRect*)cvGetSeqElem(faces, i);
- CvPoint upperLeft = cvPoint(face.x * scale, face.y * scale);
- CvPoint bottomRight = cvPoint((face.x + face.width) * scale,
- (face.y + face.height) * scale);
- cvRectangle(image, upperLeft, bottomRight, CV_RGB(255,0,0), 3);
- }
-
- if(small_image != image)
- cvReleaseImage(&small_image);
- cvReleaseMemStorage(&storage);
}
void screensave(time_t t_current)
return 0;
}
-// A Simple Camera Capture Framework.
-int main(int argc, char** argv)
+void get_frames(CvCapture* capture, CvHaarClassifierCascade* cascade)
{
- if(parse_opts(argc, argv)) return 0;
-
- CvHaarClassifierCascade* cascade =
- load_object_detector(cascade_filename.c_str());
+ IplImage* frame = NULL;
+ get_one_frame(capture, frame);
- CvCapture* capture = cvCaptureFromCAM(CV_CAP_ANY);
- if(!capture) {
- cerr << "ERROR: capture is NULL " << endl;
- getchar();
- return -1;
- }
-
- // Create a window in which the captured images will be presented
- cvNamedWindow("mywindow", CV_WINDOW_AUTOSIZE);
-
- IplImage* frame = cvQueryFrame(capture);
- if(!frame) {
- cerr << "ERROR: frame is null..." << endl;
- getchar();
- return -1;
- }
IplImage* mirrored =
cvCreateImage(cvGetSize(frame), frame->depth, frame->nChannels);
- t_current = time(NULL);
// Show the image captured from the camera in the window and repeat
while(1) {
- // Get one frame
- frame = cvQueryFrame(capture);
- if(!frame) {
- cerr << "ERROR: frame is null..." << endl;
- getchar();
- break;
- }
+ if(get_one_frame(capture, frame)) break;
//flip the image so displayed right/left corresponds to physical right/left
cvFlip(frame, mirrored, MIRROR);
//remove higher bits using AND operator
if((cvWaitKey(100) & 255) == 27) break;
}
+ cvReleaseImage(&mirrored);
+}
+
+int do_capture()
+{
+ 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;
+ }
+
+ // Create a window in which the captured images will be presented
+ cvNamedWindow("mywindow", CV_WINDOW_AUTOSIZE);
+ t_current = time(NULL);
+ get_frames(capture, cascade);
// Release the capture device housekeeping
cvReleaseCapture(&capture);
cvDestroyWindow("mywindow");
- cvReleaseImage(&mirrored);
return 0;
}
+
+int get_one_frame(CvCapture* capture, IplImage* &frame)
+{
+ frame = cvQueryFrame(capture);
+ if(!frame) {
+ cerr << "ERROR: frame is null..." << endl;
+ getchar();
+ return 1;
+ }
+ return 0;
+}
+
+// A Simple Camera Capture Framework.
+int main(int argc, char** argv)
+{
+ if(parse_opts(argc, argv)) return 0;
+
+ return do_capture();
+}