OpenCV:从图像中去除地板

问题描述 投票:0回答:1

我正在尝试检测地板上的物体(地板有图案)。 物体是中间那个杯子状的东西。

我尝试使用 Canny 和 Sobel 边缘检测,但它也检测到地板的某些部分。我还尝试过 HSV 颜色过滤,但它很容易受到房间照明的影响。 SIFT 也无法检测到该物体。

如何去除图像中的地板?

python opencv computer-vision robotics
1个回答
1
投票

以下是如何使用 Canny 边缘检测器:

import cv2
import numpy as np

def process(img):
    img_gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
    img_blur = cv2.GaussianBlur(img_gray, (5, 5), 6)
    img_canny = cv2.Canny(img_blur, 119, 175)
    kernel = np.ones((9, 3))
    img_dilate = cv2.dilate(img_canny, kernel, iterations=7)
    return cv2.erode(img_dilate, kernel, iterations=7)

img = cv2.imread("lPNAJ.jpg")
contours = cv2.findContours(process(img), cv2.RETR_TREE, cv2.CHAIN_APPROX_NONE)[0]
cnt = sorted(contours, key=cv2.contourArea)[-2]
cv2.drawContours(img, [cv2.convexHull(cnt)], -1, (0, 0, 255), 2)
cv2.imshow("result", img)
cv2.waitKey(0)
cv2.destroyAllWindows()

第一张图像作为输入的输出:

第二张图像作为输入的输出:

请注意,代码采用图像中存在的第二大轮廓,因为最大的轮廓属于右侧的表格。

© www.soinside.com 2019 - 2024. All rights reserved.