Spaces:
Running
Running
added valid len
Browse files
comic_panel_extractor/llm_panel_extractor.py
CHANGED
|
@@ -99,25 +99,27 @@ class LLMPanelExtractor:
|
|
| 99 |
if high_confidence_filter.sum() > 0:
|
| 100 |
first_detection_result.boxes = first_detection_result.boxes[high_confidence_filter]
|
| 101 |
newly_detected_boxes = self.extract_bounding_boxes(first_detection_result.boxes)
|
| 102 |
-
|
| 103 |
-
|
| 104 |
-
|
| 105 |
-
|
| 106 |
-
|
| 107 |
-
|
| 108 |
-
|
| 109 |
-
|
| 110 |
-
|
| 111 |
-
|
| 112 |
-
|
| 113 |
-
|
| 114 |
-
|
| 115 |
-
|
| 116 |
-
|
| 117 |
-
|
| 118 |
-
|
| 119 |
-
|
| 120 |
-
|
|
|
|
|
|
|
| 121 |
|
| 122 |
# Process boxes even if no new detections
|
| 123 |
all_processed_boxes = self.pre_all_processed_boxes(all_processed_boxes, image_width, image_height)
|
|
@@ -138,15 +140,16 @@ class LLMPanelExtractor:
|
|
| 138 |
similar_remaining_regions_path = f"{self.config.output_folder}/{constant.INDEX:04d}_remaining_similarity_debug.jpg"
|
| 139 |
similar_remaining_box = utils.find_similar_remaining_regions(all_processed_boxes, (image_width, image_height), similar_remaining_regions_path)
|
| 140 |
if similar_remaining_box:
|
| 141 |
-
|
| 142 |
-
|
| 143 |
-
|
|
|
|
| 144 |
|
| 145 |
-
|
| 146 |
|
| 147 |
-
|
| 148 |
-
|
| 149 |
-
|
| 150 |
|
| 151 |
return current_processed_image_path, existing_boxes
|
| 152 |
|
|
|
|
| 99 |
if high_confidence_filter.sum() > 0:
|
| 100 |
first_detection_result.boxes = first_detection_result.boxes[high_confidence_filter]
|
| 101 |
newly_detected_boxes = self.extract_bounding_boxes(first_detection_result.boxes)
|
| 102 |
+
newly_detected_boxes = utils.is_valid_panel((image_width, image_height), newly_detected_boxes, self.config.min_width_ratio, self.config.min_height_ratio)
|
| 103 |
+
if newly_detected_boxes:
|
| 104 |
+
all_processed_boxes.extend(self.extract_bounding_boxes(first_detection_result.boxes))
|
| 105 |
+
|
| 106 |
+
# Process and extend boxes
|
| 107 |
+
all_processed_boxes = self.pre_all_processed_boxes(all_processed_boxes, image_width, image_height)
|
| 108 |
+
|
| 109 |
+
# Crop and save detected panels
|
| 110 |
+
self.crop_and_save_detected_panels(newly_detected_boxes)
|
| 111 |
+
|
| 112 |
+
# Save prediction visualization
|
| 113 |
+
visualization_result = first_detection_result.plot()
|
| 114 |
+
constant.INDEX += 1
|
| 115 |
+
debug_output_path = f"{self.config.output_folder}/{constant.INDEX:04d}_debug.jpg"
|
| 116 |
+
Image.fromarray(visualization_result[..., ::-1]).save(debug_output_path)
|
| 117 |
+
|
| 118 |
+
# Create black and white mask
|
| 119 |
+
constant.INDEX += 1
|
| 120 |
+
masked_output_path = f"{self.config.output_folder}/{constant.INDEX:04d}_draw_black.jpg"
|
| 121 |
+
masked_image_path = utils.draw_black(self.config.org_input_path, all_processed_boxes, masked_output_path, stripe=False)
|
| 122 |
+
return masked_image_path, newly_detected_boxes
|
| 123 |
|
| 124 |
# Process boxes even if no new detections
|
| 125 |
all_processed_boxes = self.pre_all_processed_boxes(all_processed_boxes, image_width, image_height)
|
|
|
|
| 140 |
similar_remaining_regions_path = f"{self.config.output_folder}/{constant.INDEX:04d}_remaining_similarity_debug.jpg"
|
| 141 |
similar_remaining_box = utils.find_similar_remaining_regions(all_processed_boxes, (image_width, image_height), similar_remaining_regions_path)
|
| 142 |
if similar_remaining_box:
|
| 143 |
+
similar_remaining_box = utils.is_valid_panel((image_width, image_height), similar_remaining_box, self.config.min_width_ratio, self.config.min_height_ratio)
|
| 144 |
+
if similar_remaining_box:
|
| 145 |
+
self.crop_and_save_detected_panels(similar_remaining_box)
|
| 146 |
+
existing_boxes.extend(similar_remaining_box)
|
| 147 |
|
| 148 |
+
all_processed_boxes = self.pre_all_processed_boxes(existing_boxes, image_width, image_height)
|
| 149 |
|
| 150 |
+
constant.INDEX += 1
|
| 151 |
+
current_processed_image_path = f"{self.config.output_folder}/{constant.INDEX:04d}_remaining_similarity_draw_black.jpg"
|
| 152 |
+
current_processed_image_path = utils.draw_black(self.config.org_input_path, all_processed_boxes, current_processed_image_path, stripe=False)
|
| 153 |
|
| 154 |
return current_processed_image_path, existing_boxes
|
| 155 |
|