I am writing a function that compares two images using python, matplotlib, and gradio to see if the person in the compare image is the same as the person in the original image, and if so, returns it by writing the person's name on the image. I wrote the code like this File "c:\Users\admin\AppData\Local\Programs\Python\Python310\lib\site-packages\gradio\components\image.py", line 286, in postprocess raise ValueError("Cannot process this value as an Image") ValueError: Cannot process this value as an Image
which is an error. I'm getting the error in the return part (#error spot), what should I write here?
def compare(original_image, compare_image):
#img_original_rgb = cv2.imread(original_image)
#img_compare_rgb = cv2.imread(compare_image)
img_original_rgb = cv2.cvtColor(original_image, cv2.COLOR_BGR2RGB)
img_compare_rgb = cv2.cvtColor(compare_image, cv2.COLOR_BGR2RGB)
descriptors = encode_faces(img_original_rgb, shapes)
rects, shapes, _ = find_faces(img_compare_rgb)
fig, ax = plt.subplots(1, figsize=(20, 20))
ax.imshow(img_compare_rgb)
for i, desc in enumerate(descriptors):
found = False
for name, saved_desc in descs.items():
dist = np.linalg.norm([desc] - saved_desc, axis=1)
if dist < 0.6:
found = True
text = ax.text(rects[i][0][0], rects[i][0][1], name,
color='b', fontsize=40, fontweight='bold')
text.set_path_effects(
[path_effects.Stroke(linewidth=10, foreground='white'), path_effects.Normal()])
rect = patches.Rectangle(rects[i][0],
rects[i][1][1] - rects[i][0][1],
rects[i][1][0] - rects[i][0][0],
linewidth=2, edgecolor='w', facecolor='none')
ax.add_patch(rect)
break
if not found:
ax.text(rects[i][0][0], rects[i][0][1], 'unknown',
color='r', fontsize=20, fontweight='bold')
rect = patches.Rectangle(rects[i][0],
rects[i][1][1] - rects[i][0][1],
rects[i][1][0] - rects[i][0][0],
linewidth=2, edgecolor='r', facecolor='none')
ax.add_patch(rect)
plt.axis('off')
plt.savefig('result/output.png')
#error spot
return fig
demo = gr.Interface(
fn=compare,
inputs=["image","image"],
outputs=["image"],
)
demo.launch(debug = True)
I tried return plt.figure() but its not working.