2017-09-16 69 views
1

我用下面的代碼來檢測圈:圓檢測是跳躍

gray = cv2.GaussianBlur(gray, (5, 5), 0); 
gray = cv2.medianBlur(gray, 5) 

kernel = np.ones((2, 2), np.uint8) 
gray = cv2.erode(gray, kernel, iterations=1) 

gray = cv2.dilate(gray, kernel, iterations=1) 
circles = cv2.HoughCircles(gray, cv2.HOUGH_GRADIENT, 1, 200, 
          param1=100, param2=50, minRadius=0, maxRadius=150) 


if circles is not None: 
    # Convert the (x,y) coordinate and radius of the circles 
    circles = np.round(circles[0, :]).astype("int") 

    # Loop over the (x,y) coordinate and radius of the circles 
    for (x, y, r) in circles: 
     # Draw the circle in the output 
     cv2.circle(fancy_frame, (x+x1, y+y1), r, (0, 255, 0), 4) 

然而,當我發現的圓跳動。我怎樣才能解決這個問題?有沒有haar或svm來檢測它?

這是我得到的輸出:

Output

我想檢測實時視頻

+0

發佈您的結果和預期結果。 – zindarod

+0

請檢查更新的問題 – user1241241

+0

您必須應用一些跟蹤算法,例如kalman-filter – eyllanesc

回答

1

您的代碼看起來不錯,很有可能你只需要調整HoughCircles parameters各界。

從降低dp參數開始,它應該給你更多的檢測。我來自OpenCV的樣本圖像上的文件夾運行houghcircles.py和檢測最圓的其餘部分:

$ python houghcircles.py your_image.png 

result

霍夫檢測圈是相當重的計算,所以可能很難運行這是實時的。此外,圖像上的「圓圈」還不夠完美,不便於算法。考慮訓練神經網絡來檢測這些特徵。