我正在写一段代码来检测平原上的裂缝。随着时间的推移,plain得到了更多的裂缝。我需要检测新的裂缝,并节省每次新裂缝发生的时间。
我尝试过各种方法,但都不能满足我的需要。i.m当前所做的是获取检测到的行的x和y坐标,并将它们保存在while循环中的数组中。因此,当从摄像头检测到新帧时,将检查旧坐标是否与新坐标匹配,如果不匹配,则将其保存为新的裂纹线。但这种方法并不实用,因为它并不是每次都返回相同的行坐标(我使用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
发布于 2019-07-17 03:46:39
我认为您可以尝试将裂缝封闭在bbox中,然后看看bbox是否随着时间的推移而增长。您可以找到bbox的面积以及高度和长度随时间变化的方式。通过这种方式,您可以监控裂缝的扩展以及增长。
使用OpenCV的boundingRect函数找到关闭的bbox,然后在每次迭代中持续监视bbox。
https://stackoverflow.com/questions/57064360
复制相似问题