roi.py: Reuse roi file

This commit is contained in:
Fam Zheng 2025-03-23 08:44:58 -07:00
parent 30b23b82de
commit 4e3937b471

View File

@ -71,7 +71,7 @@ def get_roi_data(args):
with open(list_file, "a") as f:
for sd in rr.fetch_scan_data(last_id):
if not sd['image'] or not sd['labels']:
print("skipping", sd['id'])
print(f"skipping {sd['id']}, no image or labels: image={sd['image']}, labels={sd['labels']}")
continue
print("new id", sd['id'])
line = json.dumps({
@ -174,9 +174,12 @@ def roi_sim(frame_roi_img, roi_img):
return siml
def frame_roi(frame_file):
frame_roi_file = frame_file + ".roi.jpg"
if os.path.exists(frame_roi_file):
return cv2.imread(frame_roi_file)
cmd = f'./qrtool frame_roi {frame_file}'
subprocess.check_call(cmd, shell=True, cwd=os.path.dirname(os.path.abspath(__file__)) + "/../alg")
frame_roi_img = cv2.imread(frame_file + ".roi.jpg")
frame_roi_img = cv2.imread(frame_roi_file)
return frame_roi_img
def process_roi_data(id):
@ -185,7 +188,6 @@ def process_roi_data(id):
roi_file = os.path.abspath(f"{rd}/{id}-roi.jpg")
roi_img = cv2.imread(roi_file)
frame_roi_img = frame_roi(frame_file)
frame_roi_img = cv2.imread(frame_file + ".roi.jpg")
size = [128, 128]
frame_roi_img = cv2.resize(frame_roi_img, size)
roi_img = cv2.resize(roi_img, size)