๐Ÿš€ Offensive Symbol Detection Tool (OpenCV + Haar Cascade)

๐Ÿง  Project Overview

This project demonstrates how to train a custom Haar Cascade classifier using OpenCV to detect and censor offensive symbols in images or video streams. The system supports both static image detection and real-time webcam detection.

๐Ÿ›  Technologies Used

๐Ÿ“‚ Step 1: Clone Haar Training Repository

git clone https://github.com/mrnugget/opencv-haar-classifier-training
cd opencv-haar-classifier-training

๐Ÿ–ผ Step 2: Prepare Training Images

Collect 20โ€“40 positive images containing the symbol and 600โ€“800 negative images without the symbol. Place them into:

๐Ÿ“„ Step 3: Generate Image Lists

find ./positive_images -iname "*.jpg" > positives.txt
find ./negative_images -iname "*.jpg" > negatives.txt

โš™๏ธ Step 4: Create Training Samples

perl bin/createsamples.pl positives.txt negatives.txt samples 1500

๐Ÿ”— Step 5: Merge Vector Files

cd tools
python mergevec.py -v /path/to/samples/ -o samples.vec

๐Ÿ‹๏ธ Step 6: Train the Cascade

opencv_traincascade -data classifier -vec samples.vec -bg negatives.txt -numStages 20 -minHitRate 0.999 -maxFalseAlarmRate 0.5 -numPos 1000 -numNeg 600 -w 80 -h 40 -mode ALL

After training completes, your custom classifier will be located at:

classifier/cascade.xml

๐Ÿงช Step 7: Test on an Image

cascade = cv2.CascadeClassifier('cascade.xml')
image = cv2.imread('test.jpg')
gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)

detections = cascade.detectMultiScale(gray, 1.3, 5)

for (x, y, w, h) in detections:
    cv2.rectangle(image, (x,y), (x+w,y+h), (0,255,0), 2)

๐ŸŽฅ Step 8: Real-Time Webcam Detection

python detect_using_webcam.py

๐Ÿ”’ Step 9: Censor the Detected Region

roi = image[y:y+h, x:x+w]
blur = cv2.GaussianBlur(roi, (99, 99), 30)
image[y:y+h, x:x+w] = blur

โš ๏ธ Challenges Faced

โœ… Final Outcome

Successfully built and trained a custom Haar Cascade classifier capable of detecting offensive symbols in both images and live video. The system can automatically censor detected regions, demonstrating practical computer vision and classical machine learning techniques.

GitHub Repository: https://github.com/aterakrofi/Haarcascade-to-detect-swastika

โ† Back to Resume