James Jackson Random Musings

YOLO Object Detection on a Security Camera


The idea is to rapidly develop (in a few hours) a system that applies state-of-the-art object detection (YOLO) to images from a security camera. This has the benefit of significantly reducing false detections, and lays the groundwork for more intelligent handling of detection of people, vehicles etc.


Although this is a rapid prototype, there is a desire for an elegant, sustainable, design. The camera automatically drops images into Dropbox once it detects motion (from video). Several new Java microservices are built on a Digital Ocean droplet. The microservices communicate with each other via a local Redis message queue, and with Dropbox APIs. The overall flow is as follows:

  1. Camera detects motion and drops new image into a specific Dropbox folder.
  2. Longpoll microservice maintains a long poll connection with the Dropbox APIs, waits for a new image file notification, retrieves the image, and pushes a message into new_image_queue.
  3. Detect microservice waits for a new message in new_image_queue, pops the message, and passes the image to a local YOLO install for object detection. If the detected objects are not in the defined exclusions file, a message is pushed to notify_queue, and a JSON blob with detection info (filename, objects, confidences) is added to a Redis sorted set, events, and indexed by Unix timestamp.
  4. Notify microservice waits for a new message in notify_queue, pops the message, and uploads the image to a new folder via Dropbox APIs.


The system has been running without issue for several weeks. Detection of vehicles and people works remarkably well. Only 1 in 5 motion detections from the camera result in a real notification event, providing a substantial decrease in false positives.

Redis Events> zrange events 0 -1
  1) "{\"filename\":\"pa_2017-03-02_18-36-30_940.jpg\",\"objects\":[{\"truck\":47}]}"
  2) "{\"filename\":\"pa_2017-03-02_18-36-35_193.jpg\",\"objects\":[{\"truck\":27},{\"car\":63}]}"
  3) "{\"filename\":\"pa_2017-03-02_18-36-36_400.jpg\",\"objects\":[{\"car\":81}]}"
  4) "{\"filename\":\"pa_2017-03-02_19-17-35_391.jpg\",\"objects\":[{\"person\":57}]}"
  5) "{\"filename\":\"pa_2017-03-02_19-17-36_651.jpg\",\"objects\":[{\"person\":76}]}"
  6) "{\"filename\":\"pa_2017-03-02_19-23-07_420.jpg\",\"objects\":[{\"person\":30},{\"person\":44},{\"truck\":26},{\"car\":55}]}"
  7) "{\"filename\":\"pa_2017-03-02_19-23-17_440.jpg\",\"objects\":[{\"car\":58},{\"truck\":30}]}"

Vehicle Detection vehicle detection

Person Detection person detection

YOLO hasn’t seen too many deer ! deer detection

Night vision and moths can be challenging ! moth detection


The code for the Java microservices is available here.


How To Install and Configure Redis on Ubuntu 16.04

A Java library for the Dropbox Core API

A blazingly small and sane redis java client

comments powered by Disqus