表';基于OpenCV的等高线提取
我试图通过opencv检测表的边框,我选择findContour函数,这是最简单的演示表';基于OpenCV的等高线提取,opencv,computer-vision,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.
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
这里有两张图片供测试 [] []
这是他们发现结果的可视化。我用蓝色长方形指定轮廓结果。 [] []
第二个图像中的FindOntours可以正确检测表的边框,而第一个图像中的FindOntours不能检测到。然而,这两个表似乎有相似的功能,它们都有顶部和底部边框,没有左侧和白色边框。我的问题是,为什么第一个表无法检测到,而第二个表可以检测到?我已经检查了第一个图像的二值图像,它的边界信息是不会被放弃的 那么,如何通过opencv检索最佳的检测结果呢。此外,不同种类的阈值方法在这个特定任务(表检测)中似乎没有性能影响,那么我应该选择哪一种