2013-12-18 28 views
1

感謝您花時間閱讀我的文章。 我有一個應用程序接受IP攝像機的用戶名,密碼和IP地址,並顯示視頻源(這是通過使用計時器完成),我也有按鈕命名爲「捕獲」,當點擊將圖像保存到我的磁盤。另外我也嘗試過兩個IP攝像機同時使用,但是當其他攝像機添加了第一臺攝像機時,它會變慢。所以我的問題是「他們的任何解決方案都是通過在我的應用程序中使用線程來解決這個問題」。我是MFC和C++和OpenCV的新手。我使用OpenCV來顯示來自IP攝像機的視頻。請專家幫我解決問題。 下面是我已經實現的代碼來獲取視頻源。使用OpenCv和多線程從IP攝像機實時傳送視頻

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); 
} 

在此先感謝。祝你有美好的一天。

回答