Discussion:
Getting started
Chris Barnes
2014-10-10 16:41:54 UTC
Permalink
I'm a new grad student who's spent the last 3 days trying to grab some
frames from a .avi with zero success. I've tried pythons 2 and 3, openCV,
simpleCV, simpleITK, scikit-image, and ffmpeg, and have run into different
issues with each. Is it really that hard? There's next to no documentation
around for all of them, for sure.

All of the above claim to have installed correctly (e.g. skimage, SimpleITK
and SimpleCV can be imported fine, openCV responds fine to cv2.__version__,
which is what they claim defines a healthy install).

I guess the nut to crack is openCV as that's the one that's talked about
most on the internet. However, using this code snippet
from http://opencv-python-tutroals.readthedocs.org/en/latest/py_tutorials/py_gui/py_video_display/py_video_display.html

import numpy as np
import cv2

cap = cv2.VideoCapture('vtest.avi')

while(cap.isOpened()):
ret, frame = cap.read()

gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)

cv2.imshow('frame',gray)
if cv2.waitKey(1) & 0xFF == ord('q'):
break

cap.release()
cv2.destroyAllWindows()


cap.isOpened() is always false, so no reading gets done.

I know that skimage uses openCV as the backend, but I gave it ago anyway,
using this snippet from http://scikit-image.org/docs/dev/api/skimage.io.html

class AVILoader:
video_file = 'myvideo.avi'

def __call__(self, frame):
return video_read(self.video_file, frame)

avi_load = AVILoader()

frames = range(0, 1000, 10) # 0, 10, 20, ...
ic = ImageCollection(frames, load_func=avi_load)

x = ic[5] # calls avi_load(frames[5]) or equivalently avi_load(50)


Of course, that's junk too because video_read just isn't a function. Google
gets 8 results associating video_read with skimage.

I also tried this method to get the video straight into a numpy
array http://zulko.github.io/blog/2013/09/27/read-and-write-video-frames-in-python-using-ffmpeg/

It took a long time, crash my IDE a couple of times, and came up with no
data at the end.

I'm frustrated. How do you get started?
--
You received this message because you are subscribed to the Google Groups "pythonvision" group.
To unsubscribe from this group and stop receiving emails from it, send an email to pythonvision+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/***@public.gmane.org
For more options, visit https://groups.google.com/d/optout.
Stéfan van der Walt
2014-10-10 23:39:11 UTC
Permalink
Hi Chris
Post by Chris Barnes
I'm a new grad student who's spent the last 3 days trying to grab some
frames from a .avi with zero success.
Sorry, video grabbing is a bit hairy at the moment.

We're working on some documentation here:

https://github.com/scikit-image/scikit-image/pull/1012/files

You may also have some success with the video module that we removed
because we could not guarantee its working on all platforms:

https://github.com/scikit-image/scikit-image/pull/961/files

Alternatively, you can convert your .avi to .png frames using ffmpeg,
vlc, mdecoder, etc. Let us know if you need a hand.

Regards
Stéfan
--
You received this message because you are subscribed to the Google Groups "pythonvision" group.
To unsubscribe from this group and stop receiving emails from it, send an email to pythonvision+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/***@public.gmane.org
For more options, visit https://groups.google.com/d/optout.
Chris Barnes
2014-10-13 16:45:01 UTC
Permalink
Thanks Stefan (and Christoph), I've managed to get some frames out of the
.avi just using ffmpeg.

I had assumed that that was the easiest way to do video analysis, but I
suppose working directly with the video would be the way to go for speed -
which brings me back to openCV. Any idea why that code snippet may be
failing? cap.isOpened() always returns false, so it never hits the code in
the while loop.
Post by Stéfan van der Walt
Hi Chris
Post by Chris Barnes
I'm a new grad student who's spent the last 3 days trying to grab some
frames from a .avi with zero success.
Sorry, video grabbing is a bit hairy at the moment.
https://github.com/scikit-image/scikit-image/pull/1012/files
You may also have some success with the video module that we removed
https://github.com/scikit-image/scikit-image/pull/961/files
Alternatively, you can convert your .avi to .png frames using ffmpeg,
vlc, mdecoder, etc. Let us know if you need a hand.
Regards
Stéfan
--
You received this message because you are subscribed to the Google Groups "pythonvision" group.
To unsubscribe from this group and stop receiving emails from it, send an email to pythonvision+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/***@public.gmane.org
For more options, visit https://groups.google.com/d/optout.
Christoph Gohlke
2014-10-11 02:41:44 UTC
Permalink
Post by Chris Barnes
I'm a new grad student who's spent the last 3 days trying to grab some
frames from a .avi with zero success. I've tried pythons 2 and 3,
openCV, simpleCV, simpleITK, scikit-image, and ffmpeg, and have run into
different issues with each. Is it really that hard? There's next to no
documentation around for all of them, for sure.
In case you are using Windows, try vidsrc
<http://www.lfd.uci.edu/~gohlke/code/vidsrc.cpp.html>, which reads frame
data of video files via
Microsoft's DirectShow IMediaDet interface. Binaries are included in the
vLFD package installer at <http://www.lfd.uci.edu/~gohlke/pythonlibs/#vlfd>

from vidsrc import VideoSource
video = VideoSource("test.avi")
for frame in video:
print(frame.mean())

Christoph
--
You received this message because you are subscribed to the Google Groups "pythonvision" group.
To unsubscribe from this group and stop receiving emails from it, send an email to pythonvision+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/***@public.gmane.org
For more options, visit https://groups.google.com/d/optout.
Loading...