First time here? Check out the FAQ!

Ask Your Question
0

rectangle color always gray

asked Dec 10 '12

Rex gravatar image

updated Dec 10 '12

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.

Preview: (hide)

Comments

2

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

1 answer

Sort by » oldest newest most voted
2

answered Dec 10 '12

Siegfried gravatar image

updated Dec 10 '12

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);
Preview: (hide)

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 (Dec 10 '12)edit

Question Tools

Stats

Asked: Dec 10 '12

Seen: 5,883 times

Last updated: Dec 10 '12