简体   繁体   中英

OpenCV cap.get(cv2.CAP_PROP_FRAME_COUNT) returning -1

I recently setup opencv 3.0 for python on my ubuntu pc using the following tutorial http://www.pyimagesearch.com/2015/06/22/install-opencv-3-0-and-python-2-7-on-ubuntu/

So I ran the following code to get the number of frames of an mp4 video

   import cv2

   cap = cv2.VideoCapture('vid.mp4')
   length = int(cap.get(cv2.CAP_PROP_FRAME_COUNT))
   print length 

Strangely I get "-1" as output for "length". The video does infact load and I get accurate values for

   int(cap.get(cv2.CAP_PROP_FRAME_HEIGHT))  #480

and

   int(cap.get(cv2.CAP_PROP_FRAME_WIDTH))   #640

so its a wonder why frame count doesn't work. Please Help.

The problem was with the opencv build (as it also occured in c++). I ended up re-building my opencv and everything worked fine after

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM