检测随时间传播的裂缝

时间:2019-07-16 19:39:32

标签: python opencv

我正在编写代码以检测平原上的裂缝。到时候,平原会出现更多裂缝。我需要检测新裂缝并节省每次发生新裂缝的时间。

我尝试了各种方法,但是没有一种能满足我的需要。我目前正在做的是获取检测到的线的x和y坐标,并将它们保存在while循环中的数组中。因此,当从摄像机检测到新帧时,将检查旧坐标是否与新坐标匹配,如果不匹配,则将其另存为新裂缝线。但是这种方法不切实际,因为并不是每次它都返回相同的坐标线(使用粗线)

这是我的代码

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

1 个答案:

答案 0 :(得分:0)

我认为您可以尝试将裂缝包含在bbox中,然后查看bbox是否随时间增长。您可以找到bbox的区域以及高度和长度随时间的变化。这样,您可以监视裂缝的扩展以及扩展。

使用OpenCV的boundingRect函数找到要关闭的bbox,然后在每次迭代中继续监视bbox。