Getting the Webcam Working in Linux

Getting the camera to work in Ubuntu was super easy, it was plug and play.  The camera worked immediately with a webcam software called Camorama.
But I wanted to get some working c++ code that interacts with the camera.  For this exercise, just simply taking a snapshot from the webcam and saving it as a jpeg.
Thanks to Google, I found some sample code here that does just that!
Getting this to compile was a bit tricky, turns out I was missing libjpeg library so I had to download it with:
sudo apt-get install libjpeg62-dev
The code isn’t too bad either, it is just using l4v2 (Linux For Video v2) to communicate with the camera which returns images in YUV format.  That image is then converted to RGB and passed along to the jpeg library for compression and saving to a file.
Here’s the first image from the camera!
Oh yeah, I also put the robotic platform together last weekend (as you can see from the shot), I’ll discuss that in another post!

Leave a Reply

Your email address will not be published. Required fields are marked *