Ask Your Question
0

Python OpenCV - How to read AVI file

asked 2018-07-24 00:15:33 -0500

Nbb gravatar image

updated 2018-07-24 00:22:46 -0500

How can i read an avi file using python opencv ? The following code below does not work

import numpy as np
import cv2
import os

cap = cv2.VideoCapture('/home/ast/datasets/ewap/seq_eth/seq_eth.avi')

ret, frame = cap.read()
print(ret)
print(np.shape(frame))

I get output

False
()

I have verified that the file /home/ast/datasets/ewap/seq_eth/seq_eth.avi does exist

edit retag flag offensive close merge delete

Comments

how did you install cv2 ? (the PIP version can't read any video files)

berak gravatar imageberak ( 2018-07-24 00:17:19 -0500 )edit

i used this command conda install -c menpo opencv3

Nbb gravatar imageNbb ( 2018-07-24 00:22:16 -0500 )edit
1

conda - bad idea. and the same problem. try a cv2.getBuildInformation() , there is a VideoIO section there.

you'll see it's lacking all backends like gstreamer & ffmpeg

berak gravatar imageberak ( 2018-07-24 00:25:44 -0500 )edit

ah ok ty. so how should I install it then ? also, how can i get rid of the current install of opencv ?

Nbb gravatar imageNbb ( 2018-07-24 00:31:25 -0500 )edit
berak gravatar imageberak ( 2018-07-24 00:36:33 -0500 )edit

jeez. there is no easier solution...?

Nbb gravatar imageNbb ( 2018-07-24 00:43:40 -0500 )edit

no, there isnt.

berak gravatar imageberak ( 2018-07-24 00:49:05 -0500 )edit

1 answer

Sort by ยป oldest newest most voted
0

answered 2018-07-24 02:04:29 -0500

Nbb gravatar image

updated 2018-07-24 02:04:58 -0500

I found an easier solution ! I can read .avi files but am not able to use cv2.imshow() so I used matplotlib instead to show the image. https://github.com/ContinuumIO/anacon...

conda install -c anaconda opencv

The code below now works

import numpy as np
import cv2
import matplotlib.pyplot as plt

# read video
cap = cv2.VideoCapture('/home/ast/datasets/ewap/seq_eth/seq_eth.avi')

ret, frame = cap.read()    
plt.figure()
plt.imshow(frame)

Using cv2.imshow however does not work with the following error

error                                     Traceback (most recent call last)
<ipython-input-11-fc947d934e1a> in <module>()
     20 #plt.figure()
     21 #plt.imshow(frame)
---> 22 cv2.imshow('Frame', frame)

error: OpenCV(3.4.1) /opt/conda/conda-bld/opencv-suite_1527005194613/work/modules/highgui/src/window.cpp:636: error: (-2) The function is not implemented. Rebuild the library with Windows, GTK+ 2.x or Carbon support. If you are on Ubuntu or Debian, install libgtk2.0-dev and pkg-config, then re-run cmake or configure script in function cvShowImage
edit flag offensive delete link more

Question Tools

1 follower

Stats

Asked: 2018-07-24 00:15:33 -0500

Seen: 7,376 times

Last updated: Jul 24 '18