簡體   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