Note that there are some explanatory texts on larger screens.

plurals
  1. POLive Video feed from IP camera using OpenCv and multithreading
    text
    copied!<p>Thank you for taking time and reading my post. I have an application which accepts username, password and IP address of IP camera and displays the video feed(This is done by using timer), also I have button named "Capture" which when clicked saves images to my disk. Also i have tried same for two IP Camera simultaneously, but when the other camera is added the stream of first camera slow downs. So my question is "Is their any scope of solving this slow down problem by using threading with my application". I am new to MFC and C++ and OpenCV. I am using OpenCV to display the video feed from IP cam. Experts please help me to get the right solution. Here's the code which I have implemented to get the video feed.</p> <pre><code>void CStaticEx::OnPaint() { CPaintDC dc(this); // device context for painting CRect rect; GetClientRect(&amp;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-&gt;width; bitmapInfo.bmiHeader.biHeight = -m_pFrameImg-&gt;height; IplImage* tempImage; if(m_pFrameImg-&gt;nChannels == THREE) //Number of color channels (1,2,3,4) { tempImage = (IplImage*)cvClone(m_pFrameImg); bitmapInfo.bmiHeader.biBitCount=tempImage-&gt;depth * tempImage-&gt;nChannels; } else if(m_pFrameImg-&gt;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-&gt;depth * tempImage-&gt;nChannels; } dc.SetStretchBltMode(COLORONCOLOR); ::StretchDIBits(dc.GetSafeHdc(), rect.left, rect.top, rect.right, rect.bottom, ZERO, ZERO, tempImage-&gt;width, tempImage-&gt;height, tempImage-&gt;imageData, &amp;bitmapInfo, DIB_RGB_COLORS, SRCCOPY); cvReleaseImage(&amp;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(&amp;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); } </code></pre> <p>Thanks in Advance. Have a great day.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload