python - DeepFace verify() 可以接受图像数组或 PIL Image 对象吗?

标签 python image python-imaging-library verify

我的 DeepFace 实现

def verify(img, frame, model):
    results= DeepFace.verify(img, frame, enforce_detection=False, model_name=model)
    print("result: ", results)
    verification= results['verified']
    if verification is True:
        print(model, "Successfully recognised. SCORE=")
        return
    return

我试图将 PIL 图像而不是“*.jpg”传递给 verify() 函数,但它给出错误

    raise ValueError("Invalid arguments passed to verify function: ", instance)
ValueError: ('Invalid arguments passed to verify function: ', <PIL.Image.Image image mode=RGB size=160x160 at 0x7F4D5D03FBE0>)

我想问有什么办法可以直接传递PIL Image对象或图像数组而不需要事先将其保存到磁盘吗?

我正在传递什么:

picture= "extracted_face_picture/single_face_picture.jpg"
picture= Image.open(picture)
picture= picture.resize((160,160))

frames_from_npz= "video_faces.npz"
frames= np.load(frames_from_npz)
frames= frames["arr_0"]
i=0
for frames_arr in frames:
    frame= Image.fromarray(frames_arr)

    df.verify(picture,frame, "Facenet")
    print(i, "Above reuslts are for frame", frame_num)
    
    i+= 1

请注意,我仍然可以通过将图像保存在目录中然后使用 imread() 读取它们来成功实现 DeepFace,我只想知道是否还有其他方法而不将图像保存到磁盘

最佳答案

如果您使用this模块,文档说:

Herein, face pairs could be exact image paths, numpy array or base64 encoded images

因此,大概您可以将 PIL 图像 放入 Numpy 数组中,如下所示:

results = DeepFace.verify(np.array(PILIMAGE), ...)

关于python - DeepFace verify() 可以接受图像数组或 PIL Image 对象吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/67856738/

相关文章:

python-3.x - 错误: name 'Image' not defined

python - 从 np.zeros 中选取具有最高值的行

Python+Scipy+集成 : dealing with precision errors in functions with spikes

python - 如何将爬取的数据横向导出到Excel?

javascript - 通过调整页面宽度来更改图像

javascript - 在html5 Canvas 上逐帧绘制视频并用 slider 控制

java - 如何获取图像特定像素的颜色? - java

python PIL : Blend transparent image onto another

python - 在 PIL python 中查询 im.save

python - 运行 python3 manage.py migrate 时 Virtualenv(Pyt​​hon3.5/pip3/Django2.0/psycopg2) 出错