Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Incorrect bounding box #1242

Open
ammar3010 opened this issue Sep 21, 2023 · 0 comments
Open

Incorrect bounding box #1242

ammar3010 opened this issue Sep 21, 2023 · 0 comments

Comments

@ammar3010
Copy link

ammar3010 commented Sep 21, 2023

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant