data_extraction.cc

来自「VC视频对象的跟踪提取原代码(vc视频监控源码)」· CC 代码 · 共 784 行 · 第 1/2 页

CC
784
字号
// program to extract shapes of moving blobs from video// major makeover inspired by new features in MotionDetector --- nts Feb 2001// system includes#include <cstdio>#include <gl/gl.h>#include <getopt.h>#include <climits>  // for INT_MAX// the following 3 includes are for reading keyboard input only#include <sys/ioctl.h>#include <termios.h>#include <unistd.h>   // this one also for usleep()// local includes#include "Image.h"#include "miscsrc.h"#include "RegionSet.h"#include "ProfileSet.h"#include "Grey8Image.h"#include "EnvParameter.h"#include "utils.h"#include "imgsrc_utils.h"#include "tracker_defines_types_and_helpers.h"#include "icons.h"using namespace ReadingPeopleTracker;// when the user presses '+' or '-' in/decrease threshold by this value:#define THRESHOLD_INCREASE 0.01bool kbhit (void);          // check whether key was pressedint tty_cbreak (int fd);    // put tty in cbreak (raw, !cooked) modeint tty_reset (int fd);     // restore terminal's modestatic struct termios save_stdin;extern void setup_spline_matrices();#define USAGE "usage: data_extraction [options] \n\-l run Length for median filter \n\-t differencing Threshold \n\-n No. of control points \n\-i input options (-i help for details) \n\-d don't align/ normalise shapes \n\-g gaps size for merging regions \n\-v vertical flip images \n\-m minimum blob size as proportion of image area (e.g. 0.06) \n\-p parameter_file (use file to specify parameters)\n"/* fixed globals *///  bool quiet_mode = //  Configuration.register_bool("QUIET_MODE", false,//  		      &quiet_mode, true,//  		      "main", //  		      "If set ON then don't display any images");int& default_ncp = Configuration.register_int("NO_CONTROL_POINTS", 32,		     &Profile::NO_CONTROL_POINTS, true,		     "main", 		     "The number of spline control points used to \represent each shape");static bool do_background_updating =Configuration.register_bool("UPDATE_BACKGROUND",		      true, &do_background_updating,		      true, "main",		      "Update background, using a median filter ?");int ...should be frame_id_t ... and rename to background_update_skip ...  time_skip =Configuration.register_int("BACKGROUND_UPDATE_SKIP", 1,		     &time_skip, true,		     "main",		     "Temporal resampling for background filtering");int default_window_length=Configuration.register_int("BACKGROUND_RUN_LENGTH", 50,		     &default_window_length, true,		     "main",		     "Median window length (in frames) \for background image update");bool show_background_images = Configuration.register_bool("SHOW_BACKGROUND_IMAGES",		      true, &show_background_images,		      true, "main",		      "Show the generated background images ?");bool show_difference_images = Configuration.register_bool("SHOW_DIFFERENCE_IMAGES",		      false, &show_difference_images,		      false, "main",		      "Show the differenced images foreground-background ?");bool show_thresholded_difference_images = Configuration.register_bool("SHOW_THRESHOLDED_DIFF_IMAGES",		      false, &show_thresholded_difference_images,		      false, "main",		      "Show the thresholded difference foreground-background ?");bool show_motion_images = Configuration.register_bool("SHOW_MOTION_IMAGES",		      true, &show_motion_images,		      false, "main",		      "Show the thresholded and filtered motion detection images ?");bool show_filtered_difference_images = Configuration.register_bool("SHOW_FILTERED_DIFFERENCE_IMAGES",		      true, &show_filtered_difference_images,		      true, "main",		      "Show the filtered difference images fore-background?");bool do_normalisation = Configuration.register_bool("NORMALISE",		      true, &do_normalisation,		      true, "main",		      "Normalise profiles ? (i.e. recenter using centroidand rotate principal axis to vertical");bool flip_images = Configuration.register_bool("FLIP_VERTICALLY",		      false, &flip_images,		      true, "main",		      "Vertically flip input images ?");bool default_do_blur = Configuration.register_bool("BLUR_MOTION",		      false, &default_do_blur,		      true, "main",		      "Blur images in motion detection (slow) ?");static bool skip_non_existing =Configuration.register_bool("SKIP_NON_EXISTING",		      true, &skip_non_existing,		      true, "main",		      "Shall we tolerate (skip) non-existing input files ? \Useful when you have 0000.jpg, 0007.jpg etc");int max_skip_non_existing =Configuration.register_int("MAX_SKIP_NON_EXISTING", 1024,		     &max_skip_non_existing, true,		     "main",		     "Maximum number of non-existing input files to \tolerate (skip) before assuming end of sequence");static bool new_background_after_skip =Configuration.register_bool("NEW_BACKGROUND_AFTER_SKIP",		      true, &new_background_after_skip,		      true, "main",		      "After skipping non-existing input files, take 1st valid \image as new background");/* variable globals */bool use_border_regions = Configuration.register_bool("USE_BORDER_REGIONS",		      true, &use_border_regions,		      false, "main",		      "Use regions near the image border ?");bool reduce_noise = Configuration.register_bool("REDUCE_NOISE",		      true, &reduce_noise,		      false, "main",		      "Use dilation to reduce noise (slow) ?");int gap_size = Configuration.register_int("GAP_SIZE", 1,		     &gap_size, false, "main",		     "The dilation size in pixels when filtering binary motionimage.  The effect is to join blobs that are this many pixels apart.");//  realno camera_moved_threshold = //  Configuration.register_real("CAMERA_MOVED_THRESH", 0.5,//  		      0.0, 1.0,//  		      &camera_moved_threshold,//  		      false, "main", //  		      "If the number of pixels where there is movement over//  the total number of pixels is greater than this threshold, then the camera//  has moved.");realno diff_threshold = Configuration.register_real("DETECT_DIFF_THRESH", 0.1,		      0.0, 1.0, &diff_threshold, 		      false, "main",		      "Differencing threshold for object detection");realno max_region_ratio =Configuration.register_real("MAX_REGION_SIZE", 0.5,		      &max_region_ratio,		      false, "main",		      "Maximum size of a motion blob over size of image");realno min_region_ratio = Configuration.register_real("MIN_REGION_SIZE", 0.001,		      &min_region_ratio,		      false, "main",		      "Minimum size of a motion blob over size of image");int main (int argc, char** argv){    int c;    int runlength;  // background run length        ImageSource *input;    // pipe sources    PipeSource *foreground;    PipeSource *blur_foreground;    PipeSource *background;    PipeSource *difference;    PipeSource *thresholded_difference;       // (colour) filtered sources    PipeSource *filtered_input;    PipeSource *filtered_background;    PipeSource *filtered_difference;            Profile::draw_boxes = true;    char *parameter_file = NULL;        while ((c = getopt(argc, argv, "p:m:i:dg:vl:t:n:?")) != EOF)	switch(c)	{//	case 'q'://	    quiet_mode = true;//	    break;	    	case 'p':	    parameter_file = optarg;	    break;	    	case 'm':	    if (optarg != NULL)		min_region_ratio = atof(optarg);	    break;	    	case 'i':	    input = get_live_or_movie_feed(optarg);	    break;	    	case 'd':	    do_normalisation = false;	    break;	case 'g':	    reduce_noise = true;	    if (optarg != NULL)		gap_size = atoi(optarg);	    break;	case 'v':	    flip_images = true;	    break;	case 'l':	    if (optarg != NULL)		default_window_length = atoi(optarg);	    break;	case 't':	    if (optarg != NULL)		diff_threshold = atof(optarg);	    break;	case 'n':	    if (optarg != NULL)		Profile::NO_CONTROL_POINTS = atoi(optarg);	    break;	case '?':	default:	    fprintf(stderr, USAGE);	    exit(0);	}     Configuration.parse_parameter_file(parameter_file);// nts: we are always interactive   if (!quiet_mode)    // set default icon for windows...    Configuration.set_icon(data_extraction_icon_16);    Configuration.create_interface(argc, argv);          setup_spline_matrices();    Image* reference_image = get_reference_frame();    if (flip_images)    {	ImageSource* old_in = input;	input = new VFlipSource(old_in);	if (reference_image != NULL)	    reference_image->flip_vertically(reference_image);    }    //  Set up background, either constant or medium-filtered:    if (do_background_updating)    {	runlength = default_window_length;//    / time_skip;	background = new MedianFilterSource(input, runlength, reference_image);    }    else    {	// set up constant background image	runlength = INT_MAX;	if (reference_image == NULL)	{	    fprintf(stderr, " Cannot use NULL background image and not update it. \n");	    exit(1);	}    	background = new ConstantSource(reference_image);    }        filtered_background = new ColourFilterSource(background);    filtered_input = new ColourFilterSource(input);    difference = new DifferenceSource(input, background);// 2 alternatives here://    filtered_difference = new ColourFilterSource(difference,CF_METHOD_Y_709);    filtered_difference = new DifferenceSource	(filtered_input,filtered_background);    thresholded_difference = new ThresholdSource	(filtered_difference, 255 * diff_threshold);    if (default_do_blur)  // blur foreground?    {	blur_foreground = new BlurSource(thresholded_difference);	foreground = new ThresholdSource	    (blur_foreground, 255.0 * diff_threshold);    }    else    {	foreground = new NeighbourSource(thresholded_difference, 4);	// foreground = new PipeSource(thresholded_difference);    }        foreground->set_title("Detected Foreground");   //    if (do_background_updating)//	background->get_next();  // this calls input->get_next()//    else//	input->get_next();      // ... which we need, anyway     // set up Window titles...    if (do_background_updating)	background->set_title("Median-filtered Background");    else	background->set_title("Constant Background");        filtered_background->set_title("Filtered Background");    filtered_input->set_title("Filtered Input");    difference->set_title("Difference Fore-Background");    filtered_difference->set_title("Filtered Difference");    thresholded_difference->set_title("Thresholded Difference");    input->set_title("Video Input");    blur_foreground->set_title("Blurred Foreground");    foreground->set_title("Foreground");        RegionSet curr_regions;    ProfileSet curr_profiles;    unsigned int vwidth = input->get_xdim();    unsigned int vheight = input->get_ydim();    unsigned int vsize = vwidth * vheight;    fprintf(stderr, " and ACTION! \n");    ///////////////////////////////////////////////////////////////////////////                                                                     ////       MAIN LOOP                                                     //   //                                                                     ///////////////////////////////////////////////////////////////////////////    //    bool found_some = false;    bool finished = false;         // whether user wishes to exit program    bool use_profiles = false;     // user says extracted profiles are to be used    bool frame_processed = false;  // whether current frame is processed

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?