api: Add use_roi_verify
This commit is contained in:
parent
73f99d08ce
commit
c02b9e342a
@ -673,6 +673,29 @@ class QrVerifyView(BaseView):
|
|||||||
messages.append(f"All angle check api failed")
|
messages.append(f"All angle check api failed")
|
||||||
raise Exception("Angle detection failed")
|
raise Exception("Angle detection failed")
|
||||||
|
|
||||||
|
def roi_verify_check(self, sc, batch, img_fn, messages):
|
||||||
|
feature_roi = self.get_feature_roi(sc.code)
|
||||||
|
if not feature_roi:
|
||||||
|
messages.append(f"feature roi not found for code {sc.code}, skiping")
|
||||||
|
return
|
||||||
|
with tempfile.NamedTemporaryFile(dir="/tmp/", suffix=img_fn + ".roi.jpg") as f:
|
||||||
|
f.write(feature_roi)
|
||||||
|
f.flush()
|
||||||
|
side_by_side_fn = img_fn + ".side_by_side.jpg"
|
||||||
|
qrtool_path = os.path.abspath("../alg/qrtool")
|
||||||
|
cmd = [qrtool_path, 'side_by_side', img_fn, f.name]
|
||||||
|
messages.append("creating side by side image...")
|
||||||
|
subprocess.check_call(cmd, cwd=cwd)
|
||||||
|
roi_verify_py = os.path.abspath("../research/roi-verify.py")
|
||||||
|
roi_verify_model = os.path.abspath("../research/models/resnet18_20250325_114510_94.56.pth")
|
||||||
|
cmd = [roi_verify_py, '--model', roi_verify_model, '--image', side_by_side_fn]
|
||||||
|
messages.append(" ".join(cmd))
|
||||||
|
r = subprocess.call(cmd, cwd=cwd)
|
||||||
|
os.unlink(side_by_side_fn)
|
||||||
|
if r != 0:
|
||||||
|
raise Exception("roi_verify check failed, exit code not 0")
|
||||||
|
messages.append(f"roi_verify check succeeded")
|
||||||
|
|
||||||
def feature_comparison_check(self, sc, batch, img_fn, messages, threshold):
|
def feature_comparison_check(self, sc, batch, img_fn, messages, threshold):
|
||||||
if not threshold:
|
if not threshold:
|
||||||
threshold = batch.feature_comparison_threshold
|
threshold = batch.feature_comparison_threshold
|
||||||
@ -717,6 +740,7 @@ class QrVerifyView(BaseView):
|
|||||||
sd.message = ''
|
sd.message = ''
|
||||||
sd.phone_model = request.data.get("phonemodel")
|
sd.phone_model = request.data.get("phonemodel")
|
||||||
sd.client_log = request.data.get("log")
|
sd.client_log = request.data.get("log")
|
||||||
|
use_roi_verify = request.data.get("use_roi_verify")
|
||||||
messages = []
|
messages = []
|
||||||
try:
|
try:
|
||||||
filebody, filename = get_image(request)
|
filebody, filename = get_image(request)
|
||||||
@ -761,7 +785,10 @@ class QrVerifyView(BaseView):
|
|||||||
sd.tenant = tenant
|
sd.tenant = tenant
|
||||||
sd.batch = sc.batch
|
sd.batch = sc.batch
|
||||||
self.dot_angle_check(sc.batch, tf.name, messages, request.data.get("angle"))
|
self.dot_angle_check(sc.batch, tf.name, messages, request.data.get("angle"))
|
||||||
self.feature_comparison_check(sd, sc.batch, tf.name, messages, threshold)
|
if use_roi_verify:
|
||||||
|
self.roi_verify_check(sd, sc.batch, tf.name, messages)
|
||||||
|
else:
|
||||||
|
self.feature_comparison_check(sd, sc.batch, tf.name, messages, threshold)
|
||||||
sd.succeeded = True
|
sd.succeeded = True
|
||||||
article_id = None
|
article_id = None
|
||||||
if product.article:
|
if product.article:
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user