Ask Your Question
0

color.cpp:3380: error: (-215) (scn == 3 || scn == 4) && depth == CV_8U in function cvtColor

asked 2014-08-25 11:19:27 -0500

kenilworth gravatar image

Hi!

I'm completed the OpenCV iOS video processing tutorial, but I get this exception when running the completed app:

libc++abi.dylib: terminating with uncaught exception of type cv::Exception: /Users/vp/work/opencv/modules/imgproc/src/color.cpp:3380: error: (-215) (scn == 3 || scn == 4) && depth == CV_8U in function cvtColor

The exception is thrown by this function:

- (void)processImage:(Mat&)image;
{
    // Do some OpenCV stuff with the image
    Mat image_copy;
    cvtColor(image, image_copy, COLOR_BGR2GRAY);

    //invert image
    bitwise_not(image_copy, image_copy);
    cvtColor(image_copy, image, COLOR_BGR2BGRA);
}

on the line cvtColor(image_copy, image, COLOR_BGR2BGRA);

What exactly is going on?

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
2

answered 2014-08-25 11:36:09 -0500

Haris gravatar image

The above code will do

->Convert color image to gray

cvtColor(image, image_copy, COLOR_BGR2GRAY); //will work if source is 3 channel

-> Invert gray

bitwise_not(image_copy, image_copy); // should work if cvtColor() success

->Convert BGR to BGRA (three channel to four channel)

cvtColor(image_copy, image, COLOR_BGR2BGRA); // will not work as image_copy not three cannel(BGR)

So before converting BGR to BGRA convert image_copy to BGR using CV_GRAY2BGR

 Mat bgr;
 cvtColor(image_copy, bgr, CV_GRAY2BGR);

Then

 cvtColor(bgr, image, COLOR_BGR2BGRA);
edit flag offensive delete link more
Login/Signup to Answer

Question Tools

Stats

Asked: 2014-08-25 11:19:27 -0500

Seen: 4,336 times

Last updated: Aug 25 '14