2nd post here (I Think) I got an Traceback (most recent call last): File "c:\Users\bala006\OneDrive - St John's Anglican College\Desktop\Personal\Torch\lick.py", line 30, in circles = cv.HoughCircles(img, cv.HOUGH_GRADIENT, 1.2, 100) cv2.error: OpenCV(4.5.1) C:\Users\appveyor\AppData\Local\Temp\1\pip-req-build-kh7iq4w7\opencv\modules\imgproc\src\hough.cpp:2253: error: (-215:Assertion failed) !_image.empty() && _image.type() == CV_8UC1 && (_image.isMat() || _image.isUMat()) in function 'cv::HoughCircles'
error. Hopefully everything is in order... Thanks. I created a cascade using Cascade Trainer and am using it to detect Ping Pong balls.
import cv2 as cv
import numpy as np
camera = cv.VideoCapture(0, cv.CAP_DSHOW)
cascade = cv.CascadeClassifier('cascade.xml')
while(1):
_,img = camera.read()
img = cv.flip(img,1)
hsv = cv.cvtColor(img, cv.COLOR_BGR2HSV)
detector = cv.SimpleBlobDetector()
LowerRegion = np.array([4,142,149],np.uint8)
upperRegion = np.array([33,255,255],np.uint8)
redObject = cv.inRange(hsv,LowerRegion,upperRegion)
kernal = np.ones((1,1),"uint8")
red = cv.morphologyEx(redObject,cv.MORPH_OPEN,kernal)
red = cv.dilate(red,kernal,iterations=1)
res1=cv.bitwise_and(img, img, mask = red)
circles = cv.HoughCircles(img, cv.HOUGH_GRADIENT, 1.2, 100)
if circles is not None:
circles = np.round(circles[0, :]).astype("int")
for (x, y, r) in circles:
cv.circle(img, (x, y), r, (0, 255, 0), 4)
cv.imshow("Masking ",res1)
cv.imshow("please work", img)
if cv.waitKey(10) & 0xFF == ord('q'):
camera.release()
cv.destroyAllWindows()
break