As I already explained how to interface web cam with BBB here I will talk about image capture using python script programming. It is a simple tutorial where you can also add effects in the form of black and white image, motion detection, sharp image, etc. I used the opencv library which programs real-time computer functions and machine learning.
Required tools:
- Black Beaglebone
- webcam
Environment Setting
Before proceeding, create a configuration as explained in how to interface the web cam with BBB. Connect the webcam to the BBB via the USB port. Connect to the internet and turn on BBB. You have remote access from BBB on your desktop.
Fig. 1: Security camera prototype based on Beaglebone Black
First of all, update your kernel version. (Ignore if you have already done so).
Install OpenCV
Install opencv on BBB from the debian repository or official website. Here I installed from debian repository. Run the following commands at the command prompt:
sudo apt-get install python-opencv
sudo apt-get install libopencv-dev
Install dependencies
You need to install some dependencies like build, image, video, GUI etc. at BBB.
Step 1: Install the build dependency by performing the following instructions:
sudo apt-get install build-essential cmake
Step 2: Install the media I/O library by performing the following instructions:
sudo apt-get install zlib1g-dev libwebp-dev libpng-dev libjasper-dev libtiff5-dev libopenexr-dev libgdal-dev libjpeg-dev
Step 3: Install the GUI library by performing the following instructions:
sudo apt-get install qt5-default libvtk6-dev
Step 4: Install the video I/O library by performing the following instructions:
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 – developer
Introduction to the program
Open 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 code in python language.
Opencv is a great machine learning and computer science library written in C, C++, java and python. It supports excellent image and video processing functionality and works well on the embedded Linux platform. You need to read the image from the web cam device that is connected to the BBB. It will be zero if a single webcam is connected. So, just pass zero from the function as follows:
camera = cv2.VideoCapture(0)
Fig. 2: Image of the webcam connected to the Beaglebone Black
I created a frame size of 1280 x 720 which works well with BBB. You can adjust the frame size as you like, compatible with the library. Set the image frame size through the 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 the device (i.e. web cam) by following the function:
cam.read()
Provide a delay of at least 10 ms after image capture by following the function:
cv2.waitKey(10)
If you want to show the image on the screen, perform the following function:
cv2.imshow (“Test Image”, img)
Save the image file with a specific name by following the function:
cv2.imwrite (“demopic.bmp”, img)
Circuit diagrams
Circuit-Diagram-Beaglebone-Black-Security-Camera |