As I have already explained how to interface web cam with BBB here I will talk about capturing image using python script programming. It is simple tutorial where you can also add effects in the form of black and white image, motion detection, sharp picture etc. I have used opencv library which programs functions of real time computer and machine learning.
- Beaglebone Black
- Web Cam
Before proceeding, create a set up as explained in how to interface web cam with BBB. Connect web cam with BBB through USB port. Connect with internet and power up BBB. You have remote access of BBB on desktop.
Fig. 1: Prototype of Beaglebone Black based Security Camera
First of all upgrade your kernel version. (Ignore if already done).
Install the Opencv
Install the opencv on BBB from debian repository or official site. Here I have installed it from debian repository. Run the following commands from command prompt:
sudo apt-get install python-opencv
sudo apt-get install libopencv-dev
Install the Dependencies
You need to install some dependencies like build, image, video, GUI etc in BBB.
Step1: Install build dependency by running following instruction:
sudo apt-get install build-essential cmake
Step2: Install media I/O library by running following instruction:
sudo apt-get install zlib1g-dev libwebp-dev libpng-dev libjasper-dev libtiff5-dev libopenexr-dev libgdal-dev libjpeg-dev
Step3: Install GUI library by running following instruction:
sudo apt-get install qt5-default libvtk6-dev
Step4: Install video I/O library by running following instruction:
sudo apt-get install libavcodec-dev libavformat-dev libdc1394-22-dev libswscale-dev libtheora-dev libxvidcore-dev libx264-dev libvorbis-dev yasm libopencore-amrnb-dev libopencore-amrwb-dev libv4l-dev libxine2-dev libtbb-dev
Getting Started With Program
Open the command terminal and create a new file using touch command with .py extension (i.e. image.py). Open the file with any text editor (i.e. nano, vim etc.) and write a code in python language.
Opencv is a great library of machine learning and computer science written in C, C++, java and python. It supports great functionality of image and video processing and works well on embedded Linux platform. You need to read the image from web cam device which is attached with BBB. It will be zero if single webcam is connected. So just pass zero from function as the following:
cam = cv2.VideoCapture(0)
Fig. 2: Image of Webcam connected to Beaglebone Black
I created frame size of 1280 x 720 which works well with BBB. You can adjust frame size as per you wish which is supported by library. Set the frame size of image by following functions:
cam.set (cv2.cv.CV_CAP_PROP_FRAME_WIDTH, 1280)
cam.set (cv2.cv.CV_CAP_PROP_FRAME_HEIGHT, 720)
Now, capture the image from device (i.e web cam) by following function:
Provide at least 10 ms delay after capturing image by following function:
If you want to show image on screen, run the following function:
cv2.imshow (“Test Picture”, img)
Save the image file with specific name by following function:
cv2.imwrite (“demopic.bmp”, img)
Filed Under: Electronic Projects