Getting an object detector/tracker up and running on Raspberry Pi 3 (Part I)

Flavia Ninsiima
Sep 3, 2018 · 6 min read

Recently we were tasked with finding a way to install a person detector at our lab — a tracker that would possibly count who enters and leaves the lab. This was meant to be a fun experiment of sorts with machine learning and IoT. You can see my partner-in-crime Benjamin Akera(2nd left) in the photo below, as well as the requester (extreme right).

Detecting persons present in an image. Picture courtesy of a dsa2018 conference attendee.

Materials:

  • raspberry pi 3 [Model B]
  • VGA to HDMI cable
  • monitor/desktop/laptop
  • keyboard and mouse
  • internet connection
  • micro SDcard at least 8gb
VGA to HDMI Cable(left)

The first step is to install an operating system on the raspberry Pi, now there are many options you could choose from and the most popular being Raspbian OS. In our case we chose to use Ubuntu MATE (mah-tay)

Picture courtesy of Snapcraft

Step 1: The first thing you have to do is to format your SDcard just to make sure you’re starting on a clean slate. Ensure to backup any files you may have on it. Ideally you can use a sdcard reader but we didn’t have one so we improvised by inserting the card into our phones and connecting to our laptop. Even if the disk drive name doesn’t appear in windows explorer under My Computer, Windows provides a great utility called Disk Management which enables you to format the sdcard. Simply right click on the partition you would like to format and choose Format.

Disk management option to format hidden partitions that can’t be viewed in ‘My Computer’

Step 2: Download Ubuntu Mate and flash it to your sdcard. For this test, we downloaded ubuntu-mate-16.04.2-desktop-armhf-raspberry-pi.img and used Etcher to flash to the sdcard. The flashing and validating process will take a while.

For initial access to the Pi, we will employ a VGA to HDMI cable. Also a monitor, keyboard and mouse come in handy!

Step 1. Insert the HDMI bit of the connector into the Pi and plug the VGA end into the monitor.

Step 2. Insert the keyboard and mouse to the Pi via USB. Pi’s have usb ports into which you can insert your peripherals.

Step 3. Insert your sdcard into the Pi and power up the Pi. One way to power up the Pi is to insert a USB cable in it and connect to your laptop. However sometimes, the USB ports may not provide sufficient power, especially if you notice a lighting icon on the monitor, so it’s best to manually connect the USB cable from the Pi to a plug used to charge normal smart phones. Let’s not forget the wired connection if you would like to set it up now

VOILA!!! You should be able to see the start up of Ubuntu MATE. After start up is done, in the terminal you can run $sudo raspi-config to access/enable different options.

Next, we need a way to ssh into our raspberry pi. We do this such that we can access the Pi desktop UI and or terminal from any device as long as both the Pi and our device share the same ethernet/wifi connection. After this process is complete, we won’t need the VGA to HDMI cable to connect the Pi to a monitor. But first, leave in the VGA to HDMI cable until we finish setting up ssh access.

Step 1. Choose whether to connect to the Pi through wifi connection or LAN and set it up. What does this mean? In the following steps when we set up VNC connections for ssh access, our Pi and our laptop/device will need to be connected to the same networks. Therefore if Pi is on a network/internet connection with an APN called “free_wifi”, then the laptop should also be connected to “free_wifi”.

Step 2. Download VNC Viewer for the operating system of your device (the device you will use to ssh into the Pi), for our case it was Windows.

Step 3. Download VNC Connect for the pi and $sudo dpkg -i path/to/vnc_connect to install it. To download VNC, we can use the default firefox browser that comes with Ubuntu MATE. HOWEVER, you have to setup/fix the timezone of the system or else firefox continuously returns errors and web pages will not load.

Step 4. Fire up VNC Connect on the Pi terminal(Ctrl+Alt+t) using $

VCN Server application pops up and should provide an ip address to the effect of something like 192.168.1.x.

Step 5. Fire up VNC viewer from your laptop and type in this ip address. Enter the username and password if you set up one using vncserver. If successful, you should now be able to access the desktop environment of your Pi from your device.

Next, we must ensure that whenever we boot up our Pi, vcnserver is running and enabled i.e.. “ubuntu launch vnc server on startup”.

Step 1: In Pi terminal run

#systemd
#initd

However, this is bound to give you errors stating that script init.d doesnt exist. So copy the contents from this file https://github.com/fninsiima/medium-files/blob/master/vncserver into . The easiest way to do it is to copy it to your clipboard, run in a terminal, paste it in, and type . Be sure to change the NAME, GEOMETRY, variable to whatever user you want the VNC server to run under. Make the script executable with then, run . To start the server without rebooting, run

Once this is up and running, you can reboot the Pi without the VGA to HDMI connector and wait a while to connect using viewer but at the end of it all, you should be successful.

Stay tuned for part II.

Important links for further reading

https://www.realvnc.com/en/connect/docs/unix-start-stop.html#unix-start-stop

AI Research Lab Kampala

The AI & Data Science research group at Makerere University specialises in the application of artificial intelligence and data science - including, for example, methods from machine learning, computer vision and predictive analytics - to problems in the developing world.

Flavia Ninsiima

Written by

AI Research Lab Kampala

The AI & Data Science research group at Makerere University specialises in the application of artificial intelligence and data science - including, for example, methods from machine learning, computer vision and predictive analytics - to problems in the developing world.

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade