Question

I am using the following code to find all of the blobs in my image:

quad.convertTo(quad, CV_8UC1);
findContours( quad, contours, hierarchy, CV_RETR_TREE, CV_CHAIN_APPROX_SIMPLE, cv::Point(0, 0) );

vector<vector<cv::Point> > contours_poly( contours.size() );
vector<cv::Rect> boundRect( contours.size() );

for( int i = 0; i < contours.size(); i++ )
{ approxPolyDP( Mat(contours[i]), contours_poly[i], 3, true );
    boundRect[i] = boundingRect( Mat(contours_poly[i]) );
}

Mat drawing = Mat::zeros( quad.size(), CV_8UC3 );
for( int i = 0; i< contours.size(); i++ )
{
    Scalar color = Scalar( rng.uniform(0, 255), rng.uniform(0,255), rng.uniform(0,255) );
    drawContours( drawing, contours_poly, i, color, 1, 8, vector<Vec4i>(), 0, cv::Point() );
    rectangle( drawing, boundRect[i].tl(), boundRect[i].br(), color, 2, 8, 0 );
}

I am getting this as a result and it seems to be working great, but how can I draw all of the bounding boxes in a bright green? Some are white and yellow and one is green. Any way I can make all of them green? The blobs are of eroded text.

enter image description here

Was it helpful?

Solution

rng.uniform may be a uniform random law on [0,255]. So you have random colors...

Try to change

 Scalar color = Scalar( rng.uniform(0, 255), rng.uniform(0,255), rng.uniform(0,255) );

for

Scalar color = Scalar(0,255, 0 );

Colors are coded using the BGR system. B=0 G=255 R=0 is going to be green !

Bye,

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top