【MFC两种视频图像採集方法】DirectShow与Opencv

效果图:


DirectShow採集核心代码:

创建线程调用该函数,採集图像通过x264解码封装rtmp协议包。推送至FMSserver,可实现视频直播
UINT __stdcall StartVideo(void *c)
{
	CVideoConf *conf = (CVideoConf *)c;
	int vid = conf->code;
	CString strurl(conf->rtmpurl);
	CWnd *pW = conf->pW;

	CCameraDS  camera;
	if (!camera.OpenCamera(0,false));
	{  
		TRACE("OpenCamera error.....");  
	}

	while(true)
	{
		CvvImage cimg;
		CRect rect;
		
		IplImage *m_Frame ;
		BYTE *data1 =  camera.QueryFrame(); 
		m_Frame = cvCreateImageHeader(cvSize(320,240),IPL_DEPTH_8U,3);
		m_Frame->origin = 1;
		cvSetData(m_Frame,data1,320*3);

		CDC *pDC = pW->GetDC();                                                        
		HDC hDC  = pDC->GetSafeHdc();
		pW->GetClientRect(&rect); 
		cimg.CopyOf((IplImage *)m_Frame); //复制图片
		cimg.DrawToHDC(hDC, &rect);	 //显示指定区域
		HWND hWnd = pW->GetSafeHwnd();                                  
		ReleaseDC(hWnd,hDC); 

	}


	return 0;	
}

Opencv採集核心代码:

UINT __stdcall StartVideo(void *c)
{
	CVideoConf *conf = (CVideoConf *)c;
	int vid = conf->code;
	CString strurl(conf->rtmpurl);
	CWnd *pW = conf->pW;

	CCameraDS  camera;
	if (!camera.OpenCamera(0,false));
	{  
		TRACE("OpenCamera error.....");  
	}
	CvCapture* pCapture = cvCreateCameraCapture(0); //opencv打开视频 
	while(true)
	{
		CvvImage cimg;
		CRect rect;
		
		IplImage *m_Frame=cvQueryFrame( pCapture );//opencv捕获帧 

		CDC *pDC = pW->GetDC();                                                        
		HDC hDC  = pDC->GetSafeHdc();
		pW->GetClientRect(&rect); 
		cimg.CopyOf((IplImage *)m_Frame); //复制图片
		cimg.DrawToHDC(hDC, &rect);	 //显示指定区域
		HWND hWnd = pW->GetSafeHwnd();                                  
		ReleaseDC(hWnd,hDC); 

	}






评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值