Quantcast
Channel: CodeSection,代码区,网络安全 - CodeSec
Viewing all articles
Browse latest Browse all 12749

Build a DIY security camera with neural compute stick (part 1)

$
0
0

Build a DIY security camera with neural compute stick (part 1)

In 1933, achicken keeperand amateurphotographer decided to find the culprit who was stealing his eggs. Since its inception, security cameras are everywhere nowadays, most of the claimed "smart ones" work by streaming videos back to a monitor or a server so as someone or some software can analyzevideo frames and hopefully find some usefulinformation from them. They consume a large amount of network bandwidth and powerto stream videos even though ten image frames are all we need toknow who was stealing the eggs. They are also facing a dilemma of out of service when thenetwork is unstable, images cannot be analyzedand the "smart" becomes "dumb".

Edge computing is a network modelwhich enables data processingoccurs at the edge of the network where the camera is located, eliminating the need to send videos to a central server for processing. Processing image data on the edgereduces system latency, the powerconsumedby videotransmitting and costof bandwidth, plus improved privacy since less information will be transmitted which are suspectable to be hacked. Simple concept, but why it was not popular yet? Simple answer, the hardware, and software were not ready yet. Image processing has long been known for its notoriously crave for processing power and advanced algorithm to extract useful information from it. With the recent advance in deep learning algorithms followed by emerging of friendly priced inferencing hardware opens the door for more advanced edge computing right on the camera.


Build a DIY security camera with neural compute stick (part 1)

How about making such a cool camera yourself? The finalgoal for this tutorial is to show you how to build such a security camera that process the footage locally with advanced object detection algorithm andfilters the important images out of hours of video frames all in real-time. To build,you need the following essential tools and hardware.

Raspberry Pi3 Model B , single board computer powered by the 5V power supply. Movidius neural compute stick from Intel. NCSDK2 : This Intel Movidius Neural Compute software developer kit v2 from GitHub, free to download. A USB webcam, any brand should work while one with a wide anglelens stands out since we are building a security camera.

Optionalto make the camera run on battery.

12V lithiumbattery module and a DC-DC module to step down the voltage to 5V. Or battery bankwith a USB port provides 5V/2A.

Optional to build an additionalturret to turn the camera and cover an even more extensiverange of view.

Hobby Servo motor Arduino Pro Micro or other Arduino comparableboard Some soldering wire

Optional materials to build housing for the project, cardboard, solid wood board, etc.

In this post, you will learn how to install the necessary software on the Raspberry Pi for Movidius NCS and do object detection on webcam frames in real-time.

Installing NCSDK2 on Raspberry Pi

The basic installation and configuration for Raspberry Pi are alreadylisted on Movidius document,note that Raspberry Pi 3 must run the latest Raspbian Stretch for NCSDK2, and an SD card-sized 16G + is recommended.

After installing NCSDK2, install the NCAPI v2's ncappzoo which contains examples for the Movidius Neural Compute Stick.

git clone -b ncsdk2 https://github.com/movidius/ncappzoo.git

Then cd into ncappzoo/apps , remove or rename the folder video_objects to something else, clone my video_objects repo there.

git clone https://github.com/Tony607/video_objects Install OpenCV3 the easy way

It is necessary to install opencv3 to run this demo. While the officialstandard approach is to build from the source which I have triedseveral times without luck, that leads to my alternative solution to install the pre-built OpenCV3 library on raspberry Pi within a matter of minutes compares to hours of building from source. Just run the followingfour lines in a terminal.

sudo pip3 install opencv-python==3.3.0.10 sudo apt-get update sudo apt-get install libqtgui4 sudo apt-get install python-opencv

You just installed opencv -python package version 3.3.10 from python wheels for the Raspberry Pi ! The following two apt-get installs makes sure there are no missing dependencies.

To check the installation in python3, you can run like this. Expect to see the OpenCV3 version string "3.3.0".

pi@raspberrypi:~/workspace/ncappzoo/apps/video_objects $ python3 Python 3.5.3 (default, Jan 19 2017, 14:11:04) [GCC 6.3.0 20170124] on linux Type "help", "copyright", "credits" or "license" for more information. >>> import cv2 >>> cv2.__version__ '3.3.0' >>>

So no more complain about "My Code's compiling".


Build a DIY security camera with neural compute stick (part 1)
Run the object detection demo

With your NCS and a webcam plugged in your Raspberry Pi's USB ports,connect an HDMI monitor or use VNC toaccess your Pi's desktop. Let's fire up the demo. In a terminal, cd into video_objects directory you just cloned from my GitHub repo then run.

make run_cam

The first time you run this, the make script will download the SSD mobileNet deep learning model definition file and weights, so expect some delay. After that, a new window pops up with real-time camera feed plus the overlay of bounding boxesfor objects detected. The software will only save the critical image frames when the number of people recognized changes between two frames into folder images . Moreon this in the next post.


Build a DIY security camera with neural compute stick (part 1)
Conclusion and further reading

Being the first post of the security camera project,it shows what it takes to build a bare minimal "smarter" camera that detects people in real time and saves only useful keyframes. The installing of NCSDK2 on Raspberry Pi illustrated in the previous section is the toughest and most time-consuming part of this project, hope my few tips help you expedite your endeavor. In the next post, I will explain the code you just ran and show you how to add an Arduino turret to turn the camera which follows people around as shown in this video I uploaded.

One final tip, if you plan torun NCS with NCSDK2 on an Ubuntu 16.04 PC, my sug

Viewing all articles
Browse latest Browse all 12749

Trending Articles