线程用于同时从多个IP摄像机保存图像时应用程序中的异常

时间:2013-12-20 08:04:15

标签: c++ exception opencv mfc

我正在开发应用程序,我连接应用程序并显示来自IP摄像机的多个视频。我能够获得太迟滞的视频输入(努力获得解决方案以消除滞后)。在应用程序中我有按钮,当点击它时,它从连接的所有IP摄像机拍摄50张照片。但是我实现的代码在实现线程时给出了异常。在没有线程的情况下使用它可以正常工作。这是按钮事件的代码。

void CDialogBasedVideoDlg::OnBnClickedButtonTakePic()
{
int nIndex = m_CamListBox.GetCurSel();
CStaticEx *objStaticEx = (CStaticEx*)m_StaticArray.GetAt(nIndex);
objStaticEx->StartThreadToCaptureUSBCam();//threading implementation gives exception.
//objStaticEx->CapturePicture();//this func works fine(without threading)
// TODO: Add your control notification handler code here
}

我已经覆盖静态类,它动态创建一个图片控件并显示实时视频源,线程在这个保存图像的类中实现。这是捕获图像和线程功能的代码。

void CStaticEx::CapturePicture(void)
{
CString csFileDir;
CString csFileName;

csFileDir.Format(DIR_USB_CAM_NAME,m_IpAddr);
if(IsDirExist(csFileDir)== false){
    CreateDirectory(csFileDir, NULL);       
}
CString csStr = csFileDir;
csStr += RANDOM_FILE_SEARCH;
int nNoOfFile = CountFileNumInDir((char*)csStr.GetBuffer());
csFileDir += DBL_SLASH;

int i = 0;
do{
    csFileName.Format(FILE_NAME, csFileDir, (m_nCamID+1));
    CString csCount;
    csCount.Format(_T("%d"),(nNoOfFile+1));
    csFileName += csCount;
    csFileName += JPG;
    m_pFrameImg = cvQueryFrame( m_pCamera ); //<----Exception come at this point 
    if(m_pFrameImg){
        cvSaveImage(csFileName, m_pFrameImg);
        i++;
        nNoOfFile++;
        csFileName = _T("");
    }
}while(i < 50);
 }

线程控制功能。

  void CStaticEx::StartThreadToCaptureUSBCam(){
THREADSTRUCT *_param = new THREADSTRUCT;
_param->_this = this;
AfxBeginThread(StartThread,_param);


 }

 UINT CStaticEx::StartThread (LPVOID param)
 {
THREADSTRUCT*   ts = (THREADSTRUCT*)param;
//AfxMessageBox("Thread Started");
ts->_this->CapturePicture();
return 1;
 }

抛出异常如下。

Windows has treggered a breakpoint in DialogBasedVideo.exe.
This may be due to a corruption of heap, which indicates a bug in DialogBasedVideo.exe or any of the DLLs it has loaded.
This may also be due to the user pressing F12 while dialogbasedvideo.exe has focus.
The output window may have more diagnostic information. How do i get rid of this exception. 

所有的专家都请他们帮帮我。我正在使用VS2010和Windows7,OpenCv2.4.6提前致谢。

0 个答案:

没有答案