Get edge co-ordinates after edge detection (Canny)

陌路散爱 提交于 2019-12-19 09:59:08

问题


I have been working with OpenCV for a fairly short time, and have performed Canny Edge Detection on an image, and also performed dilation after that to further separate the object (in my case a square) from the background.

My problem, now is to identify graspable regions in 2D using an algorithm that requires me to handle co-ordinates of the points in those edges. Is there any way I can use OpenCV to get the co-ordinates of the corners so I can find the equation of the lines forming the edge of the square? I know the size of the square. My problem involves 2D co-ordinate geometry, and hence the need for co-ordinates.

I can provide the image after edge detection and dilation if need be. Help would be appreciated a lot.


回答1:


Just offering a second method - not guaranteed to work.

  • Step 1: extract connected component and their contours. This can be applied after the Canny Edge Detection step.
    • FindContours
  • Step 2: If the contours are fairly good approximation of a square, you can use their bounding box directly.
    • BoundingRect - if the rectangles are always upright (not rotated)
    • MinAreaRect - if the rectangles are rotated.

The reason for the disclaimer is that it only works on very clean results, without any broken edges or gaps in the Canny edges, etc. If you need a more robust way of finding rectangles, Hough transform will be necessary.




回答2:


You could use the corner detectors provided in OpenCV like Harris or Corner Eigenvalues. Here's an example of that along with full-fledged code.

In case other features are also throwing up corners you may need to go in for connected component analysis.



来源:https://stackoverflow.com/questions/5828802/get-edge-co-ordinates-after-edge-detection-canny

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!