The first Computer Vision project could be challenging but HuskyLens simplifies all the complicated parts. In this project I will use HuskyLens to autodetect guns to trigger a loud siren.
What is HuskyLens? it is a camera that can be connected to Arduino and Raspberry Pi but it is not just a camera since it includes LCD monitor and computer vision functions with learning abilities. By default HuskyLens is able to recognize colors, objects, faces, tags and lines. Arduino communication is performed with 2 cables (UART / I2C) plus power. Then with a few code lines, you are ready to react to different scenarios based on camera recognition. Example in this case: if a gun is detected, close a Relay and trigger a Loud Alarm.
Parts used
1 x Husky Lens
1 x DfRduino (it is Arduino Uno v3.0 ATmega328p with robust female headers)
1 x Red Switch
1 x Relay module
1 x microSD card (not all microSD cards are compatible)
1 x Siren horn
Jumper cables male-female and female-female
Custom 3d printed case (you can make your own with wood or a generic enclosure)
Connections are easy.
Husky Lens red cable → Arduino 5V
Husky Lens Black cable → Arduino Ground
Husky Lens Green cable → pin D10
Husky Lens Blue cable → pin D11.
(You will need male to female jumper cables)
Relay VCC → Arduino VIN
Relay GND → Arduino Ground
Relay IN1 → Arduino D2
Led Switch Green Cable → Arduino D7
Led Switch Red cable → Arduino 5v
Led Switch Black cable → Arduino Ground.
Siren Power + → Relay Com.
Siren Power - → Power Ground
Power + → Relay NO
So the Relay is in the middle of the Power + and the Siren will sound only when Arduino tells the Relay to close the circuit.
Huskylens Firmware Update
Certain optional features of this project like custom names for tracked objects and saving screenshots to microSD card won’t work if you don't upgrade HuskyLens cam firmware. You can find complete firmware update instructions at https://wiki.dfrobot.com/HUSKYLENS_V1.0_SKU_SEN0305_SEN0336#target_5
For Windows users, you will need to download 3 files: a driver, the utility and the firmware.
Training HuskyLens
You can train the model before even connecting all the project parts since you will only need Husky Lens.
Connect a USB Power Bank or Power Supply to the microUSB of the Husky Lens. Screen will turn on. Then you will be able to navigate using the wheel, which also has a push button. On the other side there is the learning button.
We will use Object Tracking feature. Just go there, enter settings, select "Learn Enable", then short press the function button, and dial it to the right to turn the "Learn Enable" ON, that is, the square icon on the progress bar is turned to the right. Turn on also "Auto Save" Select “Save & Return”
Point Huskylens to a generic gun, adjusting the distance and until the object is included in the yellow frame of the center of the screen. Then long press "learning button" to learn the gun shape from various angles and distances. When the recognition result meets the requirements, you can turn off "Learn Enable".
If you want to save images, place a first brand microSD card like Sandisk or Kingston with Fat32 format into the slot.
Source code
Download this .ino code and upload to the Arduino Uno.
https://github.com/ronibandini/GunAway
Case
Download these parts and 3d print using PLA. No support required.
https://github.com/ronibandini/GunAway
Using Gun Away
Press the red led button to arm the system. Now, whenever a gun is placed in front of the camera the siren will start. You can configure siren delay inside code settings.
Adjusting Threesold
HuskyLens includes threesold setting inside Object Tracking settings, so you can teach with one generic gun and recognize other similar guns as well. You may also need to configure False Positive threesold and frame size and ratio.
Huskylens settings that worked for me:
Frame ratio 1.50
Frame size 83
Threesold 0.8
False positive 0.350
True positive 0.7
Browse screenshots
Whenever a gun is detected a bmp picture will be also saved into microSD card. To view Gun Away screenshots, just remove the microSD from HuskyLens and place into your computer.
Saving the model
You can save the trained model from HuskyLens into a .bin file and then load it later. Just use that option from the Settings submenu.
Where to go from here?
What about replacing Arduino Uno by Arduino MKR WiFi or ESP32 so you can send Telegram messages to a group?