opencv实践程序4——canny实现摄像头的边缘检测,高斯背景建模

/*
//原摄像头视频,轮廓,高斯模型
#include <iostream>
#include <cv.h>
#include <highgui.h>
#include"cvaux.h"
using namespace std;
using namespace cv;


int main( int argc, char** argv )
{
VideoCapture cap(0); //打开默认的摄像头号  
    Mat edges,fore;  
    namedWindow("edges",1); //边缘的窗口
int num = 0;   
    cap.open(num); 
BackgroundSubtractorMOG mog;
while(1)
    {  
        Mat frame;  
        cap >> frame; // 从摄像头中获取新的一帧  
if ( !frame.empty() )  imshow("Video", frame);//摄像头部分到这就结束了,下面全是关于轮廓的
        cvtColor(frame, edges, CV_BGR2GRAY);  
        GaussianBlur(edges, edges, Size(7,7), 1.5, 1.5);  
        Canny(edges, edges, 0, 30, 3);  
        imshow("edges", edges);  

mog(frame,fore,0.01);//封信背景并返回前景
threshold(fore,fore,128,255,THRESH_BINARY_INV);//对图像取反
        //imshow("原视频", frame);  
        imshow("提取的前景", fore);  

        if(waitKey(30) >= 0) break;  
}
cap.release();
return 0;
}*/
//教材上混合高斯算法
#include <iostream>
#include <cv.h>
#include <highgui.h>
#include "cvaux.h" 
using namespace std;
using namespace cv;

int main( int argc, char** argv )
{
	VideoCapture cap(0);  
	Mat frame,foreground; //前景图像
	//namedWindow("video",1);
    namedWindow("提取的前景",1); 
	//int num = 0;   
   // cap.open(num); 
	BackgroundSubtractorMOG mog;
	bool stop(false);
	while(!stop) 
    {  
		// Mat frame;  
		if(!cap.read(frame))break;
		mog(frame,foreground,0.01);//封信背景并返回前景
		threshold(foreground,foreground,128,255,THRESH_BINARY_INV);//对图像取反	
        imshow("原视频", frame);  
        imshow("提取的前景", foreground);  
        if(waitKey(10) >= 0) stop=true;  
	}
	//cap.release();
	   return 0;
	}


  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值