api: Fix roi-verify

This commit is contained in:
Fam Zheng 2025-03-25 13:57:16 +08:00
parent 3d96d2a7ad
commit 008e3839bb
4 changed files with 9 additions and 5 deletions

1
.gitignore vendored
View File

@ -5,3 +5,4 @@ build
/emtest/target /emtest/target
/dataset/local /dataset/local
/detection/model /detection/model
/api/db.sqlite3

View File

@ -27,3 +27,4 @@ admin.site.register(GlobalConfig)
admin.site.register(ABTest) admin.site.register(ABTest)
admin.site.register(ABTestSample) admin.site.register(ABTestSample)
admin.site.register(Tenant)

View File

@ -673,16 +673,17 @@ 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): def roi_verify_check(self, sc, img_fn, messages):
feature_roi = self.get_feature_roi(sc.code) feature_roi = self.get_feature_roi(sc.code)
if not feature_roi: if not feature_roi:
messages.append(f"feature roi not found for code {sc.code}, skiping") messages.append(f"feature roi not found for code {sc.code}, skiping")
return return
with tempfile.NamedTemporaryFile(dir="/tmp/", suffix=img_fn + ".roi.jpg") as f: with tempfile.NamedTemporaryFile(dir="/tmp/", suffix=".roi.jpg") as f:
f.write(feature_roi) f.write(feature_roi)
f.flush() f.flush()
side_by_side_fn = img_fn + ".side_by_side.jpg" side_by_side_fn = img_fn + ".side_by_side.jpg"
qrtool_path = os.path.abspath("../alg/qrtool") qrtool_path = os.path.abspath("../alg/qrtool")
cwd = os.path.dirname(qrtool_path)
cmd = [qrtool_path, 'side_by_side', img_fn, f.name] cmd = [qrtool_path, 'side_by_side', img_fn, f.name]
messages.append("creating side by side image...") messages.append("creating side by side image...")
subprocess.check_call(cmd, cwd=cwd) subprocess.check_call(cmd, cwd=cwd)
@ -690,10 +691,10 @@ class QrVerifyView(BaseView):
roi_verify_model = os.path.abspath("../research/models/resnet18_20250325_114510_94.56.pth") 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] cmd = [roi_verify_py, '--model', roi_verify_model, '--image', side_by_side_fn]
messages.append(" ".join(cmd)) messages.append(" ".join(cmd))
r = subprocess.call(cmd, cwd=cwd) r = subprocess.call(cmd)
os.unlink(side_by_side_fn) os.unlink(side_by_side_fn)
if r != 0: if r != 0:
raise Exception("roi_verify check failed, exit code not 0") raise Exception("roi_verify check failed")
messages.append(f"roi_verify check succeeded") 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):
@ -786,7 +787,7 @@ class QrVerifyView(BaseView):
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"))
if use_roi_verify: if use_roi_verify:
self.roi_verify_check(sd, sc.batch, tf.name, messages) self.roi_verify_check(sd, tf.name, messages)
else: else:
self.feature_comparison_check(sd, sc.batch, tf.name, messages, threshold) self.feature_comparison_check(sd, sc.batch, tf.name, messages, threshold)
sd.succeeded = True sd.succeeded = True

1
research/.dockerignore Normal file
View File

@ -0,0 +1 @@
/data