Real-time Object Detection

Real-time Object Detection and Object Tracking

Live Object Detection and Object Tracking can be optionally turned on and off at any time. These features work with the following video modes: yuv420, h264, mjpeg (video), jpeg (continuous stills or snapshots), webrtc.

The following example is reasonably efficient for face detection on a RaspberryPi 1 with a ~15fps video at 320×240 resolution, while the RaspberryPi 2 can easily do 640×480 at 30fps:

raspberrypi ~ $ uv4l --driver raspicam --auto-video_nr --object-detection --min-object-size 80 80 --main-classifier /usr/share/uv4l/raspicam/lbpcascade_frontalface.xml --object-detection-mode accurate_detection --width 320 --height 240 --framerate 15 --encoding h264

As you can see, you can specify the path to the preferred cascade classifier that the driver shall be using for object detection.

As another example, face tracking can be enabled in a similar way as detection, with the exception that you should also specify a secondary classifier specifically suited for the tracking algorithm:

raspberrypi ~ $ uv4l --driver raspicam --auto-video_nr --object-detection --min-object-size 80 80 --main-classifier /usr/share/uv4l/raspicam/lbpcascade_frontalface.xml --secondary-classifier /usr/share/uv4l/raspicam/lbpcascade_frontalface.xml --object-detection-mode accurate_tracking --width 320 --height 240 --framerate 15 --encoding h264

Whenever objects are detected on the image, they will be surrounded by white rectangles. Other classifiers are available from the OpenCV framework.

To turn off object detection/tracking on-the-fly, type:

raspberrypi ~ $ v4l2-ctl --set-ctrl=object_face_detection=0

To turn it on again:

raspberrypi ~ $ v4l2-ctl --set-ctrl=object_face_detection=1

NOTE: if you want to turn on object detection while the camera is in use by another application AND object detection was turned off when that application opened the Camera, you might need to close that application first.