[英]How to detect all the separation lines in image in xamarin or c# or python?
I need to detect all the lines (edges) in an image an their positions in my xamarin application .我需要检测图像中的所有线条(边缘)及其在我的 xamarin 应用程序中的位置。
like in the image attached .就像所附的图片。
I have tried openCV in python but still I did not get all the lines , I only got boundary boxes around the objects and only straight lines , but I need to detect the sloping lines too .我已经在 python 中尝试了 openCV,但仍然没有得到所有的线条,我只有对象周围的边界框和直线,但我也需要检测斜线。
here is the python code I used :`这是我使用的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 :我得到的输出:
any suggestions please ?请问有什么建议吗?
Try HoughLinesP in OpenCV在 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)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.