Ask Your Question
0

Error while running video

asked 2016-02-04 11:20:07 -0600

pawan gravatar image

updated 2016-02-04 11:23:15 -0600

berak gravatar image

When I try to run a video I get the following error. The video runs then the error occurs. I am unable to find any information about this error.
\modules\imgproc\src\color.cpp:3961: error: (-215) (scn == 3 || scn == 4) && (depth == CV_8U || depth == CV_32F) in function cv::cvtColor

The code I am running is

    greenLower = np.array([26, 86, 6],dtype=np.uint8)
    greenUpper = np.array([90, 255, 255],dtype=np.uint8)

    cap =  cv2.VideoCapture('E:/PYTHON SCRIPTS/Learning python/metronome1.mp4')
    print cap.grab()
    while(cap.isOpened()):
      ret, frame = cap.read()

      gray = cv2.cvtColor(frame, cv2.COLOR_RGB2HSV)
      mask = cv2.inRange(gray, greenLower, greenUpper)
      mask = cv2.erode(mask, None, iterations=2)
      mask = cv2.dilate(mask, None, iterations=2)
      cv2.imshow('duck',mask)
      if cv2.waitKey(1) & 0xFF == ord('q'):
          break

Thanks

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
1

answered 2016-02-04 11:26:28 -0600

berak gravatar image

updated 2016-02-04 11:31:34 -0600

you will have to check the ret value inside your loop, like this:

while(cap.isOpened()):
  ret, frame = cap.read()
  if not ret: # the movie's over, we can go home.
     break

(if the video finished, there are no more frames to retrieve, and VideoCapture returns empty (None) frames. if you throw those at cvtColor or such, you will get this error msg)

edit flag offensive delete link more

Comments

Thanks a million berak that solved it !

pawan gravatar imagepawan ( 2016-02-04 11:46:49 -0600 )edit

Question Tools

1 follower

Stats

Asked: 2016-02-04 11:20:07 -0600

Seen: 215 times

Last updated: Feb 04 '16