各位好,
我将视频读取到dilong对话框中时,cpu总是100%。不知道这是个什么问题。
我是这样做的,截取一帧帧的图像,如后显示到对话框中的picture控件中。具体的显示函数如下:
 void CTestcpuDlg::DrawPicToHDC(IplImage *img, UINT ID)
    {
       CDC *pDC = GetDlgItem(ID)->GetDC();
       HDC hDC= pDC->GetSafeHdc();
       CRect rect;
       GetDlgItem(ID)->GetClientRect(&rect);
       CvvImage cimg;       cimg.CopyOf(img);
       cimg.DrawToHDC(hDC,&rect);       ReleaseDC(pDC);
    }   
以下是一个循环
CTestcpuDlg* dlg;
       int nFrmNum = 0;
       dlg = (CTestcpuDlg*)(AfxGetMainWnd());
       CvCapture *pCapture = NULL;
       if( !(pCapture = cvCaptureFromFile(dlg->FilePathName)) )
       {
          printf("Can not open video file\n");
       }
       IplImage *pFrame = NULL;
       
       while(pFrame = cvQueryFrame( pCapture ))
       {
          ++nFrmNum;
          dlg->DrawPicToHDC(pFrame, IDCRESULT);
       }
       
       cvReleaseCapture(&pCapture);
       cvReleaseImage(&pFrame);    
再次先谢谢啊。

解决方案 »

  1.   

    循环里面要Sleep一下 while(pFrame = cvQueryFrame( pCapture ))
           {
              ++nFrmNum;
              dlg->DrawPicToHDC(pFrame, IDCRESULT);
    Sleep(20);
           }
      

  2.   

    sleep后确实有改善。可是还是维持在50%左右啊。
    这个程序怎么会占到这么多cpu资源呢?
      

  3.   

    在哪儿创建线程呢?
    我的程序是创建了一个按钮,然后在响应按钮的事件中写如了下面的函数。
    CTestcpuDlg* dlg;
           int nFrmNum = 0;
           dlg = (CTestcpuDlg*)(AfxGetMainWnd());
           CvCapture *pCapture = NULL;
           if( !(pCapture = cvCaptureFromFile(dlg->FilePathName)) )
           {
              printf("Can not open video file\n");
           }
           IplImage *pFrame = NULL;
           
           while(pFrame = cvQueryFrame( pCapture ))
           {
              ++nFrmNum;
              dlg->DrawPicToHDC(pFrame, IDCRESULT);
           }
           
           cvReleaseCapture(&pCapture);
           cvReleaseImage(&pFrame);
    (1)
    用来输出图像到dilogDrawPicToHDC(pFrame, IDCRESULT)是自己写的一个函数(C...Dlg的public),我试了在C...Dlg.cpp加入线程,然后将。我应该在(1)放入线程中,可是不行。