【发布时间】:2021-12-15 16:30:09
【问题描述】:
我想从不同角度的图像中提取人脸图像/部分。
我有如下图片:
我已尝试使用以下代码。
import cv2
import sys
import numpy as np
import cv2
import matplotlib.pyplot as plt
%matplotlib inline
# imagePath = sys.argv[1]
image = cv2.imread('_img_1.png')
gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
faceCascade = cv2.CascadeClassifier(cv2.data.haarcascades + "haarcascade_frontalface_default.xml")
faces = faceCascade.detectMultiScale(
gray,
scaleFactor=1.3,
minNeighbors=3,
minSize=(30, 30)
)
print("[INFO] Found {0} Faces.".format(len(faces)))
for (x, y, w, h) in faces:
cv2.rectangle(image, (x, y), (x + w, y + h), (0, 255, 0), 2)
roi_color = image[y:y + h, x:x + w]
print("[INFO] Object found. Saving locally.")
cv2.imwrite(str(w) + str(h) + '_faces.jpg', roi_color)
plt.imshow(roi_color)
plt.show()
status = cv2.imwrite('faces_detected.jpg', image)
print("[INFO] Image faces_detected.jpg written to filesystem: ", status)
如何从旋转图像中提取人脸图像/部分?
【问题讨论】:
-
我相信
CascadeClassifier只检测到直立的脸。我认为它无法检测到您的示例图片中的人脸。
标签: python-3.x numpy opencv cv2 face-detection