int main(int argc, char **argv) { CvCapture *capture = 0; IplImage *frame = 0; CvSeq *faces = 0; FILE *out_fp = 0; char key_pressed = 0; int prev_faces = 0; int delay_mili = 0; int n; clock_t start,end; /* for measuring fps */ distance_range distances[MAX_FACES]; check_cli(argc,argv); printf("Registering camera input...\n"); if( ( capture = cvCreateCameraCapture( CAM_DEV_NUM ) ) == NULL ) { printf("Can't connect to the camera!\n"); exit(1); } printf("Loading face classifier data...\n"); cascade = ( CvHaarClassifierCascade *) cvLoad( haar_data_file, 0, 0, 0 ); if( cascade == NULL ) { printf("Can't load classifier data!\n"); exit(1); } printf("Initializating font...\n"); cvInitFont(&font, CV_FONT_HERSHEY_PLAIN, 1.0, 1.0, 0.0 ); printf("Opening output file...\n"); if( (out_fp = fopen(output_file,"w")) == NULL ) { printf("Can't open output file: %s\n",output_file ); usage(argv[0]); return -1; } /* Allocate calculation memory pool */ storage = cvCreateMemStorage(0); /* Create display window */ if(!no_gui) cvNamedWindow( WINDOW_NAME, CV_WINDOW_AUTOSIZE ); while(1) { start = clock(); frame = cvQueryFrame( capture ); if(!frame) break; /* Get all the faces on the current frame */ faces = detect_faces(frame); /* * Differren number of faces detected, make sure it's not a * single frame mistake (they happen randomly). */ if( faces->total != prev_faces && faces->total > 0) { /* reopen file to clear it */ fclose(out_fp); out_fp = fopen(output_file, "w"); prev_faces = faces->total; continue; } /* * Get distances between faces and the camera */ n = get_distances(faces, distances); write_to_file(out_fp, distances, n); /* * Draw the result on the screen */ if(!no_gui) { select_faces(frame, faces); draw_distances(frame, faces); draw_fps(frame,actual_fps); cvShowImage(WINDOW_NAME, frame); } /* * Count the delay time to get wanted number of FPS. Time of execution * of previous functions has to be considered. */ end = clock(); delay_mili = (1/(double)wanted_fps)*1000; delay_mili-= (int)(end-start)/(double)CLOCKS_PER_SEC*1000; if(delay_mili < MIN_FRAME_DELAY ) delay_mili = MIN_FRAME_DELAY; /* * Check if the close button was pressed */ key_pressed = cvWaitKey( delay_mili ) ; if( key_pressed == CLOSE_BUTTON) break; end = clock(); actual_fps = (int)round(1/((double)(end-start)/(double)CLOCKS_PER_SEC)); } cvReleaseCapture( & capture ); if(!no_gui) cvDestroyWindow( WINDOW_NAME ); fclose(out_fp); free_camera_data(); return 0; }
unsigned long vms_zip_cmdline (int *argc_p, char ***argv_p) { /* ** Routine: vms_zip_cmdline ** ** Function: ** ** Parse the DCL command line and create a fake argv array to be ** handed off to Zip. ** ** NOTE: the argv[] is built as we go, so all the parameters are ** checked in the appropriate order!! ** ** Formal parameters: ** ** argc_p - Address of int to receive the new argc ** argv_p - Address of char ** to receive the argv address ** ** Calling sequence: ** ** status = vms_zip_cmdline (&argc, &argv); ** ** Returns: ** ** SS$_NORMAL - Success. ** SS$_INSFMEM - A malloc() or realloc() failed ** SS$_ABORT - Bad time value ** */ register unsigned long status; char options[48]; char *the_cmd_line; /* buffer for argv strings */ unsigned long cmdl_size; /* allocated size of buffer */ unsigned long cmdl_len; /* used size of buffer */ char *ptr; int x, len; int new_argc; char **new_argv; struct dsc$descriptor_d work_str; struct dsc$descriptor_d foreign_cmdline; init_dyndesc(work_str); init_dyndesc(foreign_cmdline); /* ** See if the program was invoked by the CLI (SET COMMAND) or by ** a foreign command definition. Check for /YYZ_ZIP, which is a ** valid default qualifier solely for this test. */ show_VMSCLI_help = TRUE; status = check_cli(&cli_yyz); if (!(status & 1)) { lib$get_foreign(&foreign_cmdline); /* ** If nothing was returned or the first character is a "-", then ** assume it's a UNIX-style command and return. */ if (foreign_cmdline.dsc$w_length == 0) return (SS$_NORMAL); if ((*(foreign_cmdline.dsc$a_pointer) == '-') || ((foreign_cmdline.dsc$w_length > 1) && (*(foreign_cmdline.dsc$a_pointer) == '"') && (*(foreign_cmdline.dsc$a_pointer + 1) == '-'))) { show_VMSCLI_help = FALSE; return (SS$_NORMAL); } str$concat(&work_str, &zip_command, &foreign_cmdline); status = cli$dcl_parse(&work_str, &zip_clitable, lib$get_input, lib$get_input, 0); if (!(status & 1)) return (status); } /* ** There's always going to be a new_argv[] because of the image name. */ if ((the_cmd_line = (char *) malloc(cmdl_size = ARGBSIZE_UNIT)) == NULL) return (SS$_INSFMEM); strcpy(the_cmd_line, "zip"); cmdl_len = sizeof("zip"); /* ** First, check to see if any of the regular options were specified. */ options[0] = '-'; ptr = &options[1]; /* Point to temporary buffer */ /* ** Delete the specified files from the zip file? */ status = cli$present(&cli_delete); if (status & 1) *ptr++ = 'd'; /* ** Freshen (only changed files). */ status = cli$present(&cli_freshen); if (status & 1) *ptr++ = 'f'; /* ** Delete the files once they've been added to the zip file. */ status = cli$present(&cli_move); if (status & 1) *ptr++ = 'm'; /* ** Add changed and new files. */ status = cli$present(&cli_update); if (status & 1) *ptr++ = 'u'; /* ** Check for the compression level (-0 through -9). */ status = cli$present(&cli_level); if (status & 1) { unsigned long binval; status = cli$get_value(&cli_level, &work_str); status = ots$cvt_tu_l(&work_str, &binval); if (!(status & 1) || (binval > 9)) { return (SS$_ABORT); } *ptr++ = binval + '0'; } /* ** Adjust offsets of zip archive entries. */ status = cli$present(&cli_adjust); if (status & 1) *ptr++ = 'A'; /* ** Add comments? */ status = cli$present(&cli_comments); if (status & 1) { /* while ((status = cli$get_value(&cli_comments, &work_str)) & 1) { if (strncmp(work_str.dsc$a_pointer,"ZIP",3) == 0) *ptr++ = 'z'; if (strncmp(work_str.dsc$a_pointer,"FIL",3) == 0) *ptr++ = 'c'; } */ if ((status = cli$present(&cli_comment_zipfile)) & 1) *ptr++ = 'z'; if ((status = cli$present(&cli_comment_files)) & 1) *ptr++ = 'c'; } /* ** Do not add/modify directory entries. */ status = cli$present(&cli_dirnames); if (!(status & 1)) *ptr++ = 'D'; /* ** Encrypt? */ status = cli$present(&cli_encrypt); if (status & 1) if ((status = cli$get_value(&cli_encrypt, &work_str)) & 1) { x = cmdl_len; cmdl_len += work_str.dsc$w_length + 4; CHECK_BUFFER_ALLOCATION(the_cmd_line, cmdl_size, cmdl_len) strcpy(&the_cmd_line[x], "-P"); strncpy(&the_cmd_line[x+3], work_str.dsc$a_pointer, work_str.dsc$w_length); the_cmd_line[cmdl_len-1] = '\0'; } else { *ptr++ = 'e'; } /* ** Fix the zip archive structure. */ status = cli$present(&cli_fix_archive); if (status & 1) { *ptr++ = 'F'; if ((status = cli$present(&cli_fix_full)) & 1) { *ptr++ = 'F'; } } /* ** Append (allow growing of existing zip file). */ status = cli$present(&cli_append); if (status & 1) *ptr++ = 'g'; /* ** Show the help. */ status = cli$present(&cli_help); if (status & 1) *ptr++ = 'h'; /* ** Junk path names (directory specs). */ status = cli$present(&cli_junk); if (status & 1) *ptr++ = 'j'; /* ** Simulate zip file made by PKZIP. */ status = cli$present(&cli_pkzip); if (status & 1) *ptr++ = 'k'; /* ** Translate end-of-line. */ status = cli$present(&cli_translate_eol); if (status & 1) { *ptr++ = 'l'; if ((status = cli$present(&cli_transl_eol_crlf)) & 1) { *ptr++ = 'l'; } } /* ** Show the software license. */ status = cli$present(&cli_license); if (status & 1) *ptr++ = 'L'; /* ** Set zip file time to time of latest file in it. */ status = cli$present(&cli_latest); if (status & 1) *ptr++ = 'o'; /* ** Store full path (default). */ status = cli$present(&cli_full_path); if (status == CLI$_PRESENT) *ptr++ = 'p'; else if (status == CLI$_NEGATED) *ptr++ = 'j'; /* ** Junk Zipfile prefix (SFX stub etc.). */ status = cli$present(&cli_unsfx); if (status & 1) *ptr++ = 'J'; /* ** Recurse through subdirectories. */ status = cli$present(&cli_recurse); if (status & 1) { if ((status = cli$present(&cli_recurse_fnames)) & 1) *ptr++ = 'R'; else *ptr++ = 'r'; } /* ** Be verbose. */ status = cli$present(&cli_verbose); if (status & 1) { int i; int verbo = 0; /* /VERBOSE */ if ((status = cli$present(&cli_verbose_command)) & 1) { /* /VERBOSE = COMMAND */ verbose_command = 1; } /* Note that any or all of the following options may be specified, and the maximum one is used. */ if ((status = cli$present(&cli_verbose_normal)) & 1) /* /VERBOSE [ = NORMAL ] */ verbo = 1; if ((status = cli$present(&cli_verbose_more)) & 1) /* /VERBOSE = MORE */ verbo = 2; if ((status = cli$present(&cli_verbose_debug)) & 1) { /* /VERBOSE = DEBUG */ verbo = 3; } for (i = 0; i < verbo; i++) *ptr++ = 'v'; } /* ** Quiet mode. ** (Quiet mode is processed after verbose, because a "-v" modifier ** resets "noisy" to 1.) */ status = cli$present(&cli_quiet); if (status & 1) *ptr++ = 'q'; /* ** Suppress creation of any extra field. */ status = cli$present(&cli_extra_fields); if (!(status & 1)) *ptr++ = 'X'; /* ** Save the VMS file attributes (and all allocated blocks?). */ status = cli$present(&cli_vms); if (status & 1) { /* /VMS */ *ptr++ = 'V'; if ((status = cli$present(&cli_vms_all)) & 1) { /* /VMS = ALL */ *ptr++ = 'V'; } } /* ** Keep the VMS version number as part of the file name when stored. */ status = cli$present(&cli_keep_version); if (status & 1) *ptr++ = 'w'; /* ** `Batch' processing: read filenames to archive from stdin ** or the specified file. */ status = cli$present(&cli_batch); if (status & 1) { status = cli$get_value(&cli_batch, &work_str); if (status & 1) { work_str.dsc$a_pointer[work_str.dsc$w_length] = '\0'; if ((stdin = freopen(work_str.dsc$a_pointer, "r", stdin)) == NULL) { sprintf(errbuf, "could not open list file: %s", work_str.dsc$a_pointer); ziperr(ZE_PARMS, errbuf); } } *ptr++ = '@'; } /* ** Now copy the final options string to the_cmd_line. */ len = ptr - &options[0]; if (len > 1) { options[len] = '\0'; x = cmdl_len; cmdl_len += len + 1; CHECK_BUFFER_ALLOCATION(the_cmd_line, cmdl_size, cmdl_len) strcpy(&the_cmd_line[x], options); } /* ** ** OK. We've done all the regular options, so check for -b (temporary ** file path), -t (exclude before time), -n (special suffixes), zipfile, ** files to zip, and exclude list. ** */ status = cli$present(&cli_temp_path); if (status & 1) { status = cli$get_value(&cli_temp_path, &work_str); x = cmdl_len; cmdl_len += work_str.dsc$w_length + 4; CHECK_BUFFER_ALLOCATION(the_cmd_line, cmdl_size, cmdl_len) strcpy(&the_cmd_line[x], "-b"); strncpy(&the_cmd_line[x+3], work_str.dsc$a_pointer, work_str.dsc$w_length); the_cmd_line[cmdl_len-1] = '\0'; } /* ** Demand that all input files exist (and wildcards match something). */ #define OPT_MM "-MM" /* Input file specs must exist. */ status = cli$present(&cli_must_match); if (status & 1) { x = cmdl_len; cmdl_len += strlen( OPT_MM)+ 1; CHECK_BUFFER_ALLOCATION(the_cmd_line, cmdl_size, cmdl_len) strcpy( &the_cmd_line[ x], OPT_MM); } /* ** Handle "-t mmddyyyy". */ status = cli$present(&cli_since); if (status & 1) { char since_time[9]; status = get_time(&cli_since, &since_time[0]); if (!(status & 1)) return (status); /* ** Now let's add the option "-t mmddyyyy" to the new command line. */ x = cmdl_len; cmdl_len += (3 + 9); CHECK_BUFFER_ALLOCATION(the_cmd_line, cmdl_size, cmdl_len) strcpy(&the_cmd_line[x], "-t"); strcpy(&the_cmd_line[x+3], since_time); } /* ** Handle "-tt mmddyyyy". */ status = cli$present(&cli_before); if (status & 1) { char before_time[9]; status = get_time(&cli_before, &before_time[0]); if (!(status & 1)) return (status); /* ** Now let's add the option "-tt mmddyyyy" to the new command line. */ x = cmdl_len; cmdl_len += (4 + 9); CHECK_BUFFER_ALLOCATION(the_cmd_line, cmdl_size, cmdl_len) strcpy(&the_cmd_line[x], "-tt"); strcpy(&the_cmd_line[x+4], before_time); } /* ** Handle "-n suffix:suffix:...". (File types to store only.) */ status = cli$present(&cli_store_types); if (status & 1) { x = cmdl_len; cmdl_len += 3; CHECK_BUFFER_ALLOCATION(the_cmd_line, cmdl_size, cmdl_len) strcpy(&the_cmd_line[x], "-n"); status = get_list(&cli_store_types, &foreign_cmdline, ':', &the_cmd_line, &cmdl_size, &cmdl_len); if (!(status & 1)) return (status); } /* ** Now get the specified zip file name. */ status = cli$present(&cli_zipfile); if (status & 1) { status = cli$get_value(&cli_zipfile, &work_str); x = cmdl_len; cmdl_len += work_str.dsc$w_length + 1; CHECK_BUFFER_ALLOCATION(the_cmd_line, cmdl_size, cmdl_len) strncpy(&the_cmd_line[x], work_str.dsc$a_pointer, work_str.dsc$w_length); the_cmd_line[cmdl_len-1] = '\0'; } /* ** Run through the list of input files. */ status = cli$present(&cli_infile); if (status & 1) { status = get_list(&cli_infile, &foreign_cmdline, '\0', &the_cmd_line, &cmdl_size, &cmdl_len); if (!(status & 1)) return (status); } /* ** List file containing exclude patterns present? ("*****@*****.**") */ status = cli$present(&cli_exlist); if (status & 1) { status = cli$get_value(&cli_exlist, &work_str); x = cmdl_len; cmdl_len += work_str.dsc$w_length + 4; CHECK_BUFFER_ALLOCATION(the_cmd_line, cmdl_size, cmdl_len) strncpy(&the_cmd_line[x], "-x@", 3); strncpy(&the_cmd_line[x+3], work_str.dsc$a_pointer, work_str.dsc$w_length); the_cmd_line[cmdl_len-1] = '\0'; } /* ** Any files to exclude? ("-x file file") */ status = cli$present(&cli_exclude); if (status & 1) { x = cmdl_len; cmdl_len += 3; CHECK_BUFFER_ALLOCATION(the_cmd_line, cmdl_size, cmdl_len) strcpy(&the_cmd_line[x], "-x"); status = get_list(&cli_exclude, &foreign_cmdline, '\0', &the_cmd_line, &cmdl_size, &cmdl_len); if (!(status & 1)) return (status); } /* ** List file containing include patterns present? ("*****@*****.**") */ status = cli$present(&cli_inlist); if (status & 1) { status = cli$get_value(&cli_inlist, &work_str); x = cmdl_len; cmdl_len += work_str.dsc$w_length + 4; CHECK_BUFFER_ALLOCATION(the_cmd_line, cmdl_size, cmdl_len) strncpy(&the_cmd_line[x], "-i@", 3); strncpy(&the_cmd_line[x+3], work_str.dsc$a_pointer, work_str.dsc$w_length); the_cmd_line[cmdl_len-1] = '\0'; } /* ** Any files to include? ("-i file file") */ status = cli$present(&cli_include); if (status & 1) { x = cmdl_len; cmdl_len += 3; CHECK_BUFFER_ALLOCATION(the_cmd_line, cmdl_size, cmdl_len) strcpy(&the_cmd_line[x], "-i"); status = get_list(&cli_exclude, &foreign_cmdline, '\0', &the_cmd_line, &cmdl_size, &cmdl_len); if (!(status & 1)) return (status); } /* ** We have finished collecting the strings for the argv vector, ** release unused space. */ if ((the_cmd_line = (char *) realloc(the_cmd_line, cmdl_len)) == NULL) return (SS$_INSFMEM); /* ** Now that we've built our new UNIX-like command line, count the ** number of args and build an argv array. */ for (new_argc = 0, x = 0; x < cmdl_len; x++) if (the_cmd_line[x] == '\0') new_argc++; /* ** Allocate memory for the new argv[]. The last element of argv[] ** is supposed to be NULL, so allocate enough for new_argc+1. */ if ((new_argv = (char **) calloc(new_argc+1, sizeof(char *))) == NULL) return (SS$_INSFMEM); /* ** For each option, store the address in new_argv[] and convert the ** separating blanks to nulls so each argv[] string is terminated. */ for (ptr = the_cmd_line, x = 0; x < new_argc; x++) { new_argv[x] = ptr; ptr += strlen(ptr) + 1; } new_argv[new_argc] = NULL; #if defined(TEST) || defined(DEBUG) printf("new_argc = %d\n", new_argc); for (x = 0; x < new_argc; x++) printf("new_argv[%d] = %s\n", x, new_argv[x]); #endif /* TEST || DEBUG */ /* Show the complete UNIX command line, if requested. */ if (verbose_command != 0) { printf( " UNIX command line args (argc = %d):\n", new_argc); for (x = 0; x < new_argc; x++) printf( "%s\n", new_argv[ x]); printf( "\n"); } /* ** All finished. Return the new argc and argv[] addresses to Zip. */ *argc_p = new_argc; *argv_p = new_argv; return (SS$_NORMAL); }