cv :: Exception在内存位置发生错误 [英] cv::Exception at memory location error occurs

查看:112
本文介绍了cv :: Exception在内存位置发生错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个yuv相机.

我将yuv转换为bgr(由于opencv使用bgr),但出现异常:

I convert yuv to bgr (because of opencv use bgr) but I get an exception:

test1.exe中0x76c1a832处未处理的异常:Microsoft C ++异常:内存位置0x00baee60处的cv :: Exception..

Unhandled exception at 0x76c1a832 in test1.exe: Microsoft C++ exception: cv::Exception at memory location 0x00baee60..

我该如何解决?

#include <opencv/cv.h>
#include <opencv/highgui.h>
#include <opencv2/opencv.hpp>

void main()
{
    IplImage* image ;
    CvCapture* capture=cvCaptureFromCAM(CV_CAP_ANY);

    //cv::Mat input;
    cv::Mat output;

    cvNamedWindow("webcam",1);

    cvGrabFrame( capture );

    image = cvRetrieveFrame( capture );

    cv::Mat input = cv::cvarrToMat(image);

    cv::cvtColor(input,output,CV_YUV2BGR_YUY2);

    imshow("webcam", output);


    /*
    while(1)
    {
        //get image from Camera
        image = cvQueryFrame(capture);

        //Iplimage to Mat
        cv::Mat input = cv::cvarrToMat(image);

        //YUV to RGB, CV_YUV2RGB_NV12 CV_YUV2BGR_NV12 CV_YUV2RGB_YV12 CV_YUV2BGR_YV12 CV_YUV2RGB_IYUV CV_YUV2BGR_IYUV CV_YUV2RGB_UYVY CV_YUV2BGR_UYVY
        cv::cvtColor(input,output,CV_YUV2BGR_YUY2);

        // Draw image
        //cvShowImage("webcam", image);
        imshow("webcam", output);


        //key = cvWaitKey(30);
        if(cvWaitKey(33)>=27)
            break;
    }
    */

    cvReleaseCapture(&capture);
    cvDestroyWindow("webcam");
}

推荐答案

代码似乎正确,但是您没有检查图像是否真的从捕获设备中检索到.代码中最可能的问题是您没有在检索图像,而是要转换的空Mat(这是不可能的),这会产生错误.

The code seems to be correct, but you are not checking whether the image was really retrieved from the capture device. The most likely problem in your code is that you are not retrieving an image and it is an empty Mat you are trying to convert (which is impossible) and this produces the error.

但是,如果您已经在使用C ++,为什么不使用C ++ API?

However, if you are already using C++, why don't you use C++ API?

这篇关于cv :: Exception在内存位置发生错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆