⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 motiondetector.cc

📁 不错的shijuegezong的程序
💻 CC
字号:
/********************************************************************* * C++ source * * File : 	MotionDetector.cc * * Module :	MotionDetector * * Author : 	A M Baumberg * * Creation Date : Mon Jun 13 13:02:58 1994  * * Changes : nts: added support for external motion image source  Nov 2000 *           nts: Many, major changes.  New concept for creation of motion *                image, colour filtering techniques, pre-calculated difference *                image, dilation for motion image...   Dec 2000--Apr 2001 * *********************************************************************/// include files#ifndef NO_DISPLAY#ifdef DEBUG#include "os_specific_things.h"  // for sleep()#endif   // ifdef DEBUG#endif   // ifndef NO_DISPLAY#include "MotionDetector.h"#include "Region.h"#include "RegionSet.h"#include "Profile.h"#include "ProfileSet.h"#include "PnmSource.h"#ifdef HSV#include "HSV32Image.h"    // for HSV filtering using lookup table#endif#include "PipeSource.h"    // PipeSource class and image filters#include "Tracking.h"#include "Inputs.h"#include "Results.h"#include "text_output.h"namespace ReadingPeopleTracker{// see HSV32Image.{h,cc}// #ifdef HSV// extern void setup_HSV32_to_RGB32_lookup_table();// #endif//  not implemented yet.//  #ifdef DEBUG//  #ifndef NO_DISPLAY////  #include "MovieStore.h"   // for outputting demos////  MovieStore *motion_movie = NULL;//  MovieStore *difference_movie = NULL;////  EnvStringParameter motion_movie_name("MOTION_MOVIE_NAME");//  EnvStringParameter difference_movie_name("DIFFERENCE_MOVIE_NAME");////  Grey8Image *motion_image = NULL;//  RGB32Image *difference_image = NULL;////  #endif // ifndef NO_DISPLAY//  #endif // ifdef DEBUGvoid MotionDetector::register_configuration_variables(){    // set default values...    initial_background_image = NULL;    additional_motion_mask = NULL;    inverted_additional_motion_mask = NULL;        camera_moved_threshold = 	configuration_manager->register_real("CAMERA_MOVED_THRESH", 0.5,					     0.0, 1.0,					     &camera_moved_threshold,					     true, "MotionDetector", 					     "If the number of moving pixels over the total number of\ pixels is greater than this threshold, assume the camera has moved.");        resample_shift =	configuration_manager->register_int("MOTION_RESAMPLE_SHIFT", 2,					    (int *) &resample_shift,					    true, "MotionDetector",					    "Resample image dimensions by 2^n in motion detection");        do_background_updating =	configuration_manager->register_bool("UPDATE_BACKGROUND",					     true, &do_background_updating,					     false, "MotionDetector",					     "Update background, using a temporal median filter ?");        background_update_skip =	configuration_manager->register_int("BACKGROUND_UPDATE_SKIP", 4,					    (int *) &background_update_skip, true,					    "MotionDetector",					    "Temporal resampling for background filtering.  1 = no skipping");        diff_threshold = 	configuration_manager->register_real("DETECT_DIFF_THRESH", 0.05,					     0.0, 1.0, &diff_threshold, 					     false, "MotionDetector",					     "Differencing threshold for object detection");        background_run_length=	configuration_manager->register_int("BACKGROUND_RUN_LENGTH", 50,					    (int *) &background_run_length, true,					    "MotionDetector",					    "Median window length (in frames) for background update");        max_region_ratio =	configuration_manager->register_real("MAX_REGION_SIZE", 0.5,					     &max_region_ratio,					     false, "MotionDetector",					     "Maximum size of a motion blob over size of image");        min_region_ratio = 	configuration_manager->register_real("MIN_REGION_SIZE", 0.001,					     &min_region_ratio,					     false, "MotionDetector",					     "Minimum size of a motion blob over size of image");        merge_threshold = 	configuration_manager->register_real("REGION_MERGE_THRESH", 0.5,					     &merge_threshold,					     false, "MotionDetector",					     "Distance threshold for blob merging relative to blob sizes");        merge_regions =	configuration_manager->register_bool("DO_MERGE_REGIONS",					     true, &merge_regions,					     true, "MotionDetector",					     "Merge motion regions ?");        median_filter_motion_image =	configuration_manager->register_bool("MEDIAN_FILTER_MOTION_IMAGE",					     true, &median_filter_motion_image,					     true, "MotionDetector",					     "Do (spatial) median filtering on motion image (slow) ?");        do_blur =	configuration_manager->register_bool("BLUR_MOTION",					     false, &do_blur,					     true, "MotionDetector",					     "Blur images in motion detection (slow) ?");        do_motion_image_dilation = 	configuration_manager->register_bool("MOTION_IMAGE_DILATION",					     false, &do_motion_image_dilation,					     false, "MotionDetector",					     "Use dilation to improve motion image quality (slow) ?");        gap_size = 	configuration_manager->register_int("GAP_SIZE", 2,					    (int *) &gap_size, false, "MotionDetector",					    "The dilation size in pixels when filtering binary motion \image.  The effect is to join blobs that are this many pixels apart.");        use_precalculated_difference = 	configuration_manager->register_bool("PRECALCULATE_DIFFERENCE_IMAGE",					     true, &use_precalculated_difference,					     false, "MotionDetector",					     "Always calculate whole difference image for foreground \edge detector");        additional_motion_mask_filename =	configuration_manager->register_string("ADDITIONAL_MOTION_MASK_FILENAME",					       NULL, &additional_motion_mask_filename,					       false, "MotionDetector",					       "An optional PGM file with an additional constant \motion mask, for example for masking out digits from a time overlay.");        initial_background_image_filename =	configuration_manager->register_string("INITIAL_BACKGROUND_IMAGE_FILENAME",					       NULL, &initial_background_image_filename,					       false, "MotionDetector",					       "Filename for the initial background image.");        prefilter_difference =	configuration_manager->register_bool("PREFILTER_DIFFERENCE",					     true, &prefilter_difference,					     false, "MotionDetector",					     "ColourFilterSource images before differencing ?");        MAX_HEIGHT_TO_WIDTH =	configuration_manager->register_real("MAX_HEIGHT_TO_WIDTH", 4.0,					     &MAX_HEIGHT_TO_WIDTH,					     false, "MotionDetector",					     "If shapes are filtered, this is the \maximum aspect ratio allowed");        MIN_HEIGHT_TO_WIDTH =	configuration_manager->register_real("MIN_HEIGHT_TO_WIDTH", 0.8, 					     &MIN_HEIGHT_TO_WIDTH,					     false, "MotionDetector",					     "If shapes are filtered, this is the \minimum aspect ratio allowed");        NO_BLOB_FILTER =	configuration_manager->register_bool("NO_BLOB_FILTER", false, 					     &NO_BLOB_FILTER,					     false, "MotionDetector",					     "If true then all motion blobs are accepted \as possible moving people. Otherwise use constraints on aspect \ratio.");        sample_skip =	configuration_manager->register_int("SAMPLE_SKIP", 1,					    (int *) &sample_skip, false,					    "MotionDetector",					    "Spatial subsampling for motion image (1 means do not subsample)");        use_multi_background_source =	configuration_manager->register_bool("USE_MULTI_BACKGROUND_SOURCE", false, 					     &use_multi_background_source,					     true, "MotionDetector",					     "Whether to use multi-layer background for temporary \incorporation of static objects into the background.");       }//end of register_variables()MotionDetector::MotionDetector(Inputs *inputs,			       char *config_filename)    {    /************************************************************************* *                                                                       * *  New concept options/features:                                        * *    conditionally use precalculated difference,                        * *    assume background is full size (ie size of input),                 * *    allow blurring & background updating through parameter options     * *    allow HSV experimental code through #ifdef HSV                     * *    Automatically PreProccesses the first frame                        * *                                                                       * ************************************************************************/            configuration_manager = new ConfigurationManager;        //register variables with configuration manager    register_configuration_variables();        configuration_manager->parse_parameter_file(config_filename);        // set up input    input_source = inputs->get_video_image_source();        // do not update background if external background input is used    if (inputs->use_external_background_image_source())    {	do_background_updating = false;	initial_background_image = NULL;	initial_background_image_filename = NULL;    }        //    //  1 - set up initial (or, constant) background image    //    if (initial_background_image_filename != NULL)    {	FILE *initial_background_image_file =	    fopen(initial_background_image_filename, "rb");  // `b' may be important on non-UNIX	if (initial_background_image_file != NULL)	{	    // FIXME: assuming RGB32 colour images here with no check	    initial_background_image = new RGB32Image(input_source->get_xdim() / sample_skip,						      input_source->get_ydim() / sample_skip);	    	    // read in file.  The only admissible format is PNM	    if (PnmSource::read_pnm(initial_background_image_file,	   	                    initial_background_image) == NULL)	    {		delete initial_background_image;		initial_background_image = NULL;	    }	    fclose(initial_background_image_file);	}	else	{	    initial_background_image = NULL;	}    }    else	initial_background_image = NULL;    // check whether there was an error creating the initial background image    if (initial_background_image == NULL)    {	if (initial_background_image_filename != NULL)	{	    cerror << " MotionDetector::MotionDetector: Could not read initial background image 

⌨️ 快捷键说明

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