【问题标题】:Can't find the right corners of an image [closed]找不到图像的右上角[关闭]
【发布时间】:2021-07-05 10:46:39
【问题描述】:
  • 我需要找到盒子正面的四个角。

  • 我尝试输入不同的变量(角点数量、质量水平等),但它只找到了 1 个正确的角点。

  • 到目前为止,这是我的代码:

这是输出:

【问题讨论】:

标签: python visual-studio image-processing


【解决方案1】:

角检测器不起作用。他们从不工作。

在 N、NE、SE 和 S 方向寻找最远的非黑点。

【讨论】:

    【解决方案2】:

    使用其他图像处理技术更容易找到角点。由于您的图像充满了细节,我们可以使用阈值、腐蚀和膨胀。往下看:

    color = cv2.imread('box.png')
    plt.imshow(color);
    plt.xticks([]);
    plt.yticks([]);
    

    gray = cv2.imread('box.png',0)
    gray[gray > 10 ] = 255
    plt.imshow(gray,cmap='gray');
    plt.xticks([]);
    plt.yticks([]);
    

    kernel = np.ones((5,5),np.uint8)
    gray = cv2.dilate(gray,kernel,iterations = 10)
    gray = cv2.erode(gray,kernel,iterations=15)
    gray = cv2.dilate(gray,kernel,iterations = 3)
    plt.imshow(gray,cmap='gray');
    plt.xticks([]);
    plt.yticks([]);
    

    y,x = np.where(gray == 255)
    y_index = np.argmin(y)
    x_coord = x[y_index]
    gray[0:,0:x_coord] = 0
    plt.imshow(gray,cmap='gray');
    plt.xticks([]);
    plt.yticks([]);
    

    # Top-left
    top_left = (x_coord,y[y_index])
    cv2.circle(color,top_left,5,[0,255,0],-1);
    
    # Bottom-left
    y,x = np.where(gray == 255)
    y_index = np.argmax(y)
    x_coord = x[y_index]
    bottom_left = (x_coord,y[y_index])
    cv2.circle(color,bottom_left,5,[0,255,0],-1);
    
    # Top-right
    y,x = np.where(gray == 255)
    x_index = np.argmax(x)
    y_coord = y[x_index]
    top_right = (x[x_index],y_coord)
    cv2.circle(color,top_right,5,[0,255,0],-1);
    
    # Bottom-right
    for y in range(top_right[1],gray.shape[0],1):
        roi = gray[y:y+1,top_right[0]-11:top_right[0]]
        if np.all((roi == 0)):
            break
    bottom_right = (top_right[0],y)
    cv2.circle(color,bottom_right,5,[0,255,0],-1);
    plt.imshow(color);
    plt.xticks([]);
    plt.yticks([]);
    

    您可以使用所有值来获得不同的结果。如果你改变视角,你可能需要稍微改变一下代码。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-05-01
      • 2019-12-10
      • 2019-03-06
      • 2017-10-08
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多