Reader small image

You're reading from  Raspberry Pi 3 Projects for Java Programmers

Product typeBook
Published inMay 2017
Reading LevelIntermediate
PublisherPackt
ISBN-139781786462121
Edition1st Edition
Languages
Right arrow
Authors (3):
John Sirach
John Sirach
author image
John Sirach

John Sirach works as a Product Owner at Greenhouse Innovation. He has more than 10 years of experience with Internet-related disciplines from connectivity to hosting and Internet Of Things. Currently, he is involved in the open source "PiDome Home Automation platform" project as a passionate Java and JavaFX software developer and project maintainer. In the past 10 years, he has gained experience with large-scale web applications committed to online services with the most experience gained in frontend web development and application middleware.
Read more about John Sirach

Pradeeka Seneviratne
Pradeeka Seneviratne
author image
Pradeeka Seneviratne

Pradeeka Seneviratne is a software engineer with over 10 years' experience in computer programming and systems design. He is an expert in the development of Arduino- and Raspberry Pi-based embedded systems. Pradeeka is currently a full-time embedded software engineer who works with embedded systems and highly scalable technologies. Previously, he worked as a software engineer for several IT infrastructure and technology servicing companies. He collaborated with the Outernet project as a volunteer hardware and software tester for Lighthouse- and Raspberry Pi-based DIY Outernet receivers based on Ku band satellite frequencies. He is also the author of five books: Internet of Things with Arduino Blueprints [Packt Publishing] IoT: Building Arduino-Based Projects [Packt Publishing] Building Arduino PLCs [Apress] Raspberry Pi 3 Projects for Java Programmers [Packt Publishing] Beginning BBC micro:bit [Apress]
Read more about Pradeeka Seneviratne

View More author details
Right arrow

Security Camera with Face Recognition

In Chapter 3, A Social and Personal Digital Photo Frame, you learned how to build a multimedia application, which is a digital photo frame based on the Raspberry Pi. Now you're going to take a major step forward, by building a real-time video processing application, which is a security camera with face recognition. Face recognition is a revolutionary technology and it can be used in a wide range of applications such as:

  • People tagging in photos
  • Gaming
  • Price comparison
  • Making mental notes
  • Identifying TV shows
  • Augmented reality
  • Image searching
  • Solving sudoku puzzles
  • Security

Besides providing security through camera-based applications at both day and night, by displaying videos on a screen or recording video using a hard disk, face detection can be used to identify human faces among moving objects (people, animals, vehicles, and so on) within the field of view of the camera...

Raspberry Pi camera module

The Raspberry Pi camera module (Figure 7-1) helps you to make still photographs and high definition videos with all models of Raspberry Pi. The latest version of the camera module is V2.1 at the time of writing this book, but all previous versions should work with this project. The camera module offers the following features: Sony IMX219 8-megapixel sensor:

  • Supports 1080p30, 720p60, and VGA90 video modes
  • Supports still capture
Figure 7-1: Raspberry Pi camera module V2.1. Image credits: SparkFun electronics. https://www.flickr.com/photos/sparkfun/9367415640

Connecting the camera module to the Raspberry Pi

All Raspberry Pi models offer a CSI port to attach the camera module through a 15 cm ribbon cable. Figure 7-2 shows a camera module...

OpenCV

The Raspberry Pi camera module can be accessed through the MMAL, V4L APIs, and some third-party libraries, including the Picamera Python library. When you need to access the camera module with Java, a well-written, feature-rich library is available, which is OpenCV.

OpenCV is currently available for Windows, Linux/Mac, Android, and iOS as pre-built libraries. However, you can build the OpenCV library for your preferred development environment using the source code. For Raspberry Pi, we will be building the OpenCV library to work with Java in a few easy steps.

Downloading and installing OpenCV on Windows

In order to write Java applications with OpenCV, first you have to download and install Open CV on your computer. The following steps explain how to do this...

Working with video

as the key source for security purposes, rather than the still images. The video quality extends to full HD, which is 1080p, at a frame rate of 30.

It's time to work with video capture, which can be used as the key source for security purposes, rather than the still images. The video quality extends to full HD, which is 1080p, at a frame rate of 30. Listing 7-2 shows a Java program that can be used to capture video using the Raspberry Pi camera module and save a snapshot to the SD card. Replace Listing 7-1 with this:

Listing 7-2: SecurityCamera.java

package com.packt.B05688.chapter7; 

import org.opencv.core.Core;
import org.opencv.core.Mat;
import org.opencv.imgcodecs.Imgcodecs;
import org.opencv.videoio.VideoCapture;

public class SecurityCamera {

static {
System.loadLibrary(Core.NATIVE_LIBRARY_NAME);
}

public static void main(String[] args) {
Core.setErrorVerbosity(false);
VideoCapture...

Summary

In this chapter, you learned how to use the camera module with a Raspberry Pi to capture video as a series of frames, and process them to detect human faces using a cascade classifier, which is haarcascade_frontalface_alt.xml. You can improve this application by displaying the detected person's name, along with the highlighting rectangle, sending an email or SMS alert, or implementing a web stream to access the video through the network and display the video on a web page.

lock icon
The rest of the chapter is locked
You have been reading a chapter from
Raspberry Pi 3 Projects for Java Programmers
Published in: May 2017Publisher: PacktISBN-13: 9781786462121
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
undefined
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $15.99/month. Cancel anytime

Authors (3)

author image
John Sirach

John Sirach works as a Product Owner at Greenhouse Innovation. He has more than 10 years of experience with Internet-related disciplines from connectivity to hosting and Internet Of Things. Currently, he is involved in the open source "PiDome Home Automation platform" project as a passionate Java and JavaFX software developer and project maintainer. In the past 10 years, he has gained experience with large-scale web applications committed to online services with the most experience gained in frontend web development and application middleware.
Read more about John Sirach

author image
Pradeeka Seneviratne

Pradeeka Seneviratne is a software engineer with over 10 years' experience in computer programming and systems design. He is an expert in the development of Arduino- and Raspberry Pi-based embedded systems. Pradeeka is currently a full-time embedded software engineer who works with embedded systems and highly scalable technologies. Previously, he worked as a software engineer for several IT infrastructure and technology servicing companies. He collaborated with the Outernet project as a volunteer hardware and software tester for Lighthouse- and Raspberry Pi-based DIY Outernet receivers based on Ku band satellite frequencies. He is also the author of five books: Internet of Things with Arduino Blueprints [Packt Publishing] IoT: Building Arduino-Based Projects [Packt Publishing] Building Arduino PLCs [Apress] Raspberry Pi 3 Projects for Java Programmers [Packt Publishing] Beginning BBC micro:bit [Apress]
Read more about Pradeeka Seneviratne