para test
This commit is contained in:
parent
b69c4f9ecc
commit
0ea955674a
@ -3,7 +3,7 @@
|
||||
#
|
||||
import json
|
||||
import sys
|
||||
|
||||
import numpy as np
|
||||
### export PYTHONPATH=/wherever/yoloserv/modules ... as long as "paravision/.../" is in there
|
||||
from paravision.recognition.exceptions import ParavisionException
|
||||
from paravision.recognition.engine import Engine
|
||||
@ -47,31 +47,51 @@ class Paravision(FaceClass):
|
||||
|
||||
|
||||
|
||||
|
||||
# @doc compare two named images, previously loaded
|
||||
def compare(self, name1, name2):
|
||||
print("** face_recognition::compare ... %s vs %s" % (name1,name2))
|
||||
print("** paravision::compare ... %s vs %s" % (name1, name2))
|
||||
|
||||
# Ensure the image is reshaped to match the expected input size (e.g., (1, 3, 112, 112))
|
||||
def adjust_image_shape(img, target_shape=(1, 3, 112, 112)):
|
||||
img_shape = img.shape
|
||||
|
||||
# If image shape doesn't match target, adjust it (resize, pad, or reshape as needed)
|
||||
if img_shape != target_shape:
|
||||
print(f"Adjusting image shape from {img_shape} to {target_shape}")
|
||||
# Resize or pad as necessary to match the target shape
|
||||
img = np.resize(img, target_shape) # Resizes without preserving aspect ratio (can be modified if needed)
|
||||
|
||||
return img
|
||||
|
||||
# Adjust the shape of both images
|
||||
self.imgs[name1] = adjust_image_shape(self.imgs[name1])
|
||||
self.imgs[name2] = adjust_image_shape(self.imgs[name2])
|
||||
|
||||
# Get embeddings using the Paravision SDK
|
||||
self.encs[name1] = self.sdk.get_embedding_from_prepared_image(self.imgs[name1])
|
||||
self.encs[name2] = self.sdk.get_embedding_from_prepared_image(self.imgs[name2])
|
||||
#if self.encs[name1]==[]:
|
||||
# return '{ "status":14330, "remark":"could not encode image", "guilty_param":"img1", "guilty_value":"%s" }' % name1
|
||||
#if self.encs[name2]==[]:
|
||||
# return '{ "status":14331, "remark":"could not encode image", "guilty_param":"img2", "guilty_value":"%s" }' % name2
|
||||
|
||||
# Debug: Print the encodings
|
||||
print(self.encs.keys())
|
||||
print(self.encs[name1])
|
||||
print(self.encs[name2])
|
||||
try:
|
||||
res = self.sdk.get_match_score(self.model, other.model)
|
||||
print("Match is ",res)
|
||||
#self.match_score = 1000 * (1 - face_recognition.face_distance([self.encs[name1][0]], self.encs[name2][0]))
|
||||
#print("Score is ",self.match_score)
|
||||
|
||||
# Create .json
|
||||
self.tree["score"] = self.match_score[0]
|
||||
try:
|
||||
# Assuming 'self.model' and 'other.model' are defined elsewhere in your code
|
||||
res = self.sdk.get_match_score(self.model, other.model)
|
||||
print("Match is ", res)
|
||||
|
||||
# Store the result in self.tree
|
||||
self.tree["score"] = res # Assuming 'res' is the match score
|
||||
|
||||
except Exception as ex:
|
||||
print("** paravision::compare exception ... " + str(ex) )
|
||||
self.errstr = "image comparison exception at compute_scores: "+str(ex)
|
||||
print("** paravision::compare exception ... " + str(ex))
|
||||
self.errstr = "image comparison exception at compute_scores: " + str(ex)
|
||||
return '{ "status":332410, "remark":"%s" }' % self.errstr
|
||||
return '{ "status":0, "remark":"OK", "score":%d }' % self.match_score[0]
|
||||
|
||||
# Return success with the match score
|
||||
return '{ "status":0, "remark":"OK", "score":%d }' % self.tree["score"]
|
||||
|
||||
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user