<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Bofu Chen on Medium]]></title>
        <description><![CDATA[Stories by Bofu Chen on Medium]]></description>
        <link>https://medium.com/@bafu?source=rss-4e02d18e8846------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*0NO5NoXLzWybMOVHCOUGjg.jpeg</url>
            <title>Stories by Bofu Chen on Medium</title>
            <link>https://medium.com/@bafu?source=rss-4e02d18e8846------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Mon, 30 Nov 2026 17:05:18 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@bafu/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[DIY Your AI Home Security Camera With Raspberry Pi And Open-source Software]]></title>
            <link>https://medium.com/berrynet/diy-your-ai-home-security-camera-with-raspberry-pi-and-open-source-software-10d4364df20f?source=rss-4e02d18e8846------2</link>
            <guid isPermaLink="false">https://medium.com/p/10d4364df20f</guid>
            <category><![CDATA[home-security]]></category>
            <category><![CDATA[raspberry-pi]]></category>
            <category><![CDATA[ai]]></category>
            <category><![CDATA[privacy]]></category>
            <dc:creator><![CDATA[Bofu Chen]]></dc:creator>
            <pubDate>Sat, 03 Aug 2019 15:23:37 GMT</pubDate>
            <atom:updated>2019-08-03T15:24:48.300Z</atom:updated>
            <content:encoded><![CDATA[<blockquote>This article is a step-by-step tutorial to setup an AI home security camera WITHOUT leaking videos of your love to the cloud.</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/960/1*gSDY24PLLOM0RgZUA0lCOQ.jpeg" /><figcaption>Figure: This is a step-by-step intro to setup a home security system without leaking video to the cloud.</figcaption></figure><p>So you want to enhance home security to protect the family you love, and decide to install a home surveillance system. After some Google searches however, you find many solutions which provide intelligent notification and video backup by cloud, sounds great right? <strong>But what about privacy, is security more important than privacy?</strong> After all, there’s no such thing as a free lunch.</p><p>In this tutorial, we will helping you to DIY a home Surveillance system step-by-step. The system will be running on is a $35 computer, the wonderful and awesomely powerful Raspberry Pi, with <strong>all the computations running locally</strong>, so you can protect your family without losing your privacy. Our system is based on <strong>BerryNet</strong>, an open source AI system, so everything is transparent.</p><h3>Before starting the tutorial</h3><p>You will need to prepare the following devices to complete the tutorial:</p><ul><li>An old mobile phone as camera input</li><li>A Raspberry Pi for local AI computation (*)</li><li>A laptop or desktop with Ubuntu installed to check the result</li><li>A gmail account to send out notifications</li></ul><p>(*) The BerryNet open-source software also support other devices as AI computer, if you do not have a raspberry Pi in hand, please check <a href="https://github.com/DT42/BerryNet/wiki">BerryNet Wiki</a> for other alternative hardware choices.</p><p>More details of the required software and hardware are listed below in the <strong>Precondition</strong> section. If you encounter any problem during the execution, please join <a href="https://t.me/berrynetdev">BerryNet Telegram</a> and the BerryNet team is there to support you.</p><h3>Scenario</h3><p>For the first step, we will help you setup a mobile as an IP camera, send the camera images to Raspberry Pi for AI analysis, and display the analysis results on the Raspberry Pi’s screen. You will have an overview how the entire system works.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/960/1*YP7ZYpA7w8taA4xP0FPnjw.jpeg" /><figcaption>Figure: Development stage, to receive notifications by laptop.</figcaption></figure><p>Then we will help you setup your Gmail account and send event notifications through it. Your Gmail account will be like an assistant sending event notifications to another indicated email address.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/960/1*HHDNsIxwDEPhk3ZT8BJlgw.jpeg" /><figcaption>Figure: Real scenario, after the system configuration is done, one can receive notifications in Email.</figcaption></figure><p>Our sample scenario of this tutorial is below:</p><ul><li>Raspberry Pi 4 with BerryNet, the analysis center</li><li>Mobile as IP camera, the image source provider</li><li>Gmail account, the event notification sender</li><li>Another email account, the event notification receiver</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/960/1*31KlRFNEN5A6F26PbRbKeQ.jpeg" /><figcaption>Figure: Sample scenario setup.</figcaption></figure><h3>Precondition</h3><p>Here is the list of hardware and software you will need:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/706/1*-7zAKN-UwCa1yajSGzTQgg.png" /><figcaption>Table: Required software and hardware. [1] https://www.balena.io/etcher/</figcaption></figure><h3>Step-By-Step Tutorial</h3><h4><strong>Step 1: Turn your mobile to be an IP camera</strong></h4><p><a href="https://play.google.com/store/apps/details?id=com.spynet.camon&amp;hl=en">CamOn Live Streaming</a> is an easy-to-use app to turn your Android phone into an IP camera.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*YIBzY9Js1tLg0UbK4DC7NQ.png" /><figcaption>Figure: Screenshot of my mobile running CamOn Live Streaming</figcaption></figure><p>In the figure above, video streaming information is displayed on the screen. To get the RTSP URL for H.264 streaming, you can drop the menu down, to see the streaming information and the stop button. The RTSP URL is your source of input video frames in the BerryNet camera client in the latter sections.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*93MI5Y7LpPmpGKIfWvUzSw.png" /><figcaption>Figure: Get RTSP URL of camera video stream from the drop down menu.</figcaption></figure><p>You can choose focus mode in camera settings. Sometimes continuous auto-focus might affect the input quality and subsequently the accuracy of the AI system. Personally I prefer to choose on-touch auto-focus or disable auto-focus completely.</p><h4><strong>Step 2: Download And Install BerryNet System Image to SD Card</strong></h4><p>Download the <a href="https://berrynet.s3.amazonaws.com/images/2019-07-15-raspbian-buster-berrynet.zip">latest image</a> (if your browser helps decompress Zip file automatically, disable it before download). To check the integrity of the downloaded image, you can check the md5sum of the image and compare it with the <a href="https://berrynet.s3.amazonaws.com/images/2019-07-15-raspbian-buster-berrynet.md5sum">checksum file</a>.</p><p>Note: If your host OS is Windows, you can write BerryNet image to SD card by <a href="https://www.balena.io/etcher/">balenaEtcher</a>.</p><p>Assuming that the image is saved to <em>/home/DT42/Downloads/ </em>directory.</p><pre>notebook $ cd /home/DT42/Downloads<br>notebook $ md5sum 2019-07-15-raspbian-buster-berrynet.zip<br>8bda8053a69995814a0ca6fa60b1d49e  2019-07-31-raspbian-buster-berrynet.zip</pre><p>Write image to SD card. Assuming that the inserted SD card is represented as the device node<em> /dev/sdb</em> on system. You can check the device node name of the SD card by GParted Partition Editor. If you see other similar device notes like <em>/dev/sdb1</em> or <em>/dev/sdb2</em>, you can ignore them without causing any problem.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/775/1*2BcU5rHmC4NeFRpqdqEuow.png" /><figcaption>Figure: Get a list of storage device nodes in GParted.</figcaption></figure><p>Run the command below to write BerryNet image to SD card:</p><pre>notebook $ unzip -p 2019-07-15-raspbian-buster-berrynet.zip | sudo dd of=/dev/sdb bs=4M conv=fsync status=progress</pre><p>To get more information of installation, you can refer to the <a href="https://github.com/DT42/BerryNet/wiki/Installation">installation Wiki page</a>.</p><h4>Step 3: Boot And Disable Auto-Launched AI System</h4><p>After booting your Raspberry Pi, BerryNet is ready and will already have an object detection application will be running on it. Here you will learn how to create your own AI application and launch it automatically after booting in the latter sections. Now, please stop the default application manually:</p><pre>rpi $ sudo supervisorctl stop all</pre><h4>Step 4: Update The Latest BerryNet.</h4><p>Update BerryNet to the latest version:</p><pre>rpi $ sudo apt update<br>rpi $ sudo apt install -y berrynet</pre><h4>Step 5: Run Your AI Application And Verify Functionality Manually</h4><p>You are now ready to launch an object detection application by running a detection service, a dashboard client, and a camera client manually.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/960/1*YP7ZYpA7w8taA4xP0FPnjw.jpeg" /><figcaption>Figure: Re-cap the development scenario.</figcaption></figure><p>Before running the steps below, make sure that your mobile and Raspberry Pi connected to the same WiFi access point.</p><p>Firstly, start the object detection service:</p><pre>rpi $ bn_tflite -s detector -p mobilenet-ssd-coco-tflite-2.0.0 --num_threads 4 --draw --debug</pre><pre>[D 190724 06:28:19 tflite_service:183] model filepath: /usr/share/dlmodels/mobilenet-ssd-coco-tflite-2.0.0/model.tflite<br>[D 190724 06:28:19 tflite_service:184] label filepath: /usr/share/dlmodels/mobilenet-ssd-coco-tflite-2.0.0/labels.txt<br>INFO: Initialized TensorFlow Lite runtime.<br>[D 190724 06:28:19 __init__:11] Connected with result code 0<br>[D 190724 06:28:19 __init__:13] Subscribe topic berrynet/data/rgbimage</pre><p>You can see that object detection service is ready to receive input data (from the <em>berrynet/data/rgbimage</em> MQTT topic)</p><p>Secondly, start the dashboard client, and the detection result will be shown on it after camera client is started by the next step (before that, dashboard content will be empty):</p><pre>rpi $ bn_dashboard --topic berrynet/engine/tflitedetector/result --no-decoration --no-full-screen --debug</pre><pre>[D 190724 06:37:54 __init__:11] Connected with result code 0<br>[D 190724 06:37:54 __init__:13] Subscribe topic berrynet/engine/tflitedetector/result</pre><p>If you are logging in via SSH remotely, you can launch the dashboard window by adding <em>DISPLAY=:0</em> before <em>bn_dashboard</em>. To stop the dashboard client, you can click the dashboard window, and pressing “q”.</p><p>Thirdly, start the camera client, and assign an image filepath as the input source:</p><pre>rpi $ wget -O /tmp/person.jpg https://raw.githubusercontent.com/pjreddie/darknet/master/data/person.jpg</pre><pre>rpi $ bn_camera --mode file --filepath /tmp/person.jpg --debug<br>[D 190724 06:46:18 camera:165] payload: 3.301 ms<br>[D 190724 06:46:18 camera:166] payload size: 161232<br>[D 190724 06:46:18 __init__:50] Send message to topic berrynet/data/rgbimage<br>[D 190724 06:46:18 camera:171] mqtt.publish: 8.06 ms<br>[D 190724 06:46:18 camera:172] publish at 2019-07-24T06:46:18.65415</pre><p>You should see the detection result shown on the dashboard, meaning that the object detection service and data communication mechanism are ready.</p><p>Finally, stop the camera client, and restart it with RTSP URL of the camera video stream as its input source:</p><pre>rpi $ bn_camera --stream-src rtsp://10.0.0.108:8080/video/h264 --fps 1 --debug</pre><pre>[W 190724 06:34:52 camera:113] Camera FPS is 180000.0 (&gt;30 or &lt;1). Set it to 30.<br>[D 190724 06:34:52 camera:127] ===== VideoCapture Information =====<br>[D 190724 06:34:52 camera:128] Stream Source: rtsp://10.0.0.108:8080/video/h264<br>[D 190724 06:34:52 camera:129] Camera FPS: 30<br>[D 190724 06:34:52 camera:130] Output FPS: 5.0<br>[D 190724 06:34:52 camera:131] Interval: 6<br>[D 190724 06:34:52 camera:133] ====================================<br>[D 190724 06:34:52 camera:142] Drop frames: 5<br>[D 190724 06:34:52 __init__:50] Send message to topic berrynet/data/rgbimage</pre><p>The detection results will be updated on dashboard constantly. You can adjust the fps parameter of camera client, and put <a href="https://play.google.com/store/apps/details?id=de.andreas1724.bigdigitalclock&amp;hl=en">Big Digital Clock</a> in front of the camera, so that you can see if the system is capable to process the input frames by the given fps parameter. We suggest to set 1 to the fps parameter to prevent email flooding.</p><p>Note: If you are interested in the benchmark of running MobileNet SSD on Raspberry Pi 3 and 4 with TFLite, I recommend <a href="https://blog.hackster.io/benchmarking-tensorflow-lite-on-the-new-raspberry-pi-4-model-b-3fd859d05b98">this Allan’s article</a>.</p><h4>Step 6: Send Detection Result by Gmail</h4><p>If you want to receive a notification when an event happens, the Gmail client helps you to send notification emails to an indicated email address.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/960/1*HHDNsIxwDEPhk3ZT8BJlgw.jpeg" /><figcaption>Figure: Recap the real scenario.</figcaption></figure><p>Firstly, stop the dashboard client by clicking the dashboard window, and pressing <em>“q”</em>.</p><p>Secondly, configure your Gmail account to allow 3rd-party app login. Go to <a href="https://myaccount.google.com/security">Google Account</a>, disable 2-step verification, and enable less secure app access:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/960/1*Aj8kRRxQQFQfA25UWwAC-g.jpeg" /><figcaption>Figure: Google account setup for Gmail client access.</figcaption></figure><p>Finally, start the Gmail client:</p><pre>rpi $ bn_gmail --sender-address foo@gmail.com --sender-password &lt;gmail-password&gt; --receiver-address bar@dt42.io --target-label person --topic berrynet/engine/tflitedetector/result --debug</pre><pre>[D 190722 15:36:27 __init__:11] Connected with result code 0<br>[D 190722 15:36:27 __init__:13] Subscribe topic berrynet/engine/ovdetector/result<br>[D 190722 15:36:50 __init__:20] Receive message from topic berrynet/engine/ovdetector/result<br>[D 190722 15:36:50 gmail:120] inference text result: {&#39;timestamp&#39;: &#39;2019-07-22T15:36:49.674736&#39;, &#39;annotations&#39;: [{&#39;left&#39;: 63, &#39;confidence&#39;: 0.9310929179191589, &#39;bottom&#39;: 347, &#39;right&#39;: 203, &#39;label&#39;: &#39;dog&#39;, &#39;top&#39;: 261}, {&#39;left&#39;: 405, &#39;confidence&#39;: 0.7530375123023987, &#39;bottom&#39;: 341, &#39;right&#39;: 606, &#39;label&#39;: &#39;horse&#39;, &#39;top&#39;: 135}, {&#39;left&#39;: 182, &#39;confidence&#39;: 0.9989088773727417, &#39;bottom&#39;: 369, &#39;right&#39;: 271, &#39;label&#39;: &#39;person&#39;, &#39;top&#39;: 103}, {&#39;left&#39;: 404, &#39;confidence&#39;: 0.4551317095756531, &#39;bottom&#39;: 337, &#39;right&#39;: 600, &#39;label&#39;: &#39;sheep&#39;, &#39;top&#39;: 135}]}<br>[D 190722 15:36:50 gmail:109] Result labels: [&#39;dog&#39;, &#39;horse&#39;, &#39;person&#39;, &#39;sheep&#39;]<br>[D 190722 15:36:50 gmail:126] Find target label person: True<br>[D 190722 15:36:50 gmail:72] Sender: foo@gmail.com<br>[D 190722 15:36:50 gmail:73] Receiver: bar@dt42.io<br>[D 190722 15:36:50 gmail:74] Subject: BerryNet mail client notification<br>[D 190722 15:36:50 gmail:80] Attachment: /tmp/2019-07-22T15:36:50.632503.jpg<br>[D 190722 15:36:50 gmail:80] Attachment: /tmp/2019-07-22T15:36:50.632503.json</pre><p>The receiver should receive a notification email, and the attachments are an image and text of the detection results:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/679/1*kesH2WwIs8hF097OgPLw6w.png" /><figcaption>Figure: Receive notifications consisting of a snapshot and text details in Gmail.</figcaption></figure><p>If you change the target label to other object such as dog, the notification will be sent when a dog is detected.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/640/1*yXitz_SjC6qqqeDjy_QeTQ.jpeg" /><figcaption>Figure: Email attachment when the label is changed from person to dog.</figcaption></figure><p>If you see the messages below instead of receiving the notification email, please check the password entered in the command line:</p><pre>[W 190803 15:31:54 gmail:148] (535, b&#39;5.7.8 Username and Password not accepted. Learn more at\n5.7.8 <a href="https://support.google.com/mail/?p=BadCredentials">https://support.google.com/mail/?p=BadCredentials</a>n140sm80107108fpd.132 - gmtp&#39;)</pre><h4>Step 7: Make System to Run Automatically</h4><p>You might remember that you disabled default object detection application in the beginning of this tutorial. The default application is described in the configuration file</p><pre>/etc/supervisor/conf.d/berrynet-tflite.conf</pre><p>To return your application to its default, you can modify the configuration by</p><ul><li>Updating the fps parameter of the camera client (<em>bn_camera</em>)</li><li>Adding a section for the Gmail client (<em>bn_gmail</em>)</li></ul><p>The configuration content will look like (you can modify it by your needs):</p><pre>rpi $ cat /etc/supervisor/conf.d/berrynet-tflite.conf</pre><pre>[program:tflite-service]<br>command=bn_tflite --service detector --service_name tflitedetector --model_package mobilenet-ssd-coco-tflite-2.0.0 --num_threads 4 --draw --debug<br>stdout_logfile=/var/log/berrynet/tflite-service-stdout.log<br>stdout_logfile_maxbytes=1048576<br>stderr_logfile=/var/log/berrynet/tflite-service-stderr.log<br>stderr_logfile_maxbytes=1048576<br>priority=10</pre><pre>[program:camera]<br>command=bn_camera --fps 1<br>stdout_logfile=/var/log/berrynet/camera-stdout.log<br>stdout_logfile_maxbytes=1048576<br>stderr_logfile=/var/log/berrynet/camera-stderr.log<br>stderr_logfile_maxbytes=1048576<br>priority=30</pre><pre>[program:gmail]<br>command=bn_gmail --sender-address foo@gmail.com --sender-password &lt;gmail-password&gt; --receiver-address bar@dt42.io --target-label person --topic berrynet/engine/tflitedetector/result<br>stdout_logfile=/var/log/berrynet/gmail-stdout.log<br>stdout_logfile_maxbytes=1048576<br>stderr_logfile=/var/log/berrynet/gmail-stderr.log<br>stderr_logfile_maxbytes=1048576<br>priority=30</pre><p>Reboot the Raspberry Pi, and start protecting your family without sacrificing your privacy!</p><h3>Summary</h3><p>We believe that AIoT (edge AI computation and IoT) is a powerful tool to protect our security and privacy at the same time. And we’re hoping that the flexible architecture can help you build more interesting AIoT applications in education, research, robotics, health care, and more!</p><p>If you have any questions or suggestions, please visit the <a href="https://t.me/berrynetdev">BerryNet Telegram group</a>. We look forward to seeing you!</p><h3>Special Thanks</h3><p>In the end of the tutorial, I would like to thank the BerryNet QA team, Sherry, the lady in the picture who performed tests and provided suggestions to this tutorial, and Mei-mei, the dog who played the detected object.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*4mifK9pgpGIZZBOpueIdfw.jpeg" /><figcaption>Figure: BerryNet QA team</figcaption></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=10d4364df20f" width="1" height="1" alt=""><hr><p><a href="https://medium.com/berrynet/diy-your-ai-home-security-camera-with-raspberry-pi-and-open-source-software-10d4364df20f">DIY Your AI Home Security Camera With Raspberry Pi And Open-source Software</a> was originally published in <a href="https://medium.com/berrynet">BerryNet</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>