0

hi guys I want to implement (zoom in and zoom out) like digital camera to the detected faces while real-time capturing using opencv, is there is any way I can do it without just cropping the frame then display it.

here is my code ... ,,,

import cv2

# Load the cascade
face_cascade = cv2.CascadeClassifier('haarcascade_frontalface_default.xml')

# To capture video from webcam. 
cap = cv2.VideoCapture(0)
# To use a video file as input 
# cap = cv2.VideoCapture('filename.mp4')

while True:
    # Read the frame
    _, img = cap.read()
    # Convert to grayscale
    gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
    # Detect the faces
    faces = face_cascade.detectMultiScale(gray, 1.1, 4)
    # Draw the rectangle around each face
    for (x, y, w, h) in faces:
        cv2.rectangle(img, (x, y), (x+w, y+h), (255, 0, 0), 2)
    # Display
    cv2.imshow('img', img)
    # Stop if escape key is pressed
    k = cv2.waitKey(30) & 0xff
    if k==27:
        break
# Release the VideoCapture object
cap.release()
Silver
  • 1
  • 1
  • 1
    Cropping and displaying is the only zoom you can get digitally (if you could acces to a real zoom on your camera, that would be different) – Ivan Jul 07 '21 at 13:28
  • i want to apply zooming by cropping the frame but i dont have any idea of how to make it work properly. – Silver Jul 08 '21 at 05:17
  • Just use the face coordinates following [this](https://stackoverflow.com/a/15589825/11261546) – Ivan Jul 08 '21 at 14:11

0 Answers0