facenet icon indicating copy to clipboard operation
facenet copied to clipboard

Incorrect bounding box

Open ammar3010 opened this issue 1 year ago • 0 comments

I am facing the same issue. I am detecting the faces and saving the cropped face image on local drive to further train a facial recognition model. But the bounding box is only accurate on top left corner. Other corners are expanded. Below is my code:

`from facenet_pytorch import MTCNN import cv2 import os

mtcnn = MTCNN(keep_all=True, device='cuda:0') dir_path = 'assets/raw/ammar' save_path = 'assets/face_raw/ammar'

files = os.listdir(dir_path)

for file in files: img = cv2.imread(dir_path+"/"+file, cv2.COLOR_BGR2RGB) boxes, _ = mtcnn.detect(img)

x = int(boxes[0][0])
y = int(boxes[0][1])
w = int(boxes[0][2])
h = int(boxes[0][3])

crop_img = img[y:y+h, x:x+w]

cv2.imwrite(save_path+"/"+file, crop_img)`

I'm stuck here and cannot find a solution.

ammar3010 avatar Sep 21 '23 04:09 ammar3010