First time here? Check out the FAQ!

Ask Your Question
1

Drawing Circles around objects

asked Apr 8 '13

shelly gravatar image

updated Oct 26 '15

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

Preview: (hide)

1 answer

Sort by » oldest newest most voted
2

answered Apr 8 '13

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.

Preview: (hide)

Question Tools

Stats

Asked: Apr 8 '13

Seen: 1,998 times

Last updated: Apr 08 '13