1
votes

I'm looking for a way to find a non-square region of interest. I've seen examples on here where it's all rectangular based. For example here they find the tilted rectangle. I've looked at code examples like this SO page where they draw a rectangle as you drag your mouse from corner to corner.

My goal is to take an image like the one below and hand outline the road. Is this possible or do I just need to draw a rectangle over it?

Edit: My original thought is to build on one of those algorithms and instead of labeling the mouse-clicks as corners, I think I can store each point visited in a vector. Then I can just use a cv::Mat to fill in all the points in between. Not sure if it'll work, but it's a start.

Long Windy Road

3

3 Answers

1
votes

You could also draw a window with your image and then call:

cvSetMouseCallback( const char* window_name, CvMouseCallback on_mouse, void* param=NULL )

Save each time its clicked the x,y position in a list, array, dict, whatever you would like :). Build with this information a new Mat as a mask. Use a polygon for aproximation:

// Create Polygon from vertices
vector<Point> ROI_Poly;
approxPolyDP(ROI_Vertices, ROI_Poly, 1.0, true);

// Fill polygon white
fillConvexPoly(mask, &ROI_Poly[0], ROI_Poly.size(), 255, 8, 0);       

More information over here:

http://www.pieter-jan.com/node/5

2
votes

Nice picture btw. So in general boxes are used as they are simple. But as you have correctly pointed out thay are not so good for amorphous "stuff" like roads and sky. You have a few options.

  1. create a mask image, the same size as the orig. image, and for each pixel that is a "road" in the image, set it to one in the mask, zero otherwise, this is akin to "coloring in" the image, just like a child would in a coloring book.

  2. use a polygon that roughly traces around the boundary of the road. the more points in the polygon, the more accurate the segmentation.

I usually do this sort of thing in GIMP, then load the masks into OpenCV. For a full OpenCV imp, i suspect you may have to delve into the supported QT or OpenGL to make a little image editing tool.

I found one link here for QT http://qt-project.org/doc/qt-4.8/opengl-2dpainting.html

but please note i have not tried to implement such i thing myself, my answer is just to give you an idea of two possibilities to try out.

0
votes

If you want to label the region by hand, then you can save yourself the trouble by using graphical image editing environment, like GIMP, Photoshop, or MATLAB.