Dolphin-V1.5 layout string parsing function Parse layout string to extract bbox and category information Supports multiple formats: 1. Original format: [x1,y1,x2,y2] label 2. New format: [x1,y1,x2,y2][label][PAIR_SEP] or [x1,y1,x2,y2][label][meta_info][PAIR_SEP]
(bbox_str)
| 170 | |
| 171 | |
| 172 | def parse_layout_string(bbox_str): |
| 173 | """ |
| 174 | Dolphin-V1.5 layout string parsing function |
| 175 | Parse layout string to extract bbox and category information |
| 176 | Supports multiple formats: |
| 177 | 1. Original format: [x1,y1,x2,y2] label |
| 178 | 2. New format: [x1,y1,x2,y2][label][PAIR_SEP] or [x1,y1,x2,y2][label][meta_info][PAIR_SEP] |
| 179 | """ |
| 180 | parsed_results = [] |
| 181 | |
| 182 | segments = bbox_str.split('[PAIR_SEP]') |
| 183 | new_segments = [] |
| 184 | for seg in segments: |
| 185 | new_segments.extend(seg.split('[RELATION_SEP]')) |
| 186 | segments = new_segments |
| 187 | for segment in segments: |
| 188 | segment = segment.strip() |
| 189 | if not segment: |
| 190 | continue |
| 191 | |
| 192 | coord_pattern = r'\[(\d*\.?\d+),(\d*\.?\d+),(\d*\.?\d+),(\d*\.?\d+)\]' |
| 193 | coord_match = re.search(coord_pattern, segment) |
| 194 | label_matches = extract_labels_from_string(segment) |
| 195 | |
| 196 | if coord_match and label_matches: |
| 197 | coords = [float(coord_match.group(i)) for i in range(1, 5)] |
| 198 | label = label_matches[0].strip() |
| 199 | parsed_results.append((coords, label, label_matches[1:])) # label_matches[1:] 是 tags |
| 200 | |
| 201 | return parsed_results |
| 202 | |
| 203 | |
| 204 | def process_coordinates(coords, pil_image): |
no test coverage detected