OpenCV如何合并邻近边界框?网页界面区域分割场景
OpenCV网页功能区域分割落地问题
- 实现目标:通过OpenCV处理网页截图,自动定位并提取页眉、页脚、左侧面板、右侧面板等功能模块的边界坐标,当前输出结果和预期存在明显差距。
效果对比
- 预期输出效果:

- 当前实际检测输出:

现有实现代码
import cv2 import numpy from google.colab.patches import cv2_imshow img = cv2.imread("test.png") blue, green, red = cv2.split(img) def medianCanny(img, thresh1, thresh2): median = numpy.median(img) img = cv2.Canny(img, int(thresh1 * median), int(thresh2 * median)) return img blue_edges = medianCanny(blue, 0, 1) green_edges = medianCanny(green, 0, 1) red_edges = medianCanny(red, 0, 1) edges = blue_edges | green_edges | red_edges contours,hierarchy = cv2.findContours(edges, cv2.RETR_EXTERNAL ,cv2.CHAIN_APPROX_SIMPLE) hierarchy = hierarchy[0] for component in zip(contours, hierarchy): currentContour = component[0] currentHierarchy = component[1] x,y,w,h = cv2.boundingRect(currentContour) if currentHierarchy[3] < 0: cv2.rectangle(img,(x,y),(x+w,y+h),(0,255,0),1) cv2_imshow(img) cv2.waitKey(0) cv2.destroyAllWindows()
待解决核心问题
当前算法会输出大量零散的小尺寸检测框,缺乏邻近检测框的合并逻辑,无法直接输出匹配大尺度功能模块的分割结果。本次测试使用的输入图像可参考:测试输入图像
内容的提问来源于stack exchange,提问作者Nikita Kit
相关产品推荐
相关产品推荐

