Ask Your Question
0

cvtColor crash

asked 2012-12-20 20:31:01 -0600

ctagg gravatar image

updated 2012-12-20 21:54:02 -0600

I am getting a crash in Visual Studio 2010 express. Unhandled exception at ..., exception: cv::Exception at memory location ...

Also says: OpenCV Error: Assertion failed (scn == 3 || scn == 4) in unknown function, file ......\modules\imgproc\src\color.cpp, line 3256

Stepping through the code the crash happens at cvtColor line

#include <iostream>
#include <dirent.h>
#include "opencv2/highgui/highgui.hpp"
#include "opencv2/calib3d/calib3d.hpp"
#include "opencv2/imgproc/imgproc.hpp"
#include "opencv2/features2d/features2d.hpp"
#include "opencv2/nonfree/nonfree.hpp"


int main(int argc, char** argv)
{

    cv::Mat img_1 = cv::imread( argv[1] );
    cv::Mat img_1_gray;

    cv::cvtColor(img_1, img_1_gray, CV_RGB2GRAY);    

    return 0;
}

I have also tried the following demo but crashes at the cvtColor line:

http://docs.opencv.org/doc/tutorials/imgproc/shapedescriptors/find_contours/find_contours.html

edit retag flag offensive close merge delete

2 answers

Sort by ยป oldest newest most voted
3

answered 2012-12-21 01:26:28 -0600

Daniil Osokin gravatar image

Hi!
This assert means, that your source image (img_1) should have 3 or 4 channels for this type of conversion. I'm think, you don't read properly img_1 source image. Check the paths for this image. You can call img_1.empty() to find out was image read or not.
BTW, imread allows you to specify color type of loaded image, as described here, by default it is BGR image, so you should use CV_BGR2GRAY conversion type.

edit flag offensive delete link more
0

answered 2012-12-20 20:55:31 -0600

wuling gravatar image

updated 2012-12-20 20:58:23 -0600

Hi i think you must check input image format first. like:

 if (imag_1_gray.type==CV_8UC1) 
{
 //don't convert color
}
else
{
//convert color
}

if your os is windows 64 bits. The picture format you think is gray(CV_8UC1) ,but in fact,it's maybe not.

edit flag offensive delete link more

Question Tools

Stats

Asked: 2012-12-20 20:31:01 -0600

Seen: 11,658 times

Last updated: Dec 21 '12