OpenCV: How to detect rhombus on image?

懵懂的女人 提交于 2021-02-07 10:44:54

问题


I hame some image with plane which have perspective transform.

I need to detect center of each white rhombus or rhombus itself.

Here is examples:

As I unserstand the problem can be solved by simple template matching if we rectify image, but I need to do it automatically.

Is there any functions in OpenCV suitable for this task? Any other ideas?


回答1:


Here are two quick tests I just did without correcting the perspective issue.

Pure mathematical morphology:

  1. Extract the red channel
  2. Big white top-hat in order to detect all the bright areas, but without the big bright reflexion.
  3. Small white top-hat in order to detect only the thin lines between the rhombus
  4. Result of 2 minus result of 3. The lines between the rhombus are then thinner or even disappeared.
  5. Opening to clean the final result.

Here are two results: Image1 and Image2. The main issue is that the rhombus do not have the same sizes (different magnification and perspective), which can be problematic with the mathematical morphology.

So here is an other solution using the Hough transform:

  1. You start with the resulting image of the step 3 from the previous algorithm.
  2. You apply a hough transform.

Here are the results: Hough1 and Hough2. Then you have to filter between lines touching a rhombus or not, but you can use my first algorithm for that. Even if all the rhombus are not detected by the first algorithm, most will be and it will be enough to detect the lines touching the Rhombus. Then the line intersections will be the centroids that your are looking for.



来源:https://stackoverflow.com/questions/38706642/opencv-how-to-detect-rhombus-on-image

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