Ask Your Question

Revision history [back]

Basic example halts partway through video

I'm using a basic example from

http://opencv-python-tutroals.readthedocs.org/en/latest/py_tutorials/py_gui/py_video_display/py_video_display.html

as a basis for a rat-tracking program. It's working great, except for the following issue.

It runs for the first 45 seconds of the video, then gives the error "OpenCV Error: Assertion failed ((scn == 3 :: scn == 4) && (depth == CV_8U :: depth == CV_32F))" at the same frame each time. It gives this error for multiple videos, at slightly different points in each video. I tried converting the video to an avi format- it stops at the same point. There is nothing visually wrong with the video (I can watch it fine on normal video players). I've tried googling the problem, to no avail. Any suggestions would be appreciated.

import numpy as np
import cv2

cam = cv2.VideoCapture('Video2.wmv')

frames=0
while(True):
    # Capture frame-by-frame
    ret, frame = cam.read()
    frames=frames+1
    print frames
    # Our operations on the frame come here
    gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)

    # Display the resulting frame
    cv2.imshow('frame',gray)
    if cv2.waitKey(1) & 0xFF == ord('q'):
        break

print frames
# When everything done, release the capture
cap.release()
cv2.destroyAllWindows()