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);
}
在此先感谢。祝你有美好的一天。
感谢您的回答,我没有任何问题捕捉图像,我有问题,我从IP摄像机得到的视频输入滞后。 – Mayur
如果您想从IP摄像机获取实时帧,可以使用套接字通信来检索帧。你有网络摄像机的规格(文件)吗? –