使用OpenCV检测损坏的形状


一生浮华
2025-03-09 10:28:33 (12天前)
  1. 我试图检测4条内的方块。目标是比较他们的质心。在大多数情况下,我的方法(如下所述)正确识别大多数情况。在图像中......

2 条回复
  1. 0# 誓言 | 2019-08-31 10-32



    在找到中心之前尝试填充广场。我通过迭代行并连接最左边和最右边的黑色像素来做到这一点。








    1.   # Iterate through each row in the image
    2. for row in range(img.shape[0]):

    3. # Find the left-most and right-most pixel in the sqare
    4. start, stop = 0, 0
    5. for col in range(img.shape[1]):
    6.     # Find the left-most
    7.     if img[row,col] != 255 and start == 0: start = col, row
    8.     # Find the right-most
    9.     if img[row,col] != 255: stop = col, row
    10. # If there was a pixel in that row, connect them with a line
    11. if start != 0:
    12.     cv2.line(img, start, stop, 0, 1)
    13. </code>

登录 后才能参与评论