How to find angle of hough lines detected?

丶灬走出姿态 提交于 2021-02-07 04:01:34

问题


My goal is to detect the fractured bone using open cv. I tried the following code. and got correct canny detection edges.and also found houghlines.But now my job is to detected the fractured spot in the image. Iam not understanding how to proceed further. In some blogs i found the we can determine angle of houghlines to detect that line is not staright. But not knowing how to find angle of houghline in my code. Can someone help?

import cv2
import numpy as np
import math
img = cv2.imread('bone2.jpg')
gray = cv2.cvtColor(img,cv2.COLOR_BGR2GRAY)
edges = cv2.Canny(gray,100,400,apertureSize =3)
cv2.imshow('canny',edges)
kernel=np.ones((5,5),np.uint8)
boneEdges=cv2.morphologyEx(edges,cv2.MORPH_GRADIENT,kernel)
minLineLength =1000
maxLineGap = 10
lines = cv2.HoughLinesP(boneEdges,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)
 slope=(y2-y1),(x2-x1)
 # print('slope',arctan(slope))
cv2.imwrite('houghlines5.jpg',img)
cv2.waitKey(0)


回答1:


This function returns a list of rho theta sets where theta is the angle you are looking for. Here are the docs.



来源:https://stackoverflow.com/questions/36960007/how-to-find-angle-of-hough-lines-detected

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!