I'm programming in python on a Raspberry Pi Zero and I want to capture an image from a USB webcam and I can't find a way of doing this without OpenCV. I don't want to use OpenCV because it's way overkill in features and size for what I'm doing (just taking a raw image from a camera, no processing) and it will take 10+ hours to compile on a Pi Zero. Please tell me there is another way. Pygame was mentioned in another similar question but that only works on Windows. Any ideas or must I sacrifice a half GB of flash to the OpenCV gods and spend 10+ hours compiling its code just to take an image?
Asked
Active
Viewed 2,797 times
2
-
1@Coldspeed - The OP wants to do it **without** OpenCV. – rayryeng Aug 02 '17 at 05:33
-
@rayryeng has it right. This question is not answered by the linked question and is not yet shown to be a duplicate. – amoose136 Aug 02 '17 at 06:13
-
1While Picamera works for ribbon cameras, I don't think it supports USB cameras and I'm using a Rpi zero v1 which does not have a ribbon port. – amoose136 Aug 04 '17 at 17:51
-
Given the said intent - how about inspecting the dependency-graph of the source-code needed for the capture-services and creating a minimalistic-supporting-set for such an RPi compilation? Seems to take less than 10+ hours and ought be resources just-enough. – user3666197 Aug 09 '17 at 20:48
-
I don't know exactly how to do this and estimate it would take me on order 10 hours to find out. In the OpenCV solution it probably is cython underneath and I also have no experience with cython. – amoose136 Aug 09 '17 at 21:03
-
Regardless of how you deal with *this* question, you should probably set up a cross-compiler so you *never* have to compile on the actual target board. – o11c Aug 09 '17 at 21:54
-
For the OpenCV I currently am using, I transferred the SD card to a Pi 3 and did a multi core compile there before transferring back to the Pi Zero. This made compile time under 2 hours instead of 10+. – amoose136 Aug 10 '17 at 03:27
2 Answers
1
It looks like there are ctypes bindings to the Video 4 Linux 2 userspace libraries.
ctypes is icky (replace with cffi if you have time, then send that package's authors a patch), but they should work.

o11c
- 15,265
- 4
- 50
- 75
-
1Note to others that v4fl2 is py3 only but the end of life for py2 is 2020 and so you should only be writing for py3 at this point anyway. – amoose136 Aug 15 '17 at 18:30
0
Have you taken a look at fswebcam? I used this in the past on a project I had been doing. It was very easy to install and use, which is a good indicator to me that it will be easy and quick to set up on your RPi Zero. The linked docs page should be enough to get you started to see if it works well for you, but it's definitely worth a try if you haven't!

Mark R
- 337
- 2
- 9
-
I did see fswebcam but fswebcam is a binary with no python API. This means I'd need to use subprocess to launch it which makes a separate thread and uses extra resources just to keep checking if the process is complete. Direct access is far better, especially on a single core processor. – amoose136 Aug 09 '17 at 21:01
-
@amoose136 That's the wrong mindset. Processes aren't particularly heavy if you aren't using them in silly ways. Capturing a screenshot is a perfectly reasonable use. – o11c Aug 09 '17 at 21:50
-
In the current implementation I'm also running realtime audio processing to isolate and detect changes in the intensity of a particular audio frequency and any slowdowns impact the performance of this on the Pi Zero because the processor is barely fast enough to do this in the first place. – amoose136 Aug 10 '17 at 03:24