Saturday, 27 March 2021

opencv 24 houghcircle | circle detection


houghcircle detection after blurring gray image

blur


#main.py
import numpy as np
import cv2

cap = cv2.VideoCapture("assets/plate.mp4")

while True:
    ret, frame = cap.read()
    width = int(cap.get(3))
    height = int(cap.get(4))

    gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)

    blur = cv2.medianBlur(gray, 5)


    circles = cv2.HoughCircles(blur, cv2.HOUGH_GRADIENT, 1, 50, param1=50,
                               param2=50, minRadius=10, maxRadius=100)

    if not circles is None:
        detected_circles = np.uint16(np.around(circles))

        for (x, y, r) in detected_circles[0, :]:
            cv2.circle(frame, (x, y), r, (0, 255, 0), 2)

    cv2.imshow('frame', frame)
    cv2.imshow('gray', gray)
    cv2.imshow('blur', blur)


    if cv2.waitKey(1) == ord('q'):
        break

    if cv2.waitKey(1) == ord('p'):
        # wait until any key is pressed
        cv2.waitKey(-1)

cap.release()
cv2.destroyAllWindows()

reference:

No comments:

Post a Comment