int main(int argc, char **argv) { CvCapture *capture = 0; capture = cvCaptureFromCAM(0); //capture = cvCaptureFromAVI("video.avi"); if(!capture){ std::cerr << "Cannot open initialize webcam!" << std::endl; return 1; } IplImage *frame = cvQueryFrame(capture); FrameDifferenceBGS* bgs = new FrameDifferenceBGS; int key = 0; while(key != 'q') { frame = cvQueryFrame(capture); if(!frame) break; cv::Mat img_input(frame,true); cv::resize(img_input,img_input,cv::Size(320,240)); cv::imshow("input", img_input); cv::Mat img_mask; bgs->process(img_input, img_mask); // automatically shows the foreground mask image //if(!img_mask.empty()) // do something key = cvWaitKey(1); } delete bgs; cvDestroyAllWindows(); cvReleaseCapture(&capture); return 0; }
float PerformanceUtils::SimilarityMeasure(IplImage *image, IplImage *ground_truth, bool debug) { cv::Mat img_input(image,true); cv::Mat img_ref(ground_truth,true); int rn = cv::countNonZero(img_ref); cv::Mat i; cv::Mat u; if(rn > 0) { i = img_input & img_ref; u = img_input | img_ref; } else { i = (~img_input) & (~img_ref); u = (~img_input) | (~img_ref); } int in = cv::countNonZero(i); int un = cv::countNonZero(u); double s = (((double)in) / ((double)un)); if(debug) { cv::imshow("A^B", i); cv::imshow("AvB", u); //std::cout << "Similarity Measure: " << s << std::endl; //<< " press ENTER to continue" << std::endl; //cv::waitKey(0); } return s; }
int main(int argc, char **argv) { std::cout << "Using OpenCV " << CV_MAJOR_VERSION << "." << CV_MINOR_VERSION << "." << CV_SUBMINOR_VERSION << std::endl; /* Open video file */ CvCapture *capture = 0; capture = cvCaptureFromAVI("dataset/jakomali.mp4"); //video.avi if(!capture){ std::cerr << "Cannot open video!" << std::endl; return 1; } /* Background Subtraction Algorithm */ IBGS *bgs; bgs = new PixelBasedAdaptiveSegmenter; /* Blob Tracking Algorithm */ cv::Mat img_blob; BlobTracking* blobTracking; blobTracking = new BlobTracking; /* Vehicle Counting Algorithm */ VehicleCouting* vehicleCouting; vehicleCouting = new VehicleCouting; std::cout << "Press 'q' to quit..." << std::endl; int key = 0; IplImage *frame; while(key != 'q') { frame = cvQueryFrame(capture); if(!frame) break; cv::Mat img_input(frame); //cv::imshow("Input", img_input); // input video cv::Mat img_mask; bgs->process(img_input, img_mask); if(!img_mask.empty()) { // Perform blob tracking blobTracking->process(img_input, img_mask, img_blob); // Perform vehicle counting vehicleCouting->setInput(img_blob); vehicleCouting->setTracks(blobTracking->getTracks()); vehicleCouting->process(); } key = cvWaitKey(1); } delete vehicleCouting; delete blobTracking; delete bgs; cvDestroyAllWindows(); cvReleaseCapture(&capture); return 0; }
int main(int argc, char **argv) { CvCapture *capture = 0; int resize_factor = 100; if(argc > 1) { std::cout << "Openning: " << argv[1] << std::endl; capture = cvCaptureFromAVI(argv[1]); } else { capture = cvCaptureFromCAM(0); resize_factor = 50; // set size = 50% of original image } if(!capture) { std::cerr << "Cannot initialize video!" << std::endl; return 1; } IplImage *frame_aux = cvQueryFrame(capture); IplImage *frame = cvCreateImage(cvSize((int)((frame_aux->width*resize_factor)/100) , (int)((frame_aux->height*resize_factor)/100)), frame_aux->depth, frame_aux->nChannels); cvResize(frame_aux, frame); /* Background Subtraction Methods */ IBGS *bgs; /*** Default Package ***/ bgs = new FrameDifferenceBGS; //bgs = new StaticFrameDifferenceBGS; //bgs = new WeightedMovingMeanBGS; //bgs = new WeightedMovingVarianceBGS; //bgs = new MixtureOfGaussianV1BGS; //bgs = new MixtureOfGaussianV2BGS; //bgs = new AdaptiveBackgroundLearning; //bgs = new GMG; /*** DP Package (adapted from Donovan Parks) ***/ //bgs = new DPAdaptiveMedianBGS; //bgs = new DPGrimsonGMMBGS; //bgs = new DPZivkovicAGMMBGS; //bgs = new DPMeanBGS; //bgs = new DPWrenGABGS; //bgs = new DPPratiMediodBGS; //bgs = new DPEigenbackgroundBGS; //bgs = new DPTextureBGS; /*** TB Package (adapted from Thierry Bouwmans) ***/ //bgs = new T2FGMM_UM; //bgs = new T2FGMM_UV; //bgs = new T2FMRF_UM; //bgs = new T2FMRF_UV; //bgs = new FuzzySugenoIntegral; //bgs = new FuzzyChoquetIntegral; /*** JMO Package (adapted from Jean-Marc Odobez) ***/ //bgs = new MultiLayerBGS; /*** PT Package (adapted from Hofmann) ***/ //bgs = new PixelBasedAdaptiveSegmenter; /*** LB Package (adapted from Laurence Bender) ***/ //bgs = new LBSimpleGaussian; //bgs = new LBFuzzyGaussian; //bgs = new LBMixtureOfGaussians; //bgs = new LBAdaptiveSOM; //bgs = new LBFuzzyAdaptiveSOM; /*** LBP-MRF Package (adapted from Csaba Kertész) ***/ //bgs = new LbpMrf; /*** AV Package (adapted from Antoine Vacavant) ***/ //bgs = new VuMeter; /*** EG Package (adapted from Ahmed Elgammal) ***/ //bgs = new KDE; int key = 0; while(key != 'q') { frame_aux = cvQueryFrame(capture); if(!frame_aux) break; cvResize(frame_aux, frame); cv::Mat img_input(frame); cv::imshow("input", img_input); cv::Mat img_mask; cv::Mat img_bkgmodel; bgs->process(img_input, img_mask, img_bkgmodel); // automatically shows the foreground mask image //if(!img_mask.empty()) // do something key = cvWaitKey(33); } delete bgs; cvDestroyAllWindows(); cvReleaseCapture(&capture); return 0; }
int main(int argc, char **argv) { std::cout << "Using OpenCV " << CV_MAJOR_VERSION << "." << CV_MINOR_VERSION << "." << CV_SUBMINOR_VERSION << std::endl; CvCapture *capture = 0; int resize_factor = 100; if(argc > 1) { std::cout << "Openning: " << argv[1] << std::endl; capture = cvCaptureFromAVI(argv[1]); } else { capture = cvCaptureFromCAM(0); resize_factor = 50; // set size = 50% of original image } if(!capture) { std::cerr << "Cannot initialize video!" << std::endl; return -1; } IplImage *frame_aux = cvQueryFrame(capture); IplImage *frame = cvCreateImage(cvSize((int)((frame_aux->width*resize_factor)/100) , (int)((frame_aux->height*resize_factor)/100)), frame_aux->depth, frame_aux->nChannels); cvResize(frame_aux, frame); /* Background Subtraction Methods */ IBGS *bgs; /*** Default Package ***/ bgs = new FrameDifferenceBGS; //bgs = new StaticFrameDifferenceBGS; //bgs = new WeightedMovingMeanBGS; //bgs = new WeightedMovingVarianceBGS; //bgs = new MixtureOfGaussianV1BGS; //bgs = new MixtureOfGaussianV2BGS; //bgs = new AdaptiveBackgroundLearning; //bgs = new AdaptiveSelectiveBackgroundLearning; //bgs = new GMG; /*** DP Package (thanks to Donovan Parks) ***/ //bgs = new DPAdaptiveMedianBGS; //bgs = new DPGrimsonGMMBGS; //bgs = new DPZivkovicAGMMBGS; //bgs = new DPMeanBGS; //bgs = new DPWrenGABGS; //bgs = new DPPratiMediodBGS; //bgs = new DPEigenbackgroundBGS; //bgs = new DPTextureBGS; /*** TB Package (thanks to Thierry Bouwmans, Fida EL BAF and Zhenjie Zhao) ***/ //bgs = new T2FGMM_UM; //bgs = new T2FGMM_UV; //bgs = new T2FMRF_UM; //bgs = new T2FMRF_UV; //bgs = new FuzzySugenoIntegral; //bgs = new FuzzyChoquetIntegral; /*** JMO Package (thanks to Jean-Marc Odobez) ***/ //bgs = new MultiLayerBGS; /*** PT Package (thanks to Martin Hofmann, Philipp Tiefenbacher and Gerhard Rigoll) ***/ //bgs = new PixelBasedAdaptiveSegmenter; /*** LB Package (thanks to Laurence Bender) ***/ //bgs = new LBSimpleGaussian; //bgs = new LBFuzzyGaussian; //bgs = new LBMixtureOfGaussians; //bgs = new LBAdaptiveSOM; //bgs = new LBFuzzyAdaptiveSOM; /*** LBP-MRF Package (thanks to Csaba Kertész) ***/ //bgs = new LbpMrf; /*** AV Package (thanks to Lionel Robinault and Antoine Vacavant) ***/ //bgs = new VuMeter; /*** EG Package (thanks to Ahmed Elgammal) ***/ //bgs = new KDE; /*** DB Package (thanks to Domenico Daniele Bloisi) ***/ //bgs = new IndependentMultimodalBGS; /*** SJN Package (thanks to SeungJong Noh) ***/ //bgs = new SJN_MultiCueBGS; /*** BL Package (thanks to Benjamin Laugraud) ***/ //bgs = new SigmaDeltaBGS; int key = 0; while(key != 'q') { frame_aux = cvQueryFrame(capture); if(!frame_aux) break; cvResize(frame_aux, frame); cv::Mat img_input(frame); cv::imshow("input", img_input); cv::Mat img_mask; cv::Mat img_bkgmodel; bgs->process(img_input, img_mask, img_bkgmodel); // by default, it shows automatically the foreground mask image //if(!img_mask.empty()) // cv::imshow("Foreground", img_mask); // do something key = cvWaitKey(33); } delete bgs; cvDestroyAllWindows(); cvReleaseCapture(&capture); return 0; }
void VideoCapture::start() { loadConfig(); if (useCamera) setUpCamera(); if (useVideo) setUpVideo(); if (!capture) std::cerr << "Capture error..." << std::endl; int input_fps = cvGetCaptureProperty(capture, CV_CAP_PROP_FPS); std::cout << "input->fps:" << input_fps << std::endl; IplImage* frame1 = cvQueryFrame(capture); frame = cvCreateImage(cvSize((int)((frame1->width*input_resize_percent) / 100), (int)((frame1->height*input_resize_percent) / 100)), frame1->depth, frame1->nChannels); //cvCreateImage(cvSize(frame1->width/input_resize_factor, frame1->height/input_resize_factor), frame1->depth, frame1->nChannels); std::cout << "input->resize_percent:" << input_resize_percent << std::endl; std::cout << "input->width:" << frame->width << std::endl; std::cout << "input->height:" << frame->height << std::endl; double loopDelay = 33.333; if (input_fps > 0) loopDelay = (1. / input_fps)*1000.; std::cout << "loopDelay:" << loopDelay << std::endl; std::cout << "Press 'ESC' to stop..." << std::endl; bool firstTime = true; do { frameNumber++; frame1 = cvQueryFrame(capture); if (!frame1) break; cvResize(frame1, frame); if (enableFlip) cvFlip(frame, frame, 0); if (VC_ROI::use_roi == true && VC_ROI::roi_defined == false && firstTime == true) { VC_ROI::reset(); do { cv::Mat img_input(frame); if (showOutput) { cv::imshow("Input", img_input); std::cout << "Set ROI (press ESC to skip)" << std::endl; VC_ROI::img_input1 = new IplImage(img_input); cvSetMouseCallback("Input", VC_ROI::VideoCapture_on_mouse, NULL); key = cvWaitKey(0); delete VC_ROI::img_input1; } else key = KEY_ESC; if (key == KEY_ESC) { std::cout << "ROI disabled" << std::endl; VC_ROI::reset(); VC_ROI::use_roi = false; break; } if (VC_ROI::roi_defined) { std::cout << "ROI defined (" << VC_ROI::roi_x0 << "," << VC_ROI::roi_y0 << "," << VC_ROI::roi_x1 << "," << VC_ROI::roi_y1 << ")" << std::endl; break; } else std::cout << "ROI undefined" << std::endl; } while (1); } if (VC_ROI::use_roi == true && VC_ROI::roi_defined == true) { CvRect rect = cvRect(VC_ROI::roi_x0, VC_ROI::roi_y0, VC_ROI::roi_x1 - VC_ROI::roi_x0, VC_ROI::roi_y1 - VC_ROI::roi_y0); cvSetImageROI(frame, rect); } cv::Mat img_input(frame); if (showOutput) cv::imshow("Input", img_input); if (firstTime) saveConfig(); start_time = cv::getTickCount(); frameProcessor->process(img_input); int64 delta_time = cv::getTickCount() - start_time; freq = cv::getTickFrequency(); fps = freq / delta_time; //std::cout << "FPS: " << fps << std::endl; cvResetImageROI(frame); key = cvWaitKey(loopDelay); //std::cout << "key: " << key << std::endl; if (key == KEY_SPACE) key = cvWaitKey(0); if (key == KEY_ESC) break; if (stopAt > 0 && stopAt == frameNumber) key = cvWaitKey(0); firstTime = false; } while (1); cvReleaseCapture(&capture); }