Skip to content

Commit

Permalink
update: 1枚目のふぃぐ画像を推論する処理の追加
Browse files Browse the repository at this point in the history
  • Loading branch information
takahashitom committed Aug 27, 2024
1 parent 80e2cc8 commit 0916b95
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 4 deletions.
5 changes: 2 additions & 3 deletions src/detect_object.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,8 @@ class DetectObject():
__IMG_SIZE = (640, 480)

def __init__(self,
weights=YOLO_PATH/'learned_fig_weight_ver2.pt',
# weights=YOLO_PATH/'learned_fig_weight.pt',
label_data=YOLO_PATH/'fig_label.yaml',
weights=YOLO_PATH/'exp17_best.pt',
label_data=YOLO_PATH/'label_data.yaml',
conf_thres=0.6,
iou_thres=0.45,
max_det=10,
Expand Down
19 changes: 18 additions & 1 deletion src/server/flask_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,14 @@

from src.csv_to_json import CSVToJSONConverter
import os
import sys
import socket
import platform
from flask_cors import CORS

sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), '..')))
from detect_object import DetectObject

from flask import Flask, request, jsonify, send_file

app = Flask(__name__)
Expand Down Expand Up @@ -38,6 +42,18 @@ def get_image() -> jsonify:
# src/server/image_dataに、受信したファイルを保存する。
file_path = os.path.join(upload_folder, file_name)
file.save(file_path)

# 取得した画像が1枚目のふぃぐ画像である場合物体検出を行う
if file_name == 'Fig_1.jpeg':
d = DetectObject()
detected_img_path = os.path.join(upload_folder, "detected_"+file_name)

try:
objects = d.detect_object(img_path=file_path, save_path=detected_img_path)
except Exception:
print("Error: detect failed")
objects = []

return jsonify({"message": "File uploaded successfully"}), 200

# '/run-log'へのPOSTリクエストに対する操作
Expand Down Expand Up @@ -120,7 +136,8 @@ def send_run_log() -> jsonify:
else:
host = os.uname()[1]

if host == "KatLabLaptop":
# if host == "KatLabLaptop":
if host == "LAPTOP-UNI0BH6G": # 検証用
# ソケットを作成し、GoogleのDNSサーバ("8.8.8.8:80")
# に接続することで、IPアドレスを取得する。
# 参考: https://qiita.com/suzu12/items/b5c3d16aae55effb67c0
Expand Down

0 comments on commit 0916b95

Please sign in to comment.