Python Forum
How to crop eyes/nose/mouth in the face only? [OpenCV]
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to crop eyes/nose/mouth in the face only? [OpenCV]
#1
When I crop only face it does the job, but when I want to crop eyes, nose, mouth that are detected in the face it doesn't.

gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
faces = face_cascade.detectMultiScale(gray, 1.3, 5)
for (x, y, w, h) in faces:
    roi_gray = gray[y:y+w, x:x+w]
    roi_color = frame[y:y+h, x:x+w]
    eyes = left_eye_cascade.detectMultiScale(roi_gray, 1.3, 22)
    for (ex, ey, ew, eh) in eyes:
        cv2.rectangle(roi_color, (ex, ey), (ex + ew, ey + eh), (0, 255, 0), 5)

crop_img = frame[ey:ey+eh, ex:ex+ew]
cv2.imshow("cropped", crop_img)
What am I doing wrong? Sorry for if this sound dumb. I'm just new to Python and OpenCV and I am just curious in how this works. Any help/explanation is welcome. Thank you
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  How to crop a video to 9:16? yschrs 3 2,652 May-14-2022, 06:48 AM
Last Post: yschrs
  How to zoom on/follow MOUTH in FACE? (OPENCV Face Detection) buzzdarkyear 2 1,840 Jan-12-2022, 12:31 AM
Last Post: buzzdarkyear
  Face detector project? korenron 2 2,167 Mar-24-2021, 03:43 PM
Last Post: korenron
  Crop Image to Bounding Box Coordinates sallyjc81 2 5,123 Jul-23-2020, 08:46 AM
Last Post: sallyjc81
  Loop face landmarking in all folder using dlib lokoprof 5 3,006 Apr-17-2020, 10:08 AM
Last Post: deanhystad
  pycharm face recognition mcgrim 5 8,515 May-20-2019, 05:06 PM
Last Post: Larz60+
  1st Script written doesn't output anything. Need some else's eyes Kym 3 3,101 Mar-21-2018, 04:19 PM
Last Post: nilamo
  Object Detection that records the number of secs the face is not detected trabis03 1 2,575 Jul-21-2017, 04:14 PM
Last Post: nilamo

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020