c# - 如何在 xamarin 或 c# 或 python 中检测图像中的所有分隔线?
问题描述
我需要检测图像中的所有线条(边缘)以及它们在我的 xamarin 应用程序中的位置。
就像附图中一样。
我在 python 中尝试过 openCV,但仍然没有得到所有的线条,我只有对象周围的边界框和直线,但我也需要检测斜线。
这是我使用的python代码:`
blur = cv2.GaussianBlur(img, (3,3), 0)
canny = cv2.Canny(blur, l_th, u_th)
dilated = cv2.dilate(canny, None, iterations=3)
contours, hierarchy = cv2.findContours(dilated, cv2.RETR_TREE, cv2.CHAIN_APPROX_NONE)
for contour in contours:
(x, y, w, h) = cv2.boundingRect(contour)
cv2.rectangle(coloured_img, (x, y), (x+w, y+h), (0, 255, 0), 2)
原始图像:
我想要的输出:
我得到的输出:
请问有什么建议吗?
解决方案
在 OpenCV 中尝试 HoughLinesP
import cv2
import numpy as np
img = cv2.imread('dave.jpg')
gray = cv2.cvtColor(img,cv2.COLOR_BGR2GRAY)
edges = cv2.Canny(gray,50,150,apertureSize = 3)
minLineLength = 100
maxLineGap = 10
lines = cv2.HoughLinesP(edges,1,np.pi/180,100,minLineLength,maxLineGap)
for x1,y1,x2,y2 in lines[0]:
cv2.line(img,(x1,y1),(x2,y2),(0,255,0),2)
cv2.imwrite('houghlines5.jpg',img)
推荐阅读
- spring-cloud-stream - 如何在 Spring Cloud Stream 函数中定义 Message 的标头值?
- ruby-on-rails - Rails Turbo 在页面重定向中删除 Hubspot 注入的 HTML
- python-3.x - 使用 GitHub 和 GitHub 操作将 flake8 添加到不符合 flake8 的代码库中
- python - 有什么办法可以提高效率吗?Tenable API 报告调用
- sqlite - Golang exec.Command 输出空白(无错误)
- networking - linux内核版本5中'dst_entry'('input'和'output')中两个不同函数的用途
- snakemake - Snakemake:规则的数据依赖条件执行,IndexError
- tableau-api - 是否可以以编程方式创建可以在服务器上发布然后刷新的自定义 SQL Tableau 数据提取?
- ios - 如何在处理通用链接之前等待 didFinishLaunchingWithOptions 完成?
- java - 如何在 Java 中为 Singleton 类编写单元测试?