data_extraction.cc
来自「VC视频对象的跟踪提取原代码(vc视频监控源码)」· CC 代码 · 共 784 行 · 第 1/2 页
CC
784 行
Image* check_image; // for checking availability of next image// unused Point2 object_center;// unused bool flag_center = false; frame_id_t frame_id; frame_id_t number_of_tries; // counting #tries to get next frame frame_id_t iteration_count; // how often user asks to re-process frame unsigned int min_region_size; unsigned int max_region_size; int ch; // input character read from the terminal if (skip_non_existing == false) // we should not tolerate (skip) non-existing files max_skip_non_existing = 0; tty_cbreak (STDIN_FILENO); // put terminal into cbreak (raw) mode cout << endl << Profile::NO_CONTROL_POINTS << " control points" << endl; for (frame_id = input->get_frame_id(); finished == false; frame_id = input->get_frame_id()) { // // New interactive approach to improve detection quality: // // For each frame, we do an inner loop until we have found // something and detected it properly (user presses Enter) // or we or the user are sure that there is nothing. // // Frames may be skipped; more precisely: we allow for numbered // input files to be named 0000.jpg, 0005.jpeg, 0100.jpeg etc. // The maximum difference is determined by the MAX_SKIP_NON_EXISTING variable. // This skipping can be dis/enabled using the SKIP_NON_EXISTING variable. // // User interaction output is written to stderr so stdout only // contains detection data. // ////////////////////////////////////////////////////// // // // step 1 - get next input frame // // // ////////////////////////////////////////////////////// number_of_tries = 0; do {// if ((do_background_updating) && (frame_id % time_skip) == 0)// check_image = background->get_next(); // calls input->get_next()// else// check_image = input->get_next(); // ... which we need check_image = foreground->get_next(); if ((number_of_tries++) > 1) { fprintf(stderr,"\r Scanning input for next image ... %5i", number_of_tries); fflush(stderr); } if (kbhit ()) do { switch (ch=getchar()) { case 'q': // let's exit on these characters case 'Q':// case 'x':// case 'X': case 0x1b: // (Esc) finished = true; break; default: // silently ignore all other input break; } } while (kbhit ()); // process all key strokes frame_id++; } while ((check_image == NULL) && // while we don't get an image (number_of_tries <= max_skip_non_existing) && // and we don't skip too many (! finished)); // and user does not want to exit if (number_of_tries > 2) fprintf(stderr,"\r \r"); if (check_image == NULL) // we have an exit condition { if (number_of_tries > max_skip_non_existing) { fprintf(stderr,"\n %i non-existing files in a row while looking\ for next input image. \n Assuming end of sequence. \n",number_of_tries); exit(0); } else // <=> (finished) ie user pressed Esc or 'q' { fprintf(stderr,"\n Exit on user request \n"); exit(2); } } // now we have a valid current input image. // if we skipped non-existing images we might want to restart bg if ((number_of_tries > 1) && (new_background_after_skip)) { //if (do_background_updating) input->get_current()->copy(background->get_current());#ifdef DEBUG fprintf(stderr," Images skipped, therefore background restarted in frame %i \n",frame_id);#endif } ////////////////////////////////////////////////////// // // // step 2 - process current frame // // // ////////////////////////////////////////////////////// frame_processed = false; for (iteration_count = 0; ((finished == false) && (frame_processed == false)); iteration_count++) { use_profiles = false; // profiles were not accepted, yet. if (iteration_count > 0) // we were asked to re-process frame { curr_profiles.destroy_all(); curr_regions.destroy_all(); } min_region_size = (unsigned int) (vsize * min_region_ratio); max_region_size = (unsigned int) (vsize * max_region_ratio); // re-set threshold as it might have been changed online ((ThresholdSource*) thresholded_difference) -> threshold = (unsigned char) (255.0 * diff_threshold); filtered_input->refresh(); filtered_background->refresh(); // ((ThresholdSource*) foreground)// -> threshold = (unsigned char) (255.0 * diff_threshold); difference->refresh(); filtered_difference->refresh(); thresholded_difference->refresh(); // foreground->get_next(); if (reduce_noise == true) // do dilation? { if (gap_size > 0) { Grey8Image* filled_foreground = (Grey8Image*) foreground->get_current(); filled_foreground->fix_holes(gap_size, filled_foreground); } } if (show_background_images) background->display(); if (show_difference_images) difference->display(); if (show_filtered_difference_images) filtered_difference->display(); if (show_thresholded_difference_images) thresholded_difference->display(); if (show_motion_images) foreground->display(); input->display(); input->get_current()->draw_in_image(); curr_regions.grab_regions(foreground->get_current(), min_region_size, max_region_size, use_border_regions); curr_regions.trace_regions(); curr_profiles = curr_regions.to_profiles(); curr_profiles.draw(); gflush(); // displayed current profile. Now ask user what to do.// FIXME: maybe more than one profile in image fprintf(stderr,"\r `+' and `-' to adjust threshold. Enter: accept. Space: ignore. Q: quit."); fflush(stderr); // we don't have an event handler for our windows :-( while (!(kbhit ())) // make sure displays are updated { unsigned int delay; for (delay = 0; delay < 25; delay++) { usleep(20*1000); // wait 20 msec if (kbhit ()) break; } if (delay > 24) // we have waited 500 msec for input { // refresh windows: if (show_background_images) background->display(); if (show_difference_images) difference->display(); if (show_filtered_difference_images) filtered_difference->display(); if (show_thresholded_difference_images) thresholded_difference->display(); thresholded_difference->refresh(); foreground->refresh(); if (reduce_noise == true) // do dilation? { if (gap_size > 0) { Grey8Image* filled_foreground = (Grey8Image*) foreground->get_current(); filled_foreground->fix_holes(gap_size, filled_foreground); } } if (show_motion_images) foreground->display(); input->display(); input->get_current()->draw_in_image(); curr_profiles.draw(); gflush(); } } switch (ch=getchar()) { case '\n': // Enter: profiles accepted as displayed. frame_processed = true; use_profiles = true; break; case ' ': // Space: Nothing usable in this frame frame_processed = true; use_profiles = false; break; case '+': // increase detection threshold diff_threshold += THRESHOLD_INCREASE; if (diff_threshold > 1.0) diff_threshold = 1.0; break; case '-': // decrease detection threshold diff_threshold -= THRESHOLD_INCREASE; if (diff_threshold < 0.0) diff_threshold = 0.0; break; case 'q': // let's exit on these characters case 'Q':// case 'x':// case 'X':// case 0x1b: // (Esc) finished = true; break; default: // silently ignore all other input break; } fprintf(stderr,"\r \r"); fflush(stderr); } if (finished == true) // user wishes to exit program { fprintf(stderr,"\n Exit on user request \n"); exit(2); } if ((curr_profiles.no_items > 0) && (use_profiles)) { if (do_normalisation) curr_profiles.normalise(); else curr_profiles.add_origins(); cout << "*** frame " << frame_id << " ***" << endl << curr_profiles << "********************" << endl; } curr_profiles.destroy_all(); curr_regions.destroy_all(); } return 0;}// poll the keyboard for a character// idea from The Linux Journal article of Sept 95 issue 17bool kbhit (void){ struct timeval tv; fd_set read_fd; // do not wait at all, not even a microsecond tv.tv_sec = 0; tv.tv_usec = 0; // must be done first to initilize read_fd FD_ZERO (&read_fd); // makes select() ask if input is ready: 0 is the file descriptor stdin FD_SET (0, &read_fd); // the first parameter is the number of the largest file descriptor to check+1 if (select (1, &read_fd, NULL, // NO writes NULL, // NO exceptions &tv) == -1) return false; // An error occurred // read_fd now holds a bitmap of files that are readable. // We test the entry for the standardinput (file 0). if (FD_ISSET (0, &read_fd)) // character pending on stdin return true; // no charcaters were pending return false;}// from W Richard Steven's book// ``Advanced Programming in the Unix Environment''int tty_cbreak (int fd) // put terminal into a cbreak mode{ struct termios buf; if (fd == STDIN_FILENO) { if (tcgetattr (fd, &save_stdin) < 0) return -1; } buf = save_stdin; // structure copy buf.c_lflag &= ~(ECHO | ICANON); // echo off, canonical mode off buf.c_cc[VMIN] = 1; // Case B: 1 byte at a time, no timer buf.c_cc[VTIME] = 0; if (tcsetattr (fd, TCSAFLUSH, &buf) < 0) return -1; return 0;}int tty_reset (int fd) // restore terminal's mode{ if (fd == STDIN_FILENO) { if (tcsetattr (fd, TCSAFLUSH, &save_stdin) < 0) fprintf (stderr, "\n Failed to reset stdin \n"); return -1; } return 0;}// Local Variables:// compile-command: "cd ..; make; cd progs; make data_extraction"// End:
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?