Skip to content

Commit

Permalink
Update pixelateTG.py
Browse files Browse the repository at this point in the history
  • Loading branch information
arbadacarbaYK authored May 27, 2024
1 parent 4fc5e71 commit e5d0061
Showing 1 changed file with 4 additions and 7 deletions.
11 changes: 4 additions & 7 deletions pixelateTG.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from telegram import Update, InlineKeyboardButton, InlineKeyboardMarkup
from telegram.ext import Updater, CallbackContext, CommandHandler, CallbackQueryHandler, MessageHandler, Filters
from concurrent.futures import ThreadPoolExecutor, wait
from mtcnn.mtcnn import MTCNN
from uuid import uuid4

TOKEN = os.environ['TELEGRAM_BOT_TOKEN']
Expand All @@ -13,18 +14,14 @@
RESIZE_FACTOR = 1.5 # Common resize factor
executor = ThreadPoolExecutor(max_workers=MAX_THREADS)

# Load the Haar Cascade classifier for face detection
face_cascade = cv2.CascadeClassifier(cv2.data.haarcascades + 'haarcascade_frontalface_default.xml')

def start(update: Update, context: CallbackContext) -> None:
update.message.reply_text('Send me a picture or a GIF, and I will pixelate faces in it!')

def detect_heads(image):
gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
faces = face_cascade.detectMultiScale(gray, scaleFactor=1.1, minNeighbors=5, minSize=(30, 30))
head_boxes = [(x, y, w, h) for (x, y, w, h) in faces]
mtcnn = MTCNN()
faces = mtcnn.detect_faces(image)
head_boxes = [(face['box'][0], face['box'][1], int(RESIZE_FACTOR * face['box'][2]), int(RESIZE_FACTOR * face['box'][3])) for face in faces]
return head_boxes


def overlay(photo_path, user_id, overlay_type, resize_factor, bot):
image = cv2.imread(photo_path)
Expand Down

0 comments on commit e5d0061

Please sign in to comment.