python - 检测图像中网络链接周围的网络创建矩形
问题描述
我目前正在尝试编写一小段代码,可以准确检测图像中的网页链接并在它们周围创建一个矩形。这是我到目前为止的位置:
frame = self.current_frame
lower_color_bounds = np.array([121, 50, 50], dtype=np.uint8)
upper_color_bounds = np.array([130, 255, 255], dtype=np.uint8)
hsv = cv2.cvtColor(frame, cv2.COLOR_BGR2HSV)
mask = cv2.inRange(hsv, lower_color_bounds, upper_color_bounds)
res = cv2.bitwise_and(frame, frame, mask=mask)
kernel = np.ones((22, 30), np.uint8)
res = cv2.morphologyEx(mask, cv2.MORPH_CLOSE, kernel)
cv2.imshow("test", res)
cv2.moveWindow("test", 2000, 0)
kernel = cv2.getStructuringElement(cv2.MORPH_RECT, (2, 1))
closed = cv2.morphologyEx(res, cv2.MORPH_CLOSE, kernel)
closed = cv2.erode(closed, kernel, iterations=1)
closed = cv2.dilate(closed, kernel, iterations=1)
(_, tmp2) = cv2.threshold(closed, 0, 255, cv2.THRESH_BINARY)
edges = cv2.Canny(tmp2, 100, 100)
contours, hierarchy = cv2.findContours(edges, cv2.RETR_LIST, cv2.CHAIN_APPROX_SIMPLE)
output = self.current_frame.copy()
for contour in contours:
x, y, w, h = cv2.boundingRect(contour)
cv2.rectangle(self.current_frame, (x, y), (x + w, y + h), AColor.dark_red, 2)
我遇到的问题是我得到了许多嵌套部分,其中没有一个突出显示整个链接。关于如何清理它的任何建议?
解决方案
推荐阅读
- java - jOOQ 中的 UPDATE-FROM 子句引发对 CTE 字段的期望
- graphviz - 在 Graphviz 中对齐集群
- opengl - 绘制一个对象,比较两个不同的模板缓冲区值
- javascript - 如何使用本机 JavaScript 从 AJAX 回调运行 JavaScript .js 文件?
- python - Matplotlib:从保存的图像文件中删除未使用的边框区域
- laravel - 在上传 laravel 项目之前我应该删除什么?
- ruby-on-rails - 使用带有您最喜欢的 css 图标设置的 rails actiontext 扩展 Trix,例如 font-awesome
- if-statement - 条件函数的使用,定义中的条件
- java - 考虑到同步关键字的成本,使延迟初始化线程安全高效的技巧是什么?
- sql - pl/sql函数查找符合贷款条件的客户和贷款金额