윤영준 윤영준 05-21
추론 서버 코드 작성
@894e2c82a5e882304376d0010aa150fbe071dd4e
config_files/cctv_list.csv (Renamed from config/cctv_list.csv)
--- config/cctv_list.csv
+++ config_files/cctv_list.csv
No changes
config_files/hls_streaming_config.py (Renamed from config/hls_streaming_config.py)
--- config/hls_streaming_config.py
+++ config_files/hls_streaming_config.py
No changes
config_files/yolo_config.py (Renamed from config/yolo_config.py)
--- config/yolo_config.py
+++ config_files/yolo_config.py
No changes
config_files/yolo_config.txt (Renamed from config/yolo_config.txt)
--- config/yolo_config.txt
+++ config_files/yolo_config.txt
No changes
hls_streaming/hls.py
--- hls_streaming/hls.py
+++ hls_streaming/hls.py
@@ -100,7 +100,7 @@
         header = {
             'Content-Type': f'image/{image_type}',
             'x-time-sent': time_sent,
-            'x-cctv-info': base64.b64encode(str(self.cctvid).encode('utf-8')).decode('ascii'),
+            'x-cctv-name': base64.b64encode(str(self.cctvid).encode('utf-8')).decode('ascii'),
             'x-cctv-latitude' : str(self.lat),
             'x-cctv-longitude' : str(self.lon),
         }
inference_endpoint.py
--- inference_endpoint.py
+++ inference_endpoint.py
@@ -1,3 +1,4 @@
+import numpy as np
 from flask import Flask, request
 from flask_restx import Api, Resource, fields
 import os
@@ -5,6 +6,7 @@
 from yoloseg.inference_ import Inference, overlay_mask
 import cv2
 import time
+import base64
 
 app = Flask(__name__)
 api = Api(app, version='1.0', title='CCTV Image Upload API',
@@ -14,7 +16,7 @@
 ns = api.namespace('cctv', description='CCTV operations')
 
 model_path = 'yoloseg/weight/best.onnx'
-classes_txt_file = 'config/yolo_config.txt'
+classes_txt_file = 'config_files/yolo_config.txt'
 image_path = 'yoloseg/img3.jpg'
 
 model_input_shape = (640, 640)
@@ -48,32 +50,27 @@
         if 'file' not in request.files:
             ns.abort(400, 'No image part in the request')
         image = request.files['file']
-        cctv_info = request.headers.get('x-cctv-info', '')
+        cctv_info = base64.b64decode(request.headers.get('x-cctv-name', '')).decode('UTF-8')
         time_sent = request.headers.get('x-time-sent', '')
         cctv_latitude = request.headers.get('x-cctv-latitude', 'Not provided')
         cctv_longitude = request.headers.get('x-cctv-longitude', 'Not provided')
 
         timestamp = datetime.now().strftime("%Y%m%d_%H%M%S")
-        image = cv2.imdecode(image)
+        image = image.read()
+        image = np.frombuffer(image, np.uint8)
+        image = cv2.imdecode(image, cv2.IMREAD_COLOR)
         filename = f"{timestamp}_{cctv_info}.png"
 
         t1 = time.time()
         detections, mask_maps = inference_engine.run_inference(image)
         t2 = time.time()
 
-        if mask_maps is not None:
+        print(t2 - t1)
+
+        if len(mask_maps) != 0:
             seg_image = overlay_mask(image, mask_maps[0], color=(0, 255, 0), alpha=0.3)
-
-        if image.filename == '':
-            ns.abort(400, 'No selected image')
-
-        # Use current timestamp to avoid filename conflicts
-        # image_path = os.path.join(IMAGE_DIR, filename)
-        # image.save(image_path)
 
         return {"message": f"Image {filename} uploaded successfully!"}
 
-    def send_result(self):
-        pass
 if __name__ == '__main__':
     app.run(debug=True, port=12345)
streaming_process.py
--- streaming_process.py
+++ streaming_process.py
@@ -25,7 +25,7 @@
 
     cctv_ind = args.cctv_num
 
-    cctv_info = pd.read_csv("config/cctv_list.csv")
+    cctv_info = pd.read_csv("config_files/cctv_list.csv")
     cctv_info = cctv_info.iloc[cctv_ind]
 
     lat = cctv_info["coordx"]
test.py
--- test.py
+++ test.py
@@ -35,7 +35,7 @@
         if 'file' not in request.files:
             ns.abort(400, 'No image part in the request')
         image = request.files['file']
-        cctv_info = base64.b64decode(request.headers.get('x-cctv-info', '')).decode('UTF-8')
+        cctv_info = base64.b64decode(request.headers.get('x-cctv-name', '')).decode('UTF-8')
         print(cctv_info)
         time_sent = request.headers.get('x-time-sent', '')
         cctv_latitude = request.headers.get('x-cctv-latitude', 'Not provided')
yoloseg/inference_.py
--- yoloseg/inference_.py
+++ yoloseg/inference_.py
@@ -1,7 +1,7 @@
 import cv2
 import numpy as np
 import random
-from config import CLASS_NAME, CLASS_NUM
+from config_files.yolo_config import CLASS_NAME, CLASS_NUM
 
 class Inference:
     def __init__(self, onnx_model_path, model_input_shape, classes_txt_file, run_with_cuda):
@@ -188,7 +188,7 @@
 
     # Path to your ONNX model and classes text file
     model_path = 'yoloseg/weight/best.onnx'
-    classes_txt_file = 'yoloseg/config/yolo_config.txt'
+    classes_txt_file = 'yoloseg/config_files/yolo_config.txt'
     image_path = 'yoloseg/img3.jpg'
 
     model_input_shape = (640, 640)
@@ -241,7 +241,7 @@
 
     # Path to your ONNX model and classes text file
     model_path = 'yoloseg/weight/best.onnx'
-    classes_txt_file = 'yoloseg/config/yolo_config.txt'
+    classes_txt_file = 'yoloseg/config_files/yolo_config.txt'
 
     model_input_shape = (640, 640)
     inference_engine = Inference(
Add a comment
List