OpenCV-前景提取

<pre name="code" class="cpp"><pre name="code" class="cpp">// FrontSight.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"

#include <cv.h>  
#include <highgui.h>  
#include <video/video.hpp>
#include <iostream>

#ifdef _DEBUG
#pragma comment(lib, "opencv_core231d.lib")
#pragma comment(lib, "opencv_highgui231d.lib")
#pragma comment(lib, "opencv_imgproc231d.lib")
#pragma comment(lib, "opencv_calib3d231d.lib")
#pragma comment(lib, "opencv_features2d231d.lib")
#pragma comment(lib, "opencv_contrib231d.lib")
#pragma comment(lib, "opencv_ml231d.lib") 
#pragma comment(lib, "opencv_video231d.lib") 
#else
#pragma comment(lib, "opencv_core231.lib")
#pragma comment(lib, "opencv_highgui231.lib")
#pragma comment(lib, "opencv_imgproc231.lib")
#pragma comment(lib, "opencv_calib3d231.lib")
#pragma comment(lib, "opencv_features2d231.lib")
#pragma comment(lib, "opencv_contrib231.lib")
#pragma comment(lib, "opencv_ml231.lib") 
#pragma comment(lib, "opencv_video231.lib") 
#endif 

using namespace cv;
using namespace std;

int main()
{
	Mat frame; 
	Mat fground;	
	Mat bkground;
	VideoCapture capture;
	capture.open(0);

	if (!capture.isOpened())
	{
		return 0;
	}

	namedWindow("Fground");
	namedWindow("SrcImg");
	namedWindow("Bkground");
	
	BackgroundSubtractorMOG2 mog;//BackgroundSubtractorMOG2 BackgroundSubtractorMOG无法获取背景
	
	
	while (1)
	{
		if (!capture.read(frame))
		{
			break;
		}
		
		mog(frame, fground,0.05);		

		//腐蚀膨胀
		//erode(fground,fground,cv::Mat());
		//dilate(fground,fground,cv::Mat());

		threshold(fground, fground, 128, 255, THRESH_BINARY_INV);
		
		//获取背景
		mog.getBackgroundImage(bkground);

		imshow("Fground", fground);
		imshow("SrcImg", frame);
		imshow("Bkground",bkground);
		if (waitKey(10) == 27)
		{
			break;
		}
	}
}





                
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值