代码之家  ›  专栏  ›  技术社区  ›  zer02

opencv检测表上的所有通用对象形状(birdview)

  •  0
  • zer02  · 技术社区  · 8 年前

    我想检测平桌子上的各种物体形状。桌子的表面颜色可以是灰色、白色或黑色。

    对象可以是任何形状,也可以有不同的颜色。

    解决这个问题的有效方法是什么?

    我试过: 。

    1.)转换为灰度、双边过滤、canny边缘,然后使用findcontours,也尝试使用自适应阈值。

    2.)打开cv SimpleBlobDetector

    原始图片

    轮廓

    斑点检测器

    .

    对象可以是任何形状,也可以有不同的颜色。

    解决这个问题的有效方法是什么?

    我尝试过:

    1.)转换为灰度、双边滤波器、canny边缘,然后使用findcontours,也尝试使用自适应阈值。

    2.)打开cv SimpleBlobDetector

    原始图片

    Original

    轮廓

    Contours

    斑点检测器

    3 回复  |  直到 8 年前
        1
  •  1
  •   Jeru Luke    8 年前

    img = cv2.imread(r'C:\Users\Jackson\Desktop\table.png', 1)
    
    gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
    gray = cv2.medianBlur(gray, 5)
    
    ret,th1 = cv2.threshold(gray,127,255,cv2.THRESH_BINARY)
    
    adaptive_threshold = cv2.adaptiveThreshold(gray,255,cv2.ADAPTIVE_THRESH_GAUSSIAN_C,\
                cv2.THRESH_BINARY,11,2)
    
    img2 = img.copy()
    
    _, contours, _ = cv2.findContours(cv2.threshold(th3, 0, 255, cv2.THRESH_BINARY_INV)[1], cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE)
    
    cv2.drawContours(img2, contours, -1, (0, 255, 0), 2)
    

    cv2.imshow('adaptive_threshold', adaptive_threshold)
    

    enter image description here

    cv2.imshow('img2', img2)
    

    enter image description here

        2
  •  1
  •   xFL    8 年前
        3
  •  1
  •   zindarod    8 年前