From e5d0061fbaf1d1b80e1ca3bbf3f63baf5563161b Mon Sep 17 00:00:00 2001 From: arbadacarba <63317640+arbadacarbaYK@users.noreply.github.com> Date: Mon, 27 May 2024 17:22:32 +0200 Subject: [PATCH] Update pixelateTG.py --- pixelateTG.py | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/pixelateTG.py b/pixelateTG.py index a5f2bd1..b4e74d4 100644 --- a/pixelateTG.py +++ b/pixelateTG.py @@ -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'] @@ -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)