Dir_miao
Dir_miao
采纳率16.7%
2016-08-22 02:11 阅读 1.1k

VS2012 MFC,OpenCV读取不到摄像头的内容,??

void Copcv2Dlg::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 );
}

void Copcv2Dlg::OnBnClickedOpencam()
{
pCapture = cvCaptureFromCAM(0);
if(!pCapture)
{
MessageBox("camear open error!");
ExitProcess(0);
}
SetTimer(1,33,NULL);
}

void Copcv2Dlg::OnTimer(UINT_PTR nIDEvent)
{
image = cvQueryFrame(pCapture);

DrawPicToHDC(image, IDC_STATIC_PIC);
CDialogEx::OnTimer(nIDEvent);
}
摄像头正常打开,但是读取不到图像是怎么回事?

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享

1条回答 默认 最新

  • lx624909677 lx624909677 2016-08-22 03:18
     #include <opencv2/highgui/highgui.hpp>
    #include <opencv2/imgproc/imgproc.hpp>
    #include <opencv2/core/core.hpp>
    
    using namespace cv;
    
    
    int main()
    {
        VideoCapture cap(0);
        if(!cap.isOpened())
        {
            return -1;
        }
        Mat frame;
        Mat edges;
    
        bool stop = false;
        while(!stop)
        {
            cap>>frame;
            imshow("test",edges);
            if(waitKey(30) >=0)
                stop = true;
        }
        return 0;
    }
    
    点赞 评论 复制链接分享

相关推荐