繁体   English   中英

使用OpenCv和多线程处理来自IP摄像机的实时视频源

[英]Live Video feed from IP camera using OpenCv and multithreading

感谢您抽出宝贵时间阅读我的帖子。 我有一个接受用户名,密码和IP摄像机IP地址并显示视频源的应用程序(通过使用计时器来完成),还有一个名为“捕获”的按钮,单击该按钮会将图像保存到磁盘上。 我也同时尝试了两个IP摄像机,但是当添加另一个摄像机时,第一个摄像机的流会变慢。 因此,我的问题是“通过在我的应用程序中使用线程来解决这个速度缓慢的问题是否属于他们的范围”。 我是MFC和C ++和OpenCV的新手。 我正在使用OpenCV显示来自IP cam的视频。 专家们请帮助我获得正确的解决方案。 这是我为获取视频供稿而实现的代码。

void CStaticEx::OnPaint()
{
CPaintDC dc(this); // device context for painting

CRect rect;
GetClientRect(&rect);

m_pFrameImg = cvQueryFrame(m_pCamera);
//If camera is disconnected, control goes
//in if condition and displays message in 
//picture control
if(m_pFrameImg == NULL){
    KillTimer( ONE);
    CString sCamName;
    sCamName.Format(_T(CAM_ID_TXT),m_IpAddr);
    CString sDviceLost = _T(CONNECTION_LOST_TXT);
    sCamName.Append(sDviceLost);
    dc.SetBkMode(OPAQUE);
    dc.SetBkColor(BACKBRND_COLOR_TXTOUT);
    dc.SetTextColor(ERR_TXT_COLOR);// BGR(0xbbggrr);
    dc.TextOut(ERR_TXT_XAXIS,ERR_TXT_YAXIS,sCamName,sCamName.GetLength());
    return;//check after removinf return;
}
BITMAPINFO bitmapInfo;
bitmapInfo.bmiHeader.biSize             =   sizeof(BITMAPINFOHEADER);
bitmapInfo.bmiHeader.biPlanes           =   ONE;
bitmapInfo.bmiHeader.biCompression      =   BI_RGB;
bitmapInfo.bmiHeader.biXPelsPerMeter    =   PELSPERMETER;
bitmapInfo.bmiHeader.biYPelsPerMeter    =   PELSPERMETER;
bitmapInfo.bmiHeader.biClrUsed          =   ZERO;
bitmapInfo.bmiHeader.biClrImportant     =   ZERO;
bitmapInfo.bmiHeader.biSizeImage        =   ZERO;
bitmapInfo.bmiHeader.biWidth            =   m_pFrameImg->width;
bitmapInfo.bmiHeader.biHeight           =   -m_pFrameImg->height;
IplImage* tempImage;

if(m_pFrameImg->nChannels == THREE) //Number of color channels (1,2,3,4)
{
    tempImage = (IplImage*)cvClone(m_pFrameImg);
    bitmapInfo.bmiHeader.biBitCount=tempImage->depth * tempImage->nChannels;
}
else if(m_pFrameImg->nChannels ==  ONE) //Number of color channels (1,2,3,4)
{
    tempImage =  cvCreateImage(cvGetSize(m_pFrameImg), IPL_DEPTH_8U, THREE);
    cvCvtColor(m_pFrameImg, tempImage, CV_GRAY2BGR);
    bitmapInfo.bmiHeader.biBitCount=tempImage->depth * tempImage->nChannels;
    }
dc.SetStretchBltMode(COLORONCOLOR);
::StretchDIBits(dc.GetSafeHdc(), rect.left, rect.top, rect.right, rect.bottom,
    ZERO, ZERO, tempImage->width, tempImage->height, tempImage->imageData, &bitmapInfo,
    DIB_RGB_COLORS, SRCCOPY);
cvReleaseImage(&tempImage);
//String for giving Camera name
CString sCamName;
sCamName.Format(_T("Video Stream IP Cam-%s"), m_IpAddr);
dc.SetBkMode(OPAQUE);
dc.SetBkColor(MSG_BGCOLOR);
dc.SetTextColor(WHITE);// BGR(0xbbggrr);
dc.TextOut(MSG_TXT_XAXIS, MSG_TXT_YAXIS, sCamName, sCamName.GetLength());
ReleaseDC(&dc);
SetTimer( ONE,30, NULL);

 }
void CStaticEx::OnTimer(UINT_PTR nIDEvent)
{
// TODO: Add your message handler code here and/or call default
if(nIDEvent =  ONE){

    Invalidate();
}

 CStatic::OnTimer(nIDEvent);
}

提前致谢。 祝你有美好的一天。

请参考以下内容从实时摄像机捕获帧。 http://www.codeproject.com/Questions/442770/Connect-to-IP-Camera-in-Cplusplus

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM