Tuesday, April 23, 2024

Suspicious Activity Tracking AI Camera

ashwiniTracking 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

- Advertisement -

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. 

- Advertisement -

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.  

At the time of uploading the ML model, you would have received an example code snippet. Copy and paste it into your JavaScript (JS) code. JS coding and testing can be done with the help of any code editor, offline or online. Here you can also name the camera in HTML for the ML model.

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 3.Code snippet for human activity tracking camera
Fig 4.Code snippet for suspicious activity tracking


Save the JavaScript code as .html and open it in any browser with JavaScript enabled. Click on the start button and perform the suspicious activity in front of the camera. The ML model will try to recognise it and if found unusual, will issue an alert. You can also add functions for automatically calling or messaging the police.    

Fig 5.Testing code
Fig 6. camera detecting movement and suspicious activity
Fig 6. camera detecting movement and suspicious activity
Fig 7. camera detecting movement and suspicious activity
Fig 7. camera detecting movement and suspicious activity

Download ML Model  and Code

Ashwini Sinha
Ashwini Sinha
A tech journalist at EFY, with hands-on expertise in electronics DIY. He has an extraordinary passion for AI, IoT, and electronics. Holder of two design records and two times winner of US-China Makers Award.



Unique DIY Projects

Electronics News

Truly Innovative Tech

MOst Popular Videos

Electronics Components