Prerequisites: Python OpenCV
Gun Detection using Object Detection is a helpful tool to have in your repository. It forms the backbone of many fantastic industrial applications. OpenCV(Open Source Computer Vision Library) is a highly optimized library with focus on Real-Time Applications.
1) Creation of Haarcascade file of Guns: Refer to Creation of own haarcascade
From here, you will learn about how to create your own Haarcascade file. With your single positive image, you can use the opencv_createsamples command to actually create a bunch of positive examples, using your negative images. Your positive image will be superimposed on these negatives, and it will be angled and all sorts of things. It actually can work pretty well, especially if you are really just looking for one specific object. If you are looking to identify all guns, however, you will want to have thousands of unique images of guns, rather than using the opencv_createsamples to generate samples for you. We’ll keep it simple and just use one positive image, and then create a bunch of samples with our negatives.
Note: For The Gun haar cascade created – click here.
2) Detection of Guns using OpenCV
OpenCV comes with a trainer as well as a detector. If you want to train your own classifier for any object like car, planes, etc. you can use OpenCV to create one.
Here we deal with the detection of Gun. First we need to load the required XML classifiers. Then load our input image (or video) in grayscale mode. Now we find the guns in the image. If guns are found, it returns the positions of detected guns as
Rect(x, y, w, h). Once we get these locations, we can create a ROI(Region of Interest) for the gun.
- Object Detection with Detection Transformer (DERT) by Facebook
- Real-Time Edge Detection using OpenCV in Python | Canny edge detection method
- Python | Corner Detection with Shi-Tomasi Corner Detection Method using OpenCV
- Python | Corner detection with Harris Corner Detection method using OpenCV
- Collision Detection in PyGame
- Text detection using Python
- Hotword detection with Python
- Python - Tuple key detection from value list
- Python - Edge Detection using Pillow
- Z score for Outlier Detection - Python
- Car driving using hand detection in Python
- Circle Detection using OpenCV | Python
- Python | Smile detection using OpenCV
- Pedestrian Detection using OpenCV-Python
- Selective Search for Object Detection | R-CNN
- Text Detection and Extraction using OpenCV and OCR
- Machine Learning for Anomaly Detection
- ML | Credit Card Fraud Detection
- Python - Eye blink detection project
- White and black dot detection using OpenCV | Python
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.