我有一个裁切任务,我需要将np数组发送到dlib,但是它只接受RGB图像,我有一个RGBA数组。
def detect_faces(image):
# Create a face detector
face_detector = dlib.get_frontal_face_detector()
# Run detector and get bounding boxes of the faces on image.
detected_faces = face_detector(image, 1)
face_frames = [(x.left(), x.top(),
x.right(), x.bottom()) for x in detected_faces]
return face_frames
image_with_alpha = [[[1.06504470e-01 8.68966281e-02 1.65327996e-01
9.89165127e-01]
[1.14992462e-01 9.53846201e-02 1.73815995e-01 9.89192665e-01]
[1.23680241e-01 1.04072399e-01 1.82503775e-01 9.89248633e-01]
...
[4.04258035e-02 4.41362113e-02 1.53940141e-01 1.15064040e-07]
[3.30277309e-02 3.67381386e-02 1.46542057e-01 1.10802951e-07]
[2.82842554e-02 3.19946632e-02 1.41798586e-01 1.08695218e-07]]
[[1.11282051e-01 9.16742086e-02 1.70105591e-01 9.89170969e-01]
[1.16157092e-01 9.65492502e-02 1.74980626e-01 9.89198565e-01]
[1.23972625e-01 1.04364775e-01 1.82796150e-01 9.89254534e-01]
...
# Load image
img_path = 'test_data/me.jpg'
image = io.imread(img_path) #Need to change to an image with RGBA (image_with_alpha)
# Detect faces
detected_faces = detect_faces(image)
# Crop faces and plot
for n, face_rect in enumerate(detected_faces):
face = Image.fromarray(image).crop(face_rect)
通常,我需要以某种方式将此数组转换为image = io.imread(img_path)