python opencv cv2.cv.CV_CAP_PROP_FRAME_COUNT get wrong numbers -


import os import cv2 path='/home/nlpr4/video-data/ucf-101/golfswing/v_golfswing_g24_c06.avi' cap=cv2.videocapture(path) video_length=int(cap.get(cv2.cv.cv_cap_prop_frame_count))  success=true count=0 while success:     success,image=cap.read()     if success==false:         break     count=count+1  print video_length,count 

output:

149  146 

why 2 numbers different? what's wrong?

try code:

#!/usr/bin/env python  import numpy np import cv2  video = "../videos/sample.avi"  video_capture = cv2.videocapture(video) video_length = int(video_capture.get(cv2.cap_prop_frame_count))  count = 0 while(true):         # capture frame-by-frame         ret, frame = video_capture.read()         if not ret:             break          count += 1  print video_length, count # when done, release capture video_capture.release() cv2.destroyallwindows() 

on machine gives me:

$ ./openstack_video_frames.py  1232 1232 

Comments