OpenCV 2.1:运行时错误 [英] OpenCV 2.1: Runtime error

查看:16
本文介绍了OpenCV 2.1:运行时错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个使用 OpenCV 的程序.我有一个网络摄像头,它捕获彩色帧,我想将彩色帧转换为灰度帧.因此,我使用 cvCvtColor(color_frame, gray_frame, CV_BGR2GRAY); 将彩色帧转换为 BW 帧.

I have a program which uses OpenCV. I have a webcam and it captures color frames and I want to convert the color frames to gray-scale frames. So, I used the cvCvtColor(color_frame, gray_frame, CV_BGR2GRAY); to convert the color frames to BW frames.

使用此颜色->灰度转换功能后,出现运行时错误:

Upon using this color->Grayscale conversion function, I get a runtime error as:

OpenCV Error: Null pointer (NULL array pointer is passed) in unknown function, file ........ocvopencvsrccxcorecxarray.cpp, line 2376

有人遇到过这个问题吗?任何解决方案如何解决这个问题?

Anyone experienced this problem before? Any solutions how to fix this?

谢谢

#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<sys/time.h>

#include"cv.h"
#include"highgui.h"
#include"cxtypes.h"

    #define ERROR -1
    #define NO_ERROR 1

int main()
{

    int EXIT_STATUS = NO_ERROR;

    int camera_index = 0;
    CvCapture   *capture = 0;
    IplImage *color_frame = NULL;
    IplImage *gray_frame = NULL;
    int exit_key_press = 0;

    capture = cvCaptureFromCAM(camera_index);
    cvNamedWindow("SURF", CV_WINDOW_AUTOSIZE);

            while(exit_key_press != 's')
            {

                /* Capture a frame */
                color_frame = cvQueryFrame(capture);
                if(color_frame == NULL)
                {
                    break;
                }
                else
                {
                   // When this line is enabled the runtime error occurs.
                    //cvCvtColor(color_frame, gray_frame, CV_BGR2GRAY);
                    cvShowImage("SURF", color_frame );



                }
                exit_key_press = cvWaitKey(1);
            }

    cvDestroyWindow("Output");
    cvReleaseCapture(&capture);

    printf("

~*~The END~*~");
    exit(EXIT_STATUS);

}

推荐答案

你不需要分配你的 IplImage 吗?它不是由转换函数指定的,但我相信您必须分配与源相同大小/类型的 dst.

Don't you have to allocate your IplImage? It is not specified by the conversion function but I believe you have to allocate a dst the same size/type as the source.

这篇关于OpenCV 2.1:运行时错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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