Ask Your Question

Revision history [back]

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);