效果图:

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

创建线程调用该函数,採集图像通过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); 

	}






相关文章:

  • 2022-12-23
  • 2021-05-19
  • 2021-05-03
  • 2021-07-01
  • 2022-12-23
  • 2021-11-29
  • 2021-12-12
  • 2022-01-14
猜你喜欢
  • 2021-09-30
  • 2021-11-05
  • 2021-08-06
  • 2022-02-04
  • 2021-10-15
  • 2021-06-09
  • 2022-12-23
相关资源
相似解决方案