Tracking and detecting suspicious activity is one of the most demanding tasks for many security personnel and systems. If a security system fails in places like airports and banks, then criminals will get an advantage to carry out theft at gunpoint. Out of fear, people won’t be able to call the police for help.
But if a smart camera can detect any suspicious activity and automatically trigger an alarm to call the police, then such criminal acts can be prevented.
So, let’s learn how to build such a device in this project.
Bill Of Materials
Teaching The Camera
First create an ML model having datasets of normal activities such as walking, talking, reading, sitting etc. Then feed the datasets of Suspicious Activity such as fighting, boxing, pointing guns or any other violent movement deemed suspicious into the ML model.
Also, perform such activities in front of the smart camera so that various movements are captured. This will be useful for training the ML model and deploying it on Raspberry Pi to make a smart AI camera.
To create and train an ML model, there are several flexible options such as TensorFlow, Google Teachable, Edge Impulse, Lobe etc. You can choose any and work on the above idea. Here, I am demonstrating with the help of Google Teachable.
In Google Teachable, select the PoseNet option for tracking the various body movements and actions. Earlier, we performed different actions like walking, talking, eating, standing etc. By correctly labelling them, feed these datasets into the ML model. Similarly, feed the datasets of activities like pointing guns, firing guns, fighting, beating etc.
Fig 1. Feeding datasets Fig 2. Feeding datasets for ML traning
After feeding the required datasets, click on ‘Train Model’. You will be given an option to export the ML model or upload it to the cloud. I uploaded the ML model to the cloud as it will be safely stored there, allowing users to access and deploy it anywhere in the world.
On uploading to the cloud, you will receive a URL for using the ML model.
Deploying on Camera
Next, deploy the ML model on the camera and connect a speaker so that the Raspberry Pi triggers an alarm when any suspicious activity gets detected.
Now, you need to deploy the ML model in Raspberry Pi for which coding is required.
Import the ML model that was previously uploaded to the cloud. Then check whether activities such as beating, gun firing, gun possession etc, are detected by the ML model during video processing. The model gives the likelihood of a particular activity to occur in the range of 0.00 to 1.00. So, by using an if condition, if the output is greater than 0.98 then it means a person is either pointing a gun or fighting. At this point, an alarm gets triggered to alert people in the neighboring area.
Fig 3.Code snippet for human activity tracking camera Fig 4.Code snippet for suspicious activity tracking
Fig 5.Testing codeFig 6. camera detecting movement and suspicious activityFig 7. camera detecting movement and suspicious activity
Download ML Model and Code