Skip to content

Commit afa34d0

Browse files
author
Hara
committed
refactor: フォーマットの修正
1 parent 60e854f commit afa34d0

File tree

3 files changed

+24
-16
lines changed

3 files changed

+24
-16
lines changed

src/minifig_detector.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,8 @@ def preprocess_image(self, img):
6060

6161
# 灰色(114)でパディングして640x640に調整
6262
img_padded = cv2.copyMakeBorder(
63-
img_resized, top, bottom, left, right, cv2.BORDER_CONSTANT, value=(114, 114, 114))
63+
img_resized, top, bottom, left, right, cv2.BORDER_CONSTANT,
64+
value=(114, 114, 114))
6465

6566
# YOLO入力形式に変換: HWC→CHW, [0,1]正規化, バッチ次元追加
6667
img_input = img_padded.transpose(2, 0, 1).astype(
@@ -133,7 +134,8 @@ def postprocess(self, pred, scale, pad):
133134

134135
# 信頼度閾値を満たす検出がない場合
135136
if not boxes:
136-
return {"wasDetected": False, "direction": "NONE", "confidence": 0.0}
137+
return {"wasDetected": False,
138+
"direction": "NONE", "confidence": 0.0}
137139

138140
# Non-Maximum Suppression で重複検出を除去
139141
indices = cv2.dnn.NMSBoxes(
@@ -161,7 +163,8 @@ def detect(self, image_path: str) -> dict:
161163
image_path (str): 画像ファイルのパス
162164
163165
Returns:
164-
dict: 検出結果 {"wasDetected": bool, "direction": str, "confidence": float}
166+
dict: 検出結果 {"wasDetected": bool, "direction": str,
167+
"confidence": float}
165168
"""
166169
# 共通エラーレスポンス
167170
error_result = {"wasDetected": False,

src/server/fastapi_server.py

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,6 @@ def upload_minifig_image(file: UploadFile = File(...)) -> JSONResponse:
128128
Returns:
129129
JSONResponse: 結果メッセージとステータスコード
130130
"""
131-
132131
# 画像のファイル名の取得
133132
file_name = file.filename
134133

@@ -164,31 +163,37 @@ def upload_minifig_image(file: UploadFile = File(...)) -> JSONResponse:
164163
if detection_result["direction"] == "front":
165164
# frontは既存がfront以外なら即更新、frontなら高信頼度で更新
166165
if (best_minifig_result["best_direction"] != "front" or
167-
detection_result["confidence"] > best_minifig_result["best_confidence"]):
166+
detection_result["confidence"] >
167+
best_minifig_result["best_confidence"]):
168168
# それぞれの値を更新
169169
best_minifig_result["best_image_path"] = file_path
170-
best_minifig_result["best_confidence"] = detection_result["confidence"]
171-
best_minifig_result["best_direction"] = detection_result["direction"]
170+
best_minifig_result["best_confidence"] = (
171+
detection_result["confidence"])
172+
best_minifig_result["best_direction"] = (
173+
detection_result["direction"])
172174

173175
# 既存の最良画像がfrontでなく、検出結果の信頼度が高い場合
174176
elif (best_minifig_result["best_direction"] != "front" and
175-
detection_result["confidence"] > best_minifig_result["best_confidence"]):
177+
detection_result["confidence"] >
178+
best_minifig_result["best_confidence"]):
176179
# それぞれの値を更新
177180
best_minifig_result["best_image_path"] = file_path
178-
best_minifig_result["best_confidence"] = detection_result["confidence"]
179-
best_minifig_result["best_direction"] = detection_result["direction"]
181+
best_minifig_result["best_confidence"] = (
182+
detection_result["confidence"])
183+
best_minifig_result["best_direction"] = (
184+
detection_result["direction"])
180185

181186
# 4枚未満の場合
182187
if best_minifig_result["image_count"] < 4:
183188
return JSONResponse(
184189
content={
185-
"message": f"Image {best_minifig_result['image_count']} processed successfully",
190+
"message": (f"Image {best_minifig_result['image_count']} "
191+
"processed successfully"),
186192
"detection_result": detection_result,
187193
"images_received": best_minifig_result["image_count"],
188-
"remaining": 4 - best_minifig_result["image_count"]
189-
},
190-
status_code=status.HTTP_200_OK
191-
)
194+
"remaining": 4 -
195+
best_minifig_result["image_count"]},
196+
status_code=status.HTTP_200_OK)
192197

193198
# アップロード対象画像を決定
194199
if best_minifig_result["best_image_path"]:

tests/mock_official_interface.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
"""テスト用の競技システムモック.
22
3-
@author: Claude
3+
@author: Hara1274
44
"""
55
import os
66

0 commit comments

Comments
 (0)