我的目標是用open cv檢測骨折。我試了下面的代碼。並得到了正確的canny檢測邊緣,並且發現了很多缺陷。但現在我的工作是檢測圖像中的裂縫點。 Iam不理解如何進一步進行。在一些博客中,我發現我們可以確定houghlines的角度,以檢測該行不是直角。但不知道如何在我的代碼中找到houghline的角度。有人可以幫忙嗎?
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)
http://stackoverflow.com/questions/24031701/how-can-i-determine-the-angle-a-line-found-by-houghlines-function-using-opencv –