通过OpenCV查找表的轮廓

时间:2018-07-29 13:08:32

标签: opencv computer-vision

我正在尝试通过opencv检测表的边界,我选择了findContour函数,这是最小的演示。

def contour_proposal(rgb_matrix, weight_threshold, height_threshold):
    """
    :return: list of proposal region, each region is a tuple (ltx, lty, rbx, rby)
    """
    gray = cv.cvtColor(rgb_matrix, cv.COLOR_RGB2GRAY)
    _, binary = cv.threshold(gray, 0, 255, cv.THRESH_BINARY + cv.THRESH_OTSU)
    # binary = cv.adaptiveThreshold(gray, 255, cv.ADAPTIVE_THRESH_MEAN_C, cv.THRESH_BINARY, 11, 2)
    # binary = cv.adaptiveThreshold(gray, 255, cv.ADAPTIVE_THRESH_GAUSSIAN_C, cv.THRESH_BINARY, 11, 2)
    new_image_matrix, contours, hierarchy = cv.findContours(binary, cv.RETR_LIST, cv.CHAIN_APPROX_SIMPLE)
    proposals = list(filter(
        lambda x: x[2] > weight_threshold and x[3] > height_threshold,
        map(cv.boundingRect, contours)
    ))

    res = []

    for p in proposals:
        x, y, w, h = p
        res.append((x, y, x+w, y+h))

    return res

这里有两张要测试的图像

[enter image description here] [enter image description here]


这是他们的发现结果的可视化。我用蓝色矩形指定了轮廓结果。

[enter image description here] [enter image description here]


第二个图像中的findcontours可以正确地检测到表格的边框,而第一幅图像中的find边界却可以正确地检测出。但是,这两个表似乎具有相似的功能,它们都具有顶部和底部边框,而没有左侧和白色边框。我的问题是,为什么不能检测到第一个表却可以检测到第二个表?我已经检查了第一个图像的二进制图像,它的边界信息没有被放弃。

因此,如何通过opencv检索最佳检测结果。此外,在此特定任务(表检测)中,不同的阈值方法似乎对性能没有影响,所以我应该选择哪一种?

0 个答案:

没有答案
相关问题