Ask Your Question
1

Drawing Circles around objects

asked 2013-04-08 16:02:57 -0600

shelly gravatar image

updated 2015-10-26 11:05:15 -0600

image description

Good evening,

I got a good photographic result of my flower objects and now I want to draw one hollow circle (with the minimum radius) around each of the blackend objects that represent the flowers (see the right picture attached hereby).

Data is saved into the array only when the pixel is black. The main arrays on my program are: array for heigt and array for width.

The way data is saved into my arrays does not let me differ between the black objects as a whole - data recorded for an object is scattered inside the array on a basis of width sequence (with incrementing the height as a row is ended).

The left picture shows a sequence of blue circles drawn around each blackend pixel (not per object).

I would be happy if you could suggest me a solution for the above task, as mentioned on the first paragraph above.

Best regards,

Shelly

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
2

answered 2013-04-08 16:28:31 -0600

Guanta gravatar image

Actually, the way you describe it, you have a single dimensioned array containing your data. Or am I wrong here? So, first, (I assume you use C++) make a Mat-header on top of your data-array:

uchar data[]; // let's assume that's your data array which is filled with your matrix elements 
              // btw.: why haven't you used a matrix in the first place?
cv::Mat1b mat(height, width, data); // make a matrix header on top of your data

Then run cv::findContours() (if you don't know how it works please have a look in the examples of OpenCV) to find the contours, then for each contour call:

Point2f center, float radius
// Comput minimum enclosing circle - now you have `center` and `radius` 
cv::minEnclosingCircle(onecontour, center, radius ); 
cv::circle(your_output_img, center, radius, cv::Scalar(255,0,0) ); // draw circle in blue

Done.

edit flag offensive delete link more

Question Tools

Stats

Asked: 2013-04-08 16:02:57 -0600

Seen: 1,870 times

Last updated: Apr 08 '13