Ask Your Question
0

Why am I getting assertion failed in cvtColor even when convertTo was called in the line before?

asked 2013-01-18 23:45:14 -0600

ZachTM gravatar image

Hi everyone, I am having a pretty small error but I cannot figure out why I am getting it.

//Setup the input
Mat* image=(Mat*)addrImg;
Mat character = *image;
character.convertTo(character,CV_8UC1);
threshold( character, character, 0, 255,1 );
Mat color_dst;
cvtColor(character,color_dst,CV_GRAY2BGR);

I have this code which is in the android jni, the way I am calling cvtColor should only require a one channel image, since I am going from grey to BGR, but I keep getting this error:

01-19 00:37:44.269: E/cv::error()(32379): OpenCV Error: Assertion failed
 (scn == 1 && (dcn == 3 || dcn == 4)) in void 
cv::cvtColor(cv::InputArray, cv::OutputArray, int, int), 
file /home/reports/ci/slave/opencv/modules/imgproc/src/color.cpp, line 3355

It really cannot figure otu why I am getting the error, can anyone help me out here? It would be greatly appreciated.

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
3

answered 2013-01-19 02:45:34 -0600

Vladislav Vinogradov gravatar image

It seems like your image isn't grayscale. convertTo doesn't change channels number, only depth. If you want to convert image to grayscale you should call cvtColor

Mat* image=(Mat*)addrImg;
Mat character;
cvtColor(*image, character, CV_BGR2GRAY);
character.convertTo(character, CV_8U);
threshold(character, character, 0, 255, 1);
Mat color_dst;
cvtColor(character, color_dst, CV_GRAY2BGR);
edit flag offensive delete link more

Comments

Ah that fixed it thanks!

ZachTM gravatar imageZachTM ( 2013-01-19 10:43:58 -0600 )edit

Question Tools

Stats

Asked: 2013-01-18 23:45:14 -0600

Seen: 17,667 times

Last updated: Jan 19 '13