Ask Your Question

Identify the white section of a binary image

asked 2014-04-24 03:51:14 -0500

jashanvir gravatar image

I want to track the white section of the binary image. When the white section is detected (which is cuboid in my case) it should get the height and width and the value of left and top most pixel.

Then after getting the coordinates i want to assign them to ROI. so that i can then subscribe to /roi topic and perform a particular action.


edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted

answered 2014-04-25 01:07:04 -0500

Mike Charikov gravatar image

Detect contours. Cycle through contours and build rectangle, which contour fit.

Use some CV lib for this task, for example OpenCV (highly recommeded). You will need do something like that:

// contours of targets
std::vector<std::vector<cv::Point> > contours;

// get contours from binary image

// poly contours
std::vector<std::vector<cv::Point> > contours_poly(contours.size());

// bounded rectangles
std::vector<cv::Rect> boundRect(contours.size());

for (int i=0; i<contours.size(); i++) {
    // get polyDPcontour and bound rectangle of it
        cv::approxPolyDP(cv::Mat(contours[i]), contours_poly[i], 3, true);
        boundRect[i] = cv::boundingRect(cv::Mat(contours_poly[i]));
edit flag offensive delete link more


Thanks a lot for your time and patience. but can you please tell me in python (without numpy) because i dont know C++... I will really appreciate it..!

jashanvir gravatar image jashanvir  ( 2014-04-28 02:21:33 -0500 )edit

Sorry, i'm not good in python. But OpenCV has python wrappers of every c++ function with the same names. So it will be easy for you to translate from c++ to python. Also you should take a look in python contour sample here:

Mike Charikov gravatar image Mike Charikov  ( 2014-04-29 04:09:58 -0500 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower


Asked: 2014-04-24 03:51:14 -0500

Seen: 1,207 times

Last updated: Apr 25 '14