Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

I am new to OpenCV and I am using the python version of it to read out the frames of a video so that I can do some analysis on them. I am reading an mp4 video file and looping through the frames to save them off like so:

import cv2
cv2Cap = cv2.VideoCapture(filepath)
frames = []
cnt = 0 
while 1:
    # get the next frame form the video 
    ret, frame = cv2Cap.read()
    cnt+=1
    print 'Count: ' + str(cnt)
    if not ret: 
        break # means ret was false so break out of the loop 
    cv2.imshow('Frames', frame)
    # show the frame that was read to make sure it is normal
    k = cv2.waitKey(1) & 0xff
    if k == 27:
        break
    frames.append(frame) 

This code works most of the time, however, I have seen it break on a couple different videos as follows:

OpenCV Error: Unspecified error (The numpy array of typenum=2, ndims=3 can not b
e created) in NumpyAllocator::allocate, file D:\Build\OpenCV\OpenCV-2.4.9\module
s//python//src2//cv2.cpp, line 201
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "vidUtils.py", line 25, in __init__
    self.frames, self.fps, self.numFrames = self.getVideoInfo(filepath)
  File "vidUtils.py", line 57, in getVideoInfo
    ret, frame = cv2Cap.read()
cv2.error: D:\Build\OpenCV\OpenCV-2.4.9\modules//python//src2//cv2.cpp:201: erro
r: (-2) The numpy array of typenum=2, ndims=3 can not be created in function Num
pyAllocator::allocate

I am printing out the frame number that the code fails on and it is not always consistent, which makes me think that there is something else going on that I'm completely missing. It has been lately kirking out at 1780-1820 frames. Any help or suggestions would be greatly appreciated!

Thanks in advance!
~zoltana

share

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.