Skip to content

Commit b617791

Browse files
author
shuichi
committed
commit for review
1 parent b8f1bb9 commit b617791

File tree

2 files changed

+70
-0
lines changed

2 files changed

+70
-0
lines changed
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import json
2+
import os
3+
from visual_inspection_ai import VisualInspectionAi
4+
5+
6+
class VisualInspectionAiConverter:
7+
def convert_from_bbox(self, file_path: str, export_file_path: str) -> dict:
8+
bbox_json = self.open_bbox(file_path)
9+
visual_inspection_ai = VisualInspectionAi.from_bbox(bbox_json)
10+
11+
os.makedirs(os.path.dirname(export_file_path), exist_ok=True)
12+
with open(export_file_path, 'w') as file:
13+
file.write(visual_inspection_ai.as_jsonl())
14+
15+
def open_bbox(self, file_path: str) -> any:
16+
return json.load(open(file_path, "r"))
17+
18+
19+
converter = VisualInspectionAiConverter()
20+
21+
file_path = "./import/visual_inspection_ai/annotations.json" # 入力元のファイルパスを指定
22+
export_file_path = "./export/visual_inspection_ai/test.jsonl" # 出力先のファイルパスを指定
23+
result = converter.convert_from_bbox(file_path, export_file_path)

examples/visual_inspection_ai.py

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
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

Comments
 (0)