''' Please write a python code for face detection on a picture using opencv ''' import cv2 # Load the image img = cv2.imread('image.jpg') # Convert the image to grayscale gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY) # Load the face detection classifier face_cascade = cv2.CascadeClassifier('haarcascade_frontalface_default.xml') # Detect faces in the image faces = face_cascade.detectMultiScale(gray, scaleFactor=1.1, minNeighbors=5, minSize=(30, 30)) # Draw rectangles around the detected faces for (x, y, w, h) in faces: cv2.rectangle(img, (x, y), (x+w, y+h), (0, 255, 0), 2) # Display the image with the detected faces cv2.imshow('image', img) cv2.waitKey(0) cv2.destroyAllWindows()