Getting RAW images using Python

144 views
Skip to first unread message

David Haberthür

unread,
Dec 9, 2013, 5:45:37 AM12/9/13
to tisc...@googlegroups.com
Dear all.

I'm using a Linux compatible camera from TIS [1] to get images from a scintillation screen (after some x-rays) have passed the sample.

I prefer working with Python, since that enables me to be up and running fast.
For this I made a script that uses a combination of available tools (v4l2-ctl, mplayer and ffmpeg) to set the exposure time, preview the image and save the video stream to images on disk.
At the moment I'm saving the video stream to jpg-frames, which obviously introduces compression artefacts, thus reducing the available resolution.
Is there a way I can access/save the RAW video stream from the camera using Python (or any other way)?

Or do I need to capture the stream to a lossless video and then extract the single frames in a second step?

David

[1]: https://groups.google.com/d/msg/tiscamera/cIxbDSjbDSc/NE_p299ncOoJ
[2]: https://github.com/habi/GlobalDiagnostiX/blob/master/ReadCamera.py

Edgar Thier

unread,
Dec 9, 2013, 10:02:36 AM12/9/13
to tisc...@googlegroups.com
Hi,

There are several possibilities you have here.
1. Use gstreamer. gstreamer has good python bindings and would allow you to display a preview and retrieve single images from the stream without to mush hassle.
This would keep everything relatively simple.
This shell command:
> gst-launch-0.10 v4l2src device=/dev/video0 ! video/x-raw-gray,width=640,height=480 ! ffmpegcolorspace ! filesink location=test0.avi
would dump the retrieved buffers directly into a video file and
> mplayer test0.avi -demuxer rawvideo -rawvideo w=640:h=480:y8
would play that file.

2. OpenCV. Although I have no experience with opencv it certainly has abilities that could be useful for you application.

3. You could try some kind of piping. i.e. pipe the output from ffmpeg to another ffmpeg instance that handles the image dumps. This is certainly messy and not in any way preferable to gstreamer.

Unless you have some kind of restriction concerning packages etc. that you are unable to use I would go with gstreamer.

I hope this helps you.

Cheers,

Edgar


David Haberthür

unread,
Dec 10, 2013, 11:26:10 AM12/10/13
to tisc...@googlegroups.com
Dear Edgar.

Thanks for the prompt reply.

At the moment I'm bound to use ScientificLinux6, which is notoriously hard to use with multimedia stuff.
I couldn't manage to get `gstreamer` to correctly save a video.

After some thinking, I got it to work using two runs of `ffmpeg`, the first one to save an uncompressed video and the second one to convert this video to a series of TIFF files.
If you're interested, you can find the Python script I wrote in my [GitHub] repository.

I'll reconsider your suggestion once I switched my office computer from SL6 to Ubuntu 12.04, which should make lot's of stuff easier.

Thanks, David

[GitHub]: http://git.io/pKdkMw
Reply all
Reply to author
Forward
0 new messages