Home>
I tried to perform face recognition using OpenCV, but I don't know how to recognize the faces of multiple people.
The sample image is a photograph of the faces of three people, but only the leftmost face is recognized.
Corresponding source codeimport matplotlib.pyplot as plt
import urllib.request as req
import cv2
url = "destination url of sample image"
req.url retrieve (url, "sample image.png")
img = cv2.imread ("Sample image.png")
img_gray = cv2.cvtColor (img, cv2.COLOR_BGR2RGB)
url2 = "https://raw.githubusercontent.com/opencv/opencv/master/data/haarcascades/haarcascade_frontalface_alt.xml"
req.urlretrieve (url2, "cascade.xml")
cascade_file = "cascade.xml"
cascade = cv2.CascadeClassifier (cascade_file)
face_list = cascade.detectMultiScale (img_gray, minSize = (100, 100))
if len (face_list) == 0:
print ("failure")
quit ()
for (x, y, w, h) in face_list:
print ("Face position =", x, y, w, h)
red = (0, 0, 255)
cv2.rectangle (img, (x, y,), (x + w, y + h), red, thickness = 10)
cv2.imwrite ("sample image-face-detect.png", img)
plt.imshow (cv2.cvtColor (img, cv2.COLOR_BGR2RGB))
plt.show ()
What I tried
I wondered if I could change the argument of the detectMultiScale method, but it didn't work.
I thought about how to divide the image, but I thought it was not a good method because it would not be very versatile.
I'm not sure how to recognize the faces of multiple people in one process.
The execution environment is Google Colaboratory.
-
Answer # 1
Related articles
- python - i can't send multiple images with the line api
- python - detect whole body and upper body with opencv
- python 3x - multiple outputs from a list of tuples
- python - cannot inherit a class with multiple arguments
- python opencv color index
- python opencv recording time
- python - i don't see the error in the face cropping program with opencv
- python - image recognition with keras
- python - how to load multiple time formats with pandas
- python - (tensorflow/speech recognition) what kind of numerical conversion method is there to enable input of arbitrary wav file
- python - i got an error in opencv
- python multiple regression analysis statsmodelsformula
- python - randomly extract data from multiple data frames (no between data frames is the same)
- i want to perform multiple processes with else in python list comprehension notation
- python 3x - how to specify multiple conditions with a regular expression
- python - image recognition using cnn keras multiple inputs
- python - [tkinter] multiple selectable combobox
- python - i want to make a total value of channels with multiple images
- python - [opencv] i want to display the area of each object at the position adjacent to the object
I made the argument of the Minsize method smaller and it worked.
It seems that if the face is small, the argument needs to be small for the image.