윤영준 윤영준 05-20
CWD 관련 파일 위치 변경...
@22f1c8f81c0909c4dde00064de451a4cdaa926e2
hls_streaming/hls.py
--- hls_streaming/hls.py
+++ hls_streaming/hls.py
@@ -9,6 +9,7 @@
 from threading import Lock, Thread, Event
 
 
+
 class FrameCapturer:
     def __init__(
             self,
@@ -46,7 +47,7 @@
         self.video_stream = next(s for s in self.input_stream.streams if s.type == 'video')
         self.fps = self.video_stream.guessed_rate.numerator
         self.capture_interval = 1 / self.fps
-
+        print(cctv_name)
         self.cctvid = cctv_name
         self.time_zone = ZoneInfo(time_zone)
         self.endpoint = endpoint
@@ -82,13 +83,13 @@
                             # print(len(self.frame_buffer))
                             self.current_frame = buffered_frame.to_image()
                             self.current_frame = cv2.cvtColor(np.array(self.current_frame), cv2.COLOR_RGB2BGR)
-                            frame_name = f"captured_frame_{self.captured_frame_count}.jpg"
+                            frame_name = f"captured_frame_{self.cctvid}_{self.captured_frame_count}.png"
                             img_binary = cv2.imencode('.png', self.current_frame)
                             img_binary = img_binary[1].tobytes()
                             self.send_image_to_server(img_binary)
-                            cv2.imwrite(f'hls_streaming/captured_frame_/{datetime.now()}_{frame_name}', self.current_frame)
+                            cv2.imwrite(f'hls_streaming/captured_frame_/{self.cctvid}_{datetime.now()}_{frame_name}', self.current_frame)
                             self.last_capture_time = current_time
-                            print(f"Captured {frame_name} at time: {current_time - self.start_time:.2f}s")
+                            print(f"Captured {frame_name} of {self.cctvid} at time: {current_time - self.start_time:.2f}s")
                             self.captured_frame_count +=1
 
             time.sleep(0.1)
@@ -99,8 +100,8 @@
             'Content-Type': f'image/{image_type}',
             'x-time-sent': time_sent,
             'x-cctv-info': str(self.cctvid),
-            'x-cctv-latitude' : self.lat,
-            'x-cctv-longitude' : self.lon,
+            'x-cctv-latitude' : str(self.lat),
+            'x-cctv-longitude' : str(self.lon),
         }
         session = requests.Session()
         try:
@@ -132,20 +133,20 @@
         self.input_stream.close()
 
 
-# Example usage
-if __name__ == "__main__":
-    capturer = FrameCapturer(
-        'http://cctvsec.ktict.co.kr/5545/LFkDslDT81tcSYh3G4306+mcGlLb3yShF9rx2vcPfltwUL4+I950kcBlD15uWm6K0cKCtAMlxsIptMkCDo5lGQiLlARP+SyUloz8vIMNB18=',
-        101, 10, 5
-    )
-    t1 = time.time()
-    try:
-        capturer.start()
-        time.sleep(600000)
-    finally:
-        capturer.stop()
-        del capturer
-        t2 = time.time()
-        with open("result.txt", "w") as file:
-            file.write(f'{t2-t1} seconds before terminating')
-        exit()
+# # Example usage
+# if __name__ == "__main__":
+#     capturer = FrameCapturer(
+#         'http://cctvsec.ktict.co.kr/5545/LFkDslDT81tcSYh3G4306+mcGlLb3yShF9rx2vcPfltwUL4+I950kcBlD15uWm6K0cKCtAMlxsIptMkCDo5lGQiLlARP+SyUloz8vIMNB18=',
+#         101, 10, 5
+#     )
+#     t1 = time.time()
+#     try:
+#         capturer.start()
+#         time.sleep(600000)
+#     finally:
+#         capturer.stop()
+#         del capturer
+#         t2 = time.time()
+#         with open("result.txt", "w") as file:
+#             file.write(f'{t2-t1} seconds before terminating')
+#         exit()
run_image_anal_backend.sh
--- run_image_anal_backend.sh
+++ run_image_anal_backend.sh
@@ -6,9 +6,9 @@
 PYTHONPATH="/home/juni/PycharmProjects/segmentation_overlapping"
 
 # Start multiple Python processes in the background
-python hls_streaming/hls.py --cctv_num 0 &
+python streaming_process.py --cctv_num 0 &
 pids+=($!)
-python hls_streaming/hls.py --cctv_num 1 &
+python streaming_process.py --cctv_num 1 &
 pids+=($!)
 
 python test.py
streaming_process.py (Renamed from hls_streaming/streaming_process.py)
--- hls_streaming/streaming_process.py
+++ streaming_process.py
@@ -3,13 +3,6 @@
 # This is by design, and is a way to circumvent GIL of python, because the server needs to handle multiple video streaming at once.
 
 if __name__ == "__main__":
-    from dotenv import load_dotenv
-    import os
-
-    load_dotenv()
-    # print("PYTHONPATH:", os.getenv("PYTHONPATH"))
-    # print("_____")
-    # print(os.path.dirname(os.path.abspath(__file__)))
     from ITS.api import gather_cctv_list
     from hls_streaming.hls import FrameCapturer
 
@@ -33,7 +26,7 @@
     cctv_ind = args.cctv_num
 
     cctv_info = pd.read_csv("config/cctv_list.csv")
-    cctv_info = cctv_info.iloc[0]
+    cctv_info = cctv_info.iloc[cctv_ind]
 
     lat = cctv_info["coordx"]
     lon = cctv_info["coordy"]
@@ -47,6 +40,7 @@
     while True:
 
         cctv_url = refresh_hls_address(lat, lon, )
+        print(name)
         hls_streaming = FrameCapturer(cctv_url, name, lat, lon, 5, 15, 300, "Asia/Seoul",
                                       endpoint= "http://localhost:12345/cctv/infer")
         hls_streaming.start()
test.py
--- test.py
+++ test.py
@@ -2,7 +2,7 @@
 from flask_restx import Api, Resource, fields
 import os
 from datetime import datetime
-from yoloseg.inference_ import Inference
+# from yoloseg.inference_ import Inference
 
 app = Flask(__name__)
 api = Api(app, version='1.0', title='CCTV Image Upload API',
@@ -35,6 +35,7 @@
             ns.abort(400, 'No image part in the request')
         image = request.files['file']
         cctv_info = request.headers.get('x-cctv-info', '')
+        print(cctv_info)
         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')
Add a comment
List