cv::fillPoly unexpected behavior
I am trying to convert a color image to greyscale and then apply Red color on a specific region. I have tried:
Color Conversion
cv::Mat facadeColor = cv::imread("color.jpg");
cv::Mat facade;
cv::cvtColor(facadeColor, facade, cv::COLOR_BGR2GRAY);
Region Selection and Apply Solid Color
cv::Size s = facade.size();
int h = s.height;
int w = s.width;
cv::Point rook_points[1][4];
rook_points[0][0] = cv::Point( 0, h/2 );
rook_points[0][1] = cv::Point( 0, h );
rook_points[0][2] = cv::Point( w, h );
rook_points[0][3] = cv::Point( w, h/2 );
const cv::Point* ppt[1] = { rook_points[0] };
int npt[] = { 4 };
cv::fillPoly( facade, ppt, npt, 1, cv::Scalar( 0, 0, 255 ), 8 );
The problem I'm facing is that when the greyscale conversion is not performed, the fillPoly is filling correctly as red. But when the greyscale conversion is performed, the fillPoly output also comes as greyscale wheres it is expected to fill a specific region as RED.
I am so confused with it. Please help.
it's unclear:
facade
if you don't convert it. ?Yes, exactly I want to draw a color polygon on a greyscale image. I have to do it on purpose. Isn't it possible in OpenCV?
no, it's not possible. you cannot draw 3 color channels into a 1 channel image
you can, however, convert your grayscale image back to 3 (identical) channels, then it is possible.