9

I'm just starting to learn OpenCV programming. May I just ask about how can I identify lines and curves in OpenCV? My problem is that I have to identify if the image contains a convex or concave (horizontal or vertical curve) curve, a vertical, diagonal or a horizontal line.

In my code, I used CvSetImageROI to take a particular part of an image, and then I'm trying to identify each according to the said lines/curves.

Are there functions in OpenCV that are available? Thank you very much for the help. By the way, i'm using Linux and C++.

cpx
  • 17,009
  • 20
  • 87
  • 142
cmsl
  • 271
  • 2
  • 7
  • 17

1 Answers1

8

Hough transform http://en.wikipedia.org/wiki/Hough_transform, http://homepages.inf.ed.ac.uk/rbf/HIPR2/hough.htm is the standard way to do it. In its simple form (as implemented in OpenCV) it can detect lines of arbitray position and angle and line segments.

Look here for an example http://opencv.itseez.com/modules/imgproc/doc/feature_detection.html?highlight=hough#houghlinesp

For curves, the detection process is a bit more complicated, and you need the general Hough transform It is not yet available in OCV, but you can write it as an exercise or look for a good implementation. http://en.wikipedia.org/wiki/Generalised_Hough_transform describes it (in short)

Sam
  • 19,708
  • 4
  • 59
  • 82
  • 6
    You might also look into Canny() and FindContours() – Adrian Nov 08 '11 at 07:13
  • How will I able to check the angles? Can I get that from the parameters? Thank you very much! – cmsl Nov 15 '11 at 01:04
  • Hough transform returns angles and intercept (if you use the classical one) and segment endpoints (for the probabilistic one). You can extract angles with simple geometric calculations from endpoints or use the classical transform. Check OpenCV documentation and the example in the above link – Sam Nov 15 '11 at 06:58