Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Video file reading by OpenCV is very slow in Python

I'm trying to use OpenCV from Python for some video processing and it works extremely slow for me. For example a simple reading and showing of all frames works at about 1 fps:

import cv2
cap = cv2.VideoCapture("out1.avi")
cv2.namedWindow("input")
while(True):
    f, img = cap.read()
    cv2.imshow("input", img)
    cv2.waitKey(1)

The same video file in C++ is rendered without any problems at about 30 fps. Are there any ideas why Python version is so slow?

And there is another interesting thing about Python version: it doesn't show .wmv files which C++ version can process (for my Python can open raw video only).

I use OpenCV 2.3.1 and Python 2.7

Thanks for help!

like image 658
Akson Avatar asked Nov 26 '11 00:11

Akson


1 Answers

The code runs normally (fast) in my machine (opencv 2.3.0 & python 2.6.4 on win7-64, playing uncompressed avi file).

have you tried the performance using older python interface (cv instead of cv2)?

regarding .wmv video playback, it's kinda having problem with python interface (or specifically the ffmpeg). it can't play other than uncompressed .avi files.

like image 95
Peb Avatar answered Nov 03 '22 00:11

Peb