我的目标是使用OpenCV检测骨折。我尝试了以下代码,并获得了正确的Canny边缘检测和Hough线性变换。但现在我的任务是在图像中检测出骨折点。我不知道该如何进一步处理。在一些博客中,我发现可以通过确定Hough线性变换的角度来检测线条是否直线。但我不知道如何在我的代码中找到Hough线性变换的角度。有人能帮忙吗?
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)