diff --git a/annotating.py b/annotating.py index ff20930..2934ca8 100644 --- a/annotating.py +++ b/annotating.py @@ -45,7 +45,7 @@ def make_dictionary(root_dir): try: with open(jf, 'r', encoding='utf-8') as f: coord_list = json.load(f) - # Format: [["id", x, y], ...] + # Format: [["id", x, y, width_r, "label"], ...] for entry in coord_list: if entry[0] == student_id: coordinates = (entry[1], entry[2]) diff --git a/correction.py b/correction.py index 02c7d11..235bc5c 100644 --- a/correction.py +++ b/correction.py @@ -250,7 +250,8 @@ def process_single_task(task_tuple): # List of (groupid, start, end), in pixels group_data = json.load(f) n = len(group_data) - d_data = {l[0]: (l[1], l[2]) for l in group_data} + # l[3] is ratio of width to width of group + d_data = {l[0]: (l[1], l[2], l[3]) for l in group_data} total_height = group_data[-1][2] use_flash = n >= 4 or total_height <= 500 if not use_flash and limit is not None: @@ -307,9 +308,10 @@ def process_single_task(task_tuple): if pid not in d_data: print("Error : Gemini answered a copie id not present", pid, label, group_name) continue - yming,ymaxg = d_data[pid] + yming,ymaxg, width_r = d_data[pid] if ymin < yming-50 or ymax > ymaxg+50: - print("Error : Gemini answered box2d not at the right position", pid, label, group_name) + print("Error : Gemini answered box2d too low/up", + pid, label, group_name) if ymax < yming or ymin > ymaxg: print("Removing the box.") f["box_2d"] = None @@ -319,8 +321,16 @@ def process_single_task(task_tuple): f["box_2d"] = [nymin, xmin, nymax, xmax] # print("Group :", yming, ymaxg, "Answered:", ymin, ymax) + if xmax / 1000 > width_r: + print("Error : Gemini answered box2d too right", + pid, label, group_name) + if xmin /1000 > width_r: + print("Removing the box.") + f["box_2d"] = None + continue + f["box_2d"][3] = int(width_r * 1000) - # --- CRITICAL: Use Lock for writing shared data --- + # --- Use Lock for writing shared data --- with io_lock: if label not in results: results[label] = [] # Ensure key exists if not using defaultdict diff --git a/grouping.py b/grouping.py index 29a1175..59f7fee 100644 --- a/grouping.py +++ b/grouping.py @@ -178,7 +178,8 @@ def create_jpg(identifier, group_index, group, root_dir): # Record Image Coordinates h_min = y_offset h_max = y_offset + img.height - metadata.append((dd, h_min, h_max)) + # identifier should be a label + metadata.append((dd, h_min, h_max, img.width/total_width, identifier)) # Draw Image x_pos = 0