Free Shipping on orders over US$49.99

AI Camera For Tracking Suspicious Activities


ashwiniTracking and detecting suspicious activities is one of the most demanding tasks for security personnel and systems. If a security system fails in a place like airport or bank, criminals can rob at gunpoint. Out of fear, the victims are usually unable to call the police in time for help.

But if a smart camera could detect any suspicious activity and automatically trigger an alarm to call the police, such criminal acts are likely to reduce significantly. So, let’s see how to build such an alarm.

Training the camera

Create a machine learning (ML) model having datasets of normal activities, such as walking, talking, reading, and sitting. Feed the datasets of suspicious activities like fighting, boxing, pointing a gun, or any other violent movement deemed suspicious, into the ML model.

Fig. 2: Author’s prototype
Fig. 2: Author’s prototype

Perform the above-mentioned activities in front of the smart camera so that various movements are captured. This will help train the ML model and deploy it on Raspberry Pi as a smart artificial intelligence (AI) camera.

material requiredThere are several flexible options, such as TensorFlow, Google Teachable, Edge Impulse, and Lobeo to create and train an ML model. Any of these can be chosen for the project. To demonstrate, Google Teachable is being used here.

Fig. 3: Feeding the normal activity datasets to create ML model
Fig. 3: Feeding the normal activity datasets to create ML model

In Google Teachable, select the PoseNet option for tracking Correctly various body movements and actions. Correctly label the actions performed earlier of walking, talking, eating, standing, etc. Feed these datasets into the ML model. Similarly, correctly label and feed the datasets of activities like pointing guns, firing guns, fighting, beating, etc.

Fig. 4: Feeding suspicious activity datasheet
Fig. 4: Feeding suspicious activity datasheet

After feeding the required datasets, click on Train Model. The option to export the ML model or upload it to the cloud will appear. Uploaded the ML model to the cloud to safely store it there and let users access and deploy it anywhere in the world.

On uploading to the cloud, you will receive a URL for using the ML model. The URL of the ML model created by the author.

Fig. 5: Getting the ML trained
Fig. 5: Getting the ML trained

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.

Fig. 6: JavaScript code
Fig. 6: JavaScript code

Coding

To deploy the ML model in Raspberry Pi coding is required. While 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. You can name the camera in HTML for the ML model.

Fig. 7: Code for setting path of sound to play
Fig. 7: Code for setting path of sound to play

Import the ML model that was previously uploaded to the cloud. Then check whether activities such as beating, gun firing, and gun possession are detected by the ML model during video processing.

Fig. 8: Code for play alert sound
Fig. 8: Code for play alert sound

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 nearby.

Fig. 9: Testing and output of camera
Fig. 9: Testing and output of camera

Testing

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. 10: Testing in .js online editor and compiler
Fig. 10: Testing in .js online editor and compiler

Sometimes Chrome on Raspberry Pi is unable to open or access the camera and it hangs. In such a case try installing the latest version of Chrome or switch to another browser like Firefox or use an online/offline .js compiler. If problem persists, you can use the the URL of trained ML model and directly see the output using the URL.

Fig. 11: Testing camera using URL of trained ML model
Fig. 11: Testing camera using URL of trained ML model

You can also use the Files option and upload if the browser is unable to access the camera to test the ML model you have created in Rpi.

Fig. 12: Testing ML model through manual file input
Fig. 12: Testing ML model through manual file input

Download Source Code


Ashwini Kumar Sinha is a technology enthusiast





Source link

We will be happy to hear your thoughts

Leave a reply

AmElectronics
Logo
Enable registration in settings - general
Compare items
  • Total (0)
Compare
0
Shopping cart