Demo entry 6344644

Mog

   

Submitted by zhu on Jan 19, 2017 at 13:34
Language: C++. Code size: 809 Bytes.

int main(int argc, char** argv)
{
    std::string videoFile = "person01_walking_d1_uncomp.avi";

	cv::VideoCapture capture;
	capture.open(videoFile);

	if (!capture.isOpened())
	{
		std::cout<<"read video failure"<<std::endl;
		return -1;
	}
	cv::BackgroundSubtractorMOG2 mog;
	cv::Mat foreground;
	cv::Mat background;
	cv::Mat frame;
	long frameNo = 0;
	while (capture.read(frame))
	{
		++frameNo;
		std::cout<<frameNo<<std::endl;
		mog(frame, foreground, 0.001);// 运动前景检测,并更新背景
		cv::erode(foreground, foreground, cv::Mat());// 腐蚀
		cv::dilate(foreground, foreground, cv::Mat());// 膨胀
		mog.getBackgroundImage(background);   // 返回当前背景图像
		cv::imshow("video", foreground);
		cv::imshow("background", background);
		if (cv::waitKey(25) > 0)
		{
			break;
		}
	}
	return 0;
}

This snippet took 0.00 seconds to highlight.

Back to the Entry List or Home.

Delete this entry (admin only).