我在写一个代码来检测平原上的裂缝。随着时间的推移,平原上的裂缝越来越多。我需要检测新的裂缝,节省时间时,每一个新的裂缝发生
我试过各种方法,但没有一种能满足我的需要。我目前正在做的是获取检测到的线的x和y坐标,并将它们保存在while循环中的一个数组中。因此,当从摄像机检测到新帧时,将检查旧坐标是否与新坐标匹配,如果不匹配,将保存为新的裂纹线。但是这种方法并不实用,因为不是每次都返回相同的cordinate(我使用hough线)
这是我的密码
while(True):
retval,frame=cap.read()
frame = cv2.resize(frame, (480,480))
cv2.imwrite(THIS_FOLDER+"/Specimens/"+specimenName+"/images/"+specimenName+"_"+str(currentCycles)+"_(Baseline).jpg",frame)
points = np.array([[list(boundPointOne), list(boundPointTwo), list(boundPointThree), list(boundPointFour),list(boundPointFive), list(boundPointSix)]])
thresh = cv2.getTrackbarPos("Threshold", "Propagation")
minLength = cv2.getTrackbarPos("Min Line Length", "Propagation")
if(thresh<0):
thresh =1
gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
edges = cv2.Canny(gray, minimumVal, maximumVal, apertureSize = 3)
minimumVal = cv2.getTrackbarPos("Minimum Value", "Edges")
maximumVal = cv2.getTrackbarPos("Maximum Value", "Edges")
croppedFrame=cropROI(frame)
cropped=cropROI(edges)
lines = cv2.HoughLinesP(image=cropped, rho=1, theta=np.pi/180, threshold=int(thresh), minLineLength=minLength, maxLineGap=25)
for i in lineList:
cv2.line(croppedFrame, (i[0],i[1]), (i[2],i[3]), (0,0,255), 1)
if lines is not None:
print("Line Detected")
# Loop through all the coordinates
for x1, y1, x2, y2 in lines[0]:
print("Coming here")
for (x3,y3,x4,y4) in lineList:
if not collinear(x1,y1,x2,y2,x3,y3):
if not collinear(x1,y1,x2,y2,x4,y4):
anglea = np.rad2deg(np.arctan2(y2 - y1, x2 - x1))
print(anglea)
if not anglea<20 and anglea >50 :
lineList.append((x1, y1, x2, y2))
crackTip = (x1, y1, x2, y2)
print("--------------------------- New Line ---------------------------------------")
break
else:
print("-------------------------Linear")
break
elif collinear(x1,y1,x2,y2,x4,y4):
print("-------------------------Linear")
break
else:
crackTip=(0,0,0,0)
print("Exited")
requiredLine= cv2.line(croppedFrame, (crackTip[0],crackTip[1]), (crackTip[2],crackTip[3]), (0,255,0), 2)
cv2.imshow("Edges", edges)
cv2.imshow("Propagation", croppedFrame)
for i in range(1, 10):
cv2.waitKey(1)
这就是我的形象。 带掩模的裂纹探测器1
边缘 检测到的边2
我想你可以试着把裂缝封闭在一个盒子里,然后看看这个盒子是否会随着时间而增长。您可以找到bbox的面积以及高度和长度随时间的变化。这样你就可以监控裂纹的扩展和扩展
使用OpenCV的boundingRect函数找到与您的点对应的封闭bbox,然后在每次迭代中持续监视bbox
相关问题 更多 >
编程相关推荐