Getting openCV error: Assertion Failed (scn ==3 || scn ==4) in python on RaspberryPi 3 -


i'm trying make gesture controlled lamp following steps shown here https://makezine.com/projects/raspberry-pi-potter-wand/

but i've run issue keep getting assertion failure

def trackwand():      global rval,old_frame,old_gray,p0,mask,color,ig,img,frame     color = (0,0,255)     rval, old_frame = cam.read()     cv2.flip(old_frame,1,old_frame)     old_gray = cv2.cvtcolor(old_frame, cv2.color_bgr2gray)     equalizehist(old_gray,old_gray)     old_gray = gaussianblur(old_gray,(9,9),1.5)     dilate_kernel = np.ones(dilation_params, np.uint8)     old_gray = cv2.dilate(old_gray, dilate_kernel, iterations=1)     # take first frame , find circles in     p0 = cv2.houghcircles(old_gray,cv2.cv.cv_hough_gradient,3,100,param1=100,param2=30,minradius=4,maxradius=15)     try:             p0.shape = (p0.shape[1], 1, p0.shape[2])             p0 = p0[:,:,0:2]      except:             print ("no points found")          # create mask image drawing purposes     mask = np.zeros_like(old_frame)      while true:             rval, frame = cam.read()             cv2.flip(frame,1,frame)             frame_gray = cv2.cvtcolor(frame, cv2.color_bgr2gray)         #equalizehist(frame_gray,frame_gray)     #frame_gray = gaussianblur(frame_gray,(9,9),1.5)     #dilate_kernel = np.ones(dilation_params, np.uint8)         #frame_gray = cv2.dilate(frame_gray, dilate_kernel, iterations=1)             try:              # calculate optical flow                     p1, st, err = cv2.calcopticalflowpyrlk(old_gray, frame_gray, p0, none, **lk_params)          # select points                     good_new = p1[st==1]                     good_old = p0[st==1]                  # draw tracks                     i,(new,old) in enumerate(zip(good_new,good_old)):                             a,b = new.ravel()                             c,d = old.ravel()                     # try detect gesture on highly-rated points (below 15)                             if (i<15):                                     isgesture(a,b,c,d,i)                             dist = math.hypot(a - c, b - d)                             if (dist<movment_threshold):                                     cv2.line(mask, (a,b),(c,d),(0,255,0), 2)                             cv2.circle(frame,(a,b),5,color,-1)                             cv2.puttext(frame, str(i), (a,b), cv2.font_hershey_simplex, 1.0, (0,0,255))             except indexerror:                     print ("index error")                       cam.release()                     cv2.destroyallwindows()                     break                       except:                     e = sys.exc_info()[0]                     print ("error: %s" % (e,))                      cam.release()                     cv2.destroyallwindows()                     break             img = cv2.add(frame,mask)              cv2.puttext(img, "press esc close.", (5, 25),                 cv2.font_hershey_simplex, 1.0, (255,255,255))             cv2.imshow("raspberry potter", frame)          # next frame             rval, frame = cam.read()          # update previous frame , previous points             old_gray = frame_gray.copy()             p0 = good_new.reshape(-1,1,2)             key = cv2.waitkey(20)             if key in [27, ord('q'), ord('q')]: # exit on esc                     break 

this assertion error

initializing point tracking error: module 'cv2' has no attribute 'cv' opencv error: assertion failed (scn == 3 || scn == 4) in cvtcolor, file /home/pi/opencv-3.3.0/modules/imgproc/src/color.cpp, line 10638 traceback (most recent call last): file "rpotter2.py", line 202, in trackwand()
file "rpotter2.py", line 131, in trackwand old_gray = cv2.cvtcolor(old_frame, cv2.color_bgr2gray) cv2.error: /home/pi/opencv-3.3.0/modules/imgproc/src/color.cpp:10638: error: (-215) scn == 3 || scn == 4 in function cvtcolor

i'm new this, appreciated!


Comments

Popular posts from this blog

ZeroMQ on Windows, with Qt Creator -

unity3d - Unity SceneManager.LoadScene quits application -

python - Error while using APScheduler: 'NoneType' object has no attribute 'now' -