Ask Your Question

Revision history [back]

Getting openCV error: Assertion Failed

I'm using opencv 3.1 in RaspberryPi 3. I,m trying to run the following Hough Circle detection algorithm

! /usr/bin/python

import numpy as np import cv2 from cv2 import cv

VInstance = cv2.VideoCapture(0) key = True

""" params = dict(dp, minDist, circles, param1, param2, minRadius, maxRadius) """ def draw_circles(circles, output):

if circles is not None:

    for i in circles[0,:]:
        #draw the outer circle,(i[0],i[1]),i[2],(0,255,0),2)
        #draw the centre of the circle,(i[0],i[1]),2,(0,0,255),3)
        print("The number of circles if %d" %(circles[0].shape[0]))      
elif circles is None:
    print ("The number of circles is 0")

if __name__ == '__main__':

while key:
    ret,img =
    ## Smooth image to reduce the input noise

    imgGray = cv2.cvtColor(img,cv2.COLOR_BGR2GRAY)
    imgSmooth = cv2.GaussianBlur(imgGray,(5,5),3)

    ## Compute Hough Circles
    circles = cv2.HoughCircles(imgSmooth,,1,100,

    ## Display the circles
    cv2.imshow('detected circles',imgGray)
    k = cv2.waitKey(1)
    if k == 27:

But I'm getting Assertion Failed error, details are below. OpenCV Error: Assertion failed (scn == 3 || scn == 4) in cvtColor, file /home/pi/opencv-3.1.0/modules/imgproc/src/color.cpp, line 8000 Traceback (most recent call last): File "", line 70, in <module> imgGray = cv2.cvtColor(img,cv2.COLOR_BGR2GRAY) cv2.error: /home/pi/opencv-3.1.0/modules/imgproc/src/color.cpp:8000: error: (-215) scn == 3 || scn == 4 in function cvtColor

Can anyone please check and help!