Opencv/Hough Circles: How to stop program from crashing when circles is none

Viewed 43

I have the following code:


import cv2
import numpy as np
import time
from datetime import timedelta

lower = np.array([35, 192, 65])
upper = np.array([179, 255, 255])

video = cv2.VideoCapture(1, 0)

while True:
    success, img = video.read()
    img = img[80:440, 30:602]
    image = cv2.cvtColor(img, cv2.COLOR_BGR2HSV)
    mask = cv2.inRange(image, lower, upper)
    blur = cv2.GaussianBlur(mask, (15, 15), 0,)

    circles = cv2.HoughCircles(blur, cv2.HOUGH_GRADIENT, 1, 14,
                               param1=30, param2=10, minRadius=3, maxRadius=10)

    circles = np.uint16(np.around(circles))
    for i in circles[0, :]:
        # draw the outer circle
        cv2.circle(img, (i[0], i[1]), i[2], (0, 255, 0), 2)
    # draw the center of the circle
    cv2.circle(img, (i[0], i[1]), 2, (0, 0, 255), 3)

    if cv2.waitKey(1) & 0xFF == ord('q'):

        break

This program detects coloured objects in a live video, how do i make it so when circles is none, instead of stopping the program, make it so it carries on checking for circles.

This is the current error:

TypeError: loop of ufunc does not support argument 0 of type NoneType which has no callable rint method
0 Answers
Related