Detecting lines and shapes in OpenCV using Python

后端 未结 2 1771
小蘑菇
小蘑菇 2020-11-30 07:05

I\'ve been playing around with OpenCV (cv2) and detecting lines and shapes. Say that my daughter drew a drawing, like so:

I am trying to write a Python scri

2条回答
  •  自闭症患者
    2020-11-30 07:24

    You might check out a couple of resources.

    First, you might consider asking questions at answers.opencv.org. There is probably a higher concentration of opencv specialists there.

    Second, the book Practical OpenCV by Samarth Brahmbhatt is available as a free pdf and is easily found on google. It is contains many examples related to what you are looking for.

    For example, you can separate different (non-overlapping) contours, as is shown in example 6.1 on page 68. He has a simple program for finding circles and lines in example 6.4 on page 78. You can also find a RANSAC-based ellipse-finder (much more complicated, but would be very useful here) in example 6.5 on page 82.

    The book is in C++, but I imagine it will be very relevant, only you will need an API reference to translate it to python.

    Personally, for your proejct, I would analyze one contour at a time, starting with his ellipse finder, and where a suitable ellipse can not be found, you could use a Hough transform of adjustable threshold, and truncate the resulting lines at their intersections, and bam! You have polygons.

提交回复
热议问题