|
| 1 | +import json |
| 2 | + |
| 3 | + |
| 4 | +# いろいろなフォーマットを受け取って、VisualInspectionAiのjsonlで出力するのが責務 |
| 5 | +class VisualInspectionAi: |
| 6 | + |
| 7 | + def __init__(self, vertex, project_type): |
| 8 | + self.vertex = vertex |
| 9 | + self.project_type = project_type |
| 10 | + |
| 11 | + @classmethod |
| 12 | + def from_bbox(cls, bbox_json): |
| 13 | + # TODO bboxからvertexへの変換処理 |
| 14 | + vertex = [{"x": 0.1, "y": 0.1}] |
| 15 | + return cls(vertex, "bbox") |
| 16 | + |
| 17 | + @classmethod |
| 18 | + def from_segmentation(cls, segmentation_json, project_type): |
| 19 | + # TODO segmentationからvertexへの変換処理 |
| 20 | + vertex = [{"x": 0.1, "y": 0.1}] |
| 21 | + return cls(vertex, "segmentation") |
| 22 | + |
| 23 | + # VisualInspectionAiのjsonlを作成する。 |
| 24 | + def __make_jsonl(self): |
| 25 | + via = [] |
| 26 | + via_el = { |
| 27 | + "image_gcs_uri": "gs://ffod-98sm/20240613/NG/test/BQ1334B__11-7_18-19_0004.png", |
| 28 | + "vi_annotations": self.__make_vi_annotations_jsonl(), |
| 29 | + "dataItemResourceLabels": { |
| 30 | + "goog_vi_ml_use": "test" |
| 31 | + } |
| 32 | + } |
| 33 | + via.append(via_el) |
| 34 | + return via |
| 35 | + |
| 36 | + def __make_vi_annotations_jsonl(self): |
| 37 | + return { |
| 38 | + "viBoundingPoly": { |
| 39 | + "vertex": self.vertex |
| 40 | + }, |
| 41 | + "annotationSpec": "defect", |
| 42 | + "annotationSet": "Polygons Regions" if self.project_type == "bbox" else "TODO segmentationの場合の表記調査" |
| 43 | + } |
| 44 | + |
| 45 | + def as_jsonl(self): |
| 46 | + return json.dumps(self.__make_jsonl(), ensure_ascii=False, indent=4) + '\n' |
| 47 | + |
0 commit comments