- int index, c;
- //int opterr=0, optopt=0, optind=0;
- //char *optarg;
- // int getopt(int argc, char **argv, const char *options);
- opterr = 0;
- const char *options = "c:";
- while((c = getopt(argc, argv, options)) != -1)
- switch(c)
- {
- case 'c':
- cascade_filename = string(optarg);
- printf("option c, argument = %s\n", optarg);
- case '?':
- if(optopt == 'c')
- printf("option -%c requires an argument.\n", optopt);
- else if(isprint (optopt))
- printf("unknown option `-%c'.\n", optopt);
- else
- printf("unknown option char `\\x%x'.\n", optopt);
- goto known_args_processed;
- default:
- abort();
- }
-known_args_processed:
-
- for(index = optind; index < argc; index++)
- printf("Non-option arg %s\n", argv[index]);
-
- return 0;
+ int index, c;
+ opterr = 0;
+ const char *options = "vc:\x0";
+ while((c = getopt(argc, argv, options)) != -1)
+ {
+ switch(c)
+ {
+ case 'v': verbose = 1; break;
+ case 'c': cascade_filename = string(optarg); break;
+ case '?':
+ if(optopt == 'c')
+ {
+ printf("option -%c requires an argument.\n", optopt);
+ }
+ else if(isprint (optopt))
+ {
+ printf("unknown option `-%c'.\n", optopt);
+ }
+ else
+ {
+ printf("unknown option char `\\x%x'.\n", optopt);
+ }
+ break;
+ case '\x0': break; //ignore. not sure why this shows up. maybe zsh?
+ default: abort();
+ }
+ }
+
+ for(index = optind; index < argc; index++)
+ printf("Non-option arg %s\n", argv[index]);
+
+ if(cascade_filename == "")
+ {
+ printf("you must supply a filename with -c option. example:\n");
+ printf(
+ "%s -c %s\n",
+ argv[0],
+ "/usr/share/opencv/haarcascades/haarcascade_frontalface_alt.xml"
+ );
+ return 1;
+ }
+ if(verbose) printf("SILENT ALARM ACTIVATED!!!\n");
+ return 0;
+}
+
+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(!(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);
+
+ //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;