ITmaster
ITmaster

Reputation: 29

Unsupported format in function medianBlur for USB Camera (Python/RaspberryPI/OpenCV)

I'm creating a test program that would allow the program to find any circles in the image after camera capture, but for some reason, if I used the data from the camera into any function (for this one, medianBlur), an error would return.

error: (-210:Unsupported format or combination of formats) in function 'medianBlur'

Here is the code for the test program:


# initialize the camera
cam = cv2.VideoCapture(0)
ret, image = cam.read()
img = cv2.medianBlur(ret,5)
cimg = cv2.cvtColor(img,cv2.COLOR_GRAY2BGR)

circles = cv2.HoughCircles(img,cv2.HOUGH_GRADIENT,1,20,param1=50,param2=30,minRadius=0,maxRadius=0)

circles = np.uint16(np.around(circles))
for i in circles[0,:]:
    # draw the outer circle
    cv2.circle(cimg,(i[0],i[1]),i[2],(0,255,0),2)
    # draw the center of the circle
    cv2.circle(cimg,(i[0],i[1]),2,(0,0,255),3)
cv2.imshow('SnapshotTest',cimg)
cv2.waitKey(0)
cv2.destroyWindow('SnapshotTest')
cv2.imwrite('/home/pi/Desktop/lol.jpg',image)
cam.release()

Thanks in advance for the help!

Upvotes: 0

Views: 438

Answers (1)

abhilb
abhilb

Reputation: 5757

Problem lies here

ret, image = cam.read()
img = cv2.medianBlur(ret,5)

You are applying medianBlurto ret value instead of image.

Use

img = cv2.medianBlur(image, 5)

Upvotes: 1

Related Questions