c# - 如何在 xamarin 或 c# 或 python 中检测图像中的所有分隔线?

标签 c# opencv xamarin object-detection straight-line-detection

我需要检测图像中的所有线条(边缘)及其在我的 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)

原图:

the original image

我想要的输出:

the output that I want

我得到的输出:

the output that I got

有什么建议吗?

最佳答案

在 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)

More info - OpenCV doc

关于c# - 如何在 xamarin 或 c# 或 python 中检测图像中的所有分隔线?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57542916/

相关文章:

python - OpenCV-检测颜色范围并在控制台上显示

c# - Xamarin - 将 ESRI MapView 动态添加到 FrameLayout

c# - Xamarin.Forms Scrollview 不会滚动

android - 我是 xamarin 新手,想在我的 xamarin.forms 项目中实现对话框

c# - 为什么此 Entity Framework LINQ 查询不会产生 SELECT DISTINCT?

c# - 中国日期 - 在有效的日期时间无法识别字符串

c# - 为什么不同版本的 Visual Studio 会输出相同代码的不同结果?

c# - 使用 Jquery Ajax 将模型和 2 个复选框列表发布到 Controller

c++ - 使用 OpenCV 在轮廓线上标记点

c++ - 从 uint16 指针创建 Mat