Ask Your Question
0

rectangle color always gray

asked 2012-12-10 04:43:07 -0600

Rex gravatar image

updated 2012-12-10 04:44:05 -0600

Hi

Silly little problem , but for some reason the method rectangle does not react to the input argument.

This should yield a red box, but the box is always gray no matter what I do to the input arguments of Scalar.

rectangle( CurrentMat, matchLoc, Point( matchLoc.x + TemplateMat.cols , matchLoc.y + TemplateMat.rows ), Scalar(0,0,255), 2, 8, 0);

Any suggestions? TIA.

edit retag flag offensive close merge delete

Comments

2

Are your CurrentMat grayscale? If CurrentMat is 1-channel mat, rectangle always draw grayscale objects.

Vladislav Vinogradov gravatar imageVladislav Vinogradov ( 2012-12-10 05:04:49 -0600 )edit

1 answer

Sort by ยป oldest newest most voted
2

answered 2012-12-10 05:05:59 -0600

Siegfried gravatar image

updated 2012-12-10 05:12:28 -0600

Hi, check the type of your image (CurrentMat). If it is a single channel image, the rectangle will be drawn in gray. Then you can use cv::cvtColor() to convert the image into a RGB image and draw the rectangle in this image.

cv::Mat CurrentMat_RGB;
cv::cvtColor(CurrentMat, CurrentMat_RGB, CV_GRAY2RGB);
rectangle( CurrentMat_RGB, matchLoc, Point( matchLoc.x + TemplateMat.cols , matchLoc.y + TemplateMat.rows ), Scalar(0,0,255), 2, 8, 0);
edit flag offensive delete link more

Comments

Thanks. There was an alpha channel in CurrentMat which caused the problem. Not sure why. CvtColor CV_BGRA2BGR seems to have sorted the problem out.

Rex gravatar imageRex ( 2012-12-10 05:55:49 -0600 )edit

Question Tools

Stats

Asked: 2012-12-10 04:43:07 -0600

Seen: 5,665 times

Last updated: Dec 10 '12