윤영준 윤영준 06-03
bug fix : mismatch in request file fields name causing postprocess_draft.py not reading segmented image
@ae76301f2f7396b39a4c8b4f61a163b3feef0a2c
ITS/api.py
--- ITS/api.py
+++ ITS/api.py
@@ -48,8 +48,6 @@
     :return: pandas DataFrame 형태로 반환
             주요 컬럼은 다음과 같음
             coordx	 coordy   cctvtype	cctvformat	 cctvname	cctvurl
-
-
     '''
     dotenv = load_dotenv()
     apiKey= os.getenv("ITS_API")
@@ -68,8 +66,14 @@
 
             url = create_url(apiKey, roadType, cctvType,
                              x, x_next, y, y_next)
-            response = requests.get(url)
+            try :
+                response = requests.get(url)
+            except :
+                df_temp = pd.DataFrame([x,x_next,y,y_next], columns=["x_min", "x_max", "y_min", "y_max"])
+                df_temp.to_csv(f"ITS/list/error/{x}_{x_next}_{y}_{y_next}.csv")
+                continue
             response_json = json.loads(response.text)
+            print(response)
             if response_json['response']['datacount'] == 1:
                 new_df = pd.json_normalize(response_json['response']['data'])
                 all_data_df = pd.concat([all_data_df, new_df], ignore_index=True)
@@ -80,7 +84,7 @@
                 # df.to_csv(f"result/pohang/listofcctv_포항_{x}_{y}.csv", index=False)
             time.sleep(1)
             print(f"{i}, {j}")
-    all_data_df.to_csv(f"result/{xmin}_{xmax}_y{ymin}_{ymax}.csv")
+    all_data_df.to_csv(f"ITS/list/{xmin}_{xmax}_y{ymin}_{ymax}.csv")
     return all_data_df
 
 def get_jpeg(url):
@@ -92,6 +96,6 @@
 
 
 if __name__ == "__main__":
-    df = gather_cctv_list(127.9, 128.3, 35.9, 36.07, 1, "its", 1)
+    df = gather_cctv_list(125, 130, 33, 39, 2, "ex", 1)
     pass
     # get_jpeg("http://cctvsec.ktict.co.kr:8090/74236/IM2NQs4/uHZcgnvJo3V/mjo3tswwgUj87kpcYZfR/BPxaQ4lk9agnl8ARIB9lhlgOD87VBx6RDHFl423kLkqHQ==")
(파일 끝에 줄바꿈 문자 없음)
 
ITS/api_list_gatherer.py (added)
+++ ITS/api_list_gatherer.py
@@ -0,0 +1,114 @@
+import requests
+import pandas as pd
+import numpy as np
+import os
+import json
+import time
+from dotenv import load_dotenv
+import cv2
+
+
+def create_url(apiKey, roadType, cctvType, minX, maxX, minY, maxY, getType="json",
+               baseurl="https://openapi.its.go.kr:9443/cctvInfo"):
+    '''
+    국가교통정보센터 api 예제 실행 코드, 더 자세한 내용은
+    https://www.its.go.kr/opendata/openApiEx?service=cctv 참고
+    :param apiKey: ``str`` 국가교통정보센터에서 발급받은 api 키
+    :param roadType: ``str`` 도로 유형 ('ex' : 고속도로, 'its' : 국도)
+    :param cctvType: ``int`` CCTV 유형 (1. 실시간 스트리밍(HLS) / 2. 동영상 파일(m3u8) / 3. 정지 영상(JPEG))
+    :param minX: 최소 경도 영역
+    :param maxX: 최대 경도 영역
+    :param minY: 최소 위도 영역
+    :param maxY: 최대 경도 영역
+    :param getType: 출력 결과 형식 ("xml" or "json")
+    :return: api 요청 url
+    '''
+    assert roadType != "ex" or "its", 'Error! roadType should be either "ex" or "its"'
+    assert cctvType != 1 or 2 or 3, 'Error! cctvType should be one of 1, 2, 3!'
+    assert getType != "json" or "xml", 'Error! gettype should be either "json" or "xml"!'
+    return (
+        f"{baseurl}?"
+        f"apiKey={apiKey}&"
+        f"type={roadType}&"
+        f"cctvType={cctvType}&"
+        f"minX={minX}&maxX={maxX}&minY={minY}&maxY={maxY}&"
+        f"getType={getType}"
+    )
+
+
+def gather_cctv_list(xmin, xmax, ymin, ymax, intervals, roadType, cctvType, depth=0, max_depth=5):
+    '''
+    :param minX: 최소 경도 영역
+    :param maxX: 최대 경도 영역
+    :param minY: 최소 위도 영역
+    :param maxY: 최대 경도 영역
+    :param intervals: api를 통해서 cctv 목록을 불러올때 위경도 격자 간격
+    :param roadType: ``str`` 도로 유형 ('ex' : 고속도로, 'its' : 국도)
+    :param cctvType: ``int`` CCTV 유형 (1. 실시간 스트리밍(HLS) / 2. 동영상 파일(m3u8) / 3. 정지 영상(JPEG))
+    :param depth: ``int`` 재귀적으로 불러온 함수의 깊이 (절대로 직접 넣지 말것.)
+    :param max_depth: ``int`` 재귀 함수 깊이 제한
+    :return: pandas DataFrame 형태로 반환
+            주요 컬럼은 다음과 같음
+            coordx	 coordy   cctvtype	cctvformat	 cctvname	cctvurl
+    '''
+    dotenv = load_dotenv()
+    apiKey = os.getenv("ITS_API")
+    x_values = np.linspace(xmin, xmax, intervals + 1)
+    y_values = np.linspace(ymin, ymax, intervals + 1)
+    all_data_df = pd.DataFrame()
+
+    if depth > max_depth:
+        return all_data_df  # Avoids excessive recursion depth
+
+    for i in range(len(x_values) - 1):
+        for j in range(len(y_values) - 1):
+            x = x_values[i]
+            y = y_values[j]
+            x_next = x_values[i + 1]
+            y_next = y_values[j + 1]
+
+            url = create_url(apiKey, roadType, cctvType, x, x_next, y, y_next)
+            try:
+                response = requests.get(url)
+                response_json = json.loads(response.text)
+                if response_json['response']['datacount'] == 0:
+                    continue
+                new_df = pd.json_normalize(response_json['response']['data'])
+                all_data_df = pd.concat([all_data_df, new_df], ignore_index=True)
+                print(f"x: {i}, y: {j}, d: {depth}")
+            except Exception as e:
+                # Splitting the area into four if an exception occurs (likely due to too many entries)
+                if depth < max_depth:
+                    mid_x = (x + x_next) / 2
+                    mid_y = (y + y_next) / 2
+                    all_data_df = pd.concat([
+                        all_data_df,
+                        gather_cctv_list(x, mid_x, y, mid_y, intervals, roadType, cctvType, depth + 1, max_depth),
+                        gather_cctv_list(mid_x, x_next, y, mid_y, intervals, roadType, cctvType, depth + 1, max_depth),
+                        gather_cctv_list(x, mid_x, mid_y, y_next, intervals, roadType, cctvType, depth + 1, max_depth),
+                        gather_cctv_list(mid_x, x_next, mid_y, y_next, intervals, roadType, cctvType, depth + 1, max_depth)
+                    ], ignore_index=True)
+            time.sleep(1)  # To prevent hitting the API rate limit
+    return all_data_df
+
+
+if __name__ == "__main__":
+    list2= [
+        [129.37762, 36.318485, 'its'],
+        [129.381293, 36.339985, 'its'],
+        [129.3459, 36.11983, 'its'],
+        [129.200930555555, 35.772125, 'its'],
+        [129.347244, 36.286135, 'its'],
+        [128.03166, 36.011665, 'its'],
+        [128.840556, 35.384722, 'ex']
+    ]
+    delta = 0.01
+    all_data_df = pd.DataFrame()
+    for i in list2:
+        x = i[0]
+        y = i[1]
+        ty = i[2]
+        df = gather_cctv_list(x-delta,x+delta, y-delta, y+delta, 1, ty, 1)
+        all_data_df = pd.concat((all_data_df,df), ignore_index=True)
+    # df = gather_cctv_list(127, 130, 33, 39, 8, "its", 1)
+    all_data_df.to_csv("cctv_data.csv")(파일 끝에 줄바꿈 문자 없음)
config_files/cctv_list.csv
--- config_files/cctv_list.csv
+++ config_files/cctv_list.csv
@@ -2,4 +2,11 @@
 ,129.245312,35.920346,,,1,HLS,[국도 7호선] 모아초교,http://cctvsec.ktict.co.kr/4463/6SqphQj32sxeB2nYIMerulhkk0HdDKP/aSEgp7hHbUY9iwTDb+UQZfTbag9pXmM/yo3a7l1usm64GwBH77/SCVEel3JF3g9BZDc+ws1es2w=
 ,129.2005,35.921825,,,1,HLS,[국도20호선] 검단산업단지,http://cctvsec.ktict.co.kr/71187/bWDrL7fpStZDeDZgCybpJH8gagWJOynbaA/l91ExpmUPKzc3bCsHJtIblDkzG3TfmkwkLj7+PPdYAHSYBXxem4SZJpaAYFU0CtDtr5rz7DY=
 ,128.06396,36.047108,,,1,HLS,[국도3호선] 송죽교차로,http://cctvsec.ktict.co.kr/71208/Z9Acztz6CYwzuUXQFreRR0Kdewba8Ml4CNxR0Jsp9uSCWmvL9W/BO1w2XIPxtxs9kn58qVvtHREs6vU305JaRa40F1m/P6f13gpiz9C+46M=
-,128.2671,35.91457,,,1,HLS,[국도33호선] 대흥교차로,http://cctvsec.ktict.co.kr/72593/mTZfGWopuLSKGZsBABx2whdCW4FLmBl6wi4dCvp0MxMpKF6c6ydtf40G8dVXQcAGlDug1DIE/E4MVUyoa3UuD18aYxP6ZCMD5zISEiDxXTQ=
(파일 끝에 줄바꿈 문자 없음)
+,128.2671,35.91457,,,1,HLS,[국도33호선] 대흥교차로,http://cctvsec.ktict.co.kr/72593/mTZfGWopuLSKGZsBABx2whdCW4FLmBl6wi4dCvp0MxMpKF6c6ydtf40G8dVXQcAGlDug1DIE/E4MVUyoa3UuD18aYxP6ZCMD5zISEiDxXTQ=
+,129.378721,36.310334,,,1,HLS,[국도 7호선] 영덕 구계휴게소,http://cctvsec.ktict.co.kr/4459/kAgktFah0VAtMosKMfrJ13d7CBLAa5+M1xhiLgsypRh5NDDIqY0Y7Z2+hkF88PZUhL1uFJTYshn/Afc4FCS67iWpGfxUOoNU8b0ul3flW8c=
+,129.37762,36.318485,,,1,HLS,"[국도7호선] 영덕 영덕구계항부근(마을주민,해안가)",http://cctvsec.ktict.co.kr/72957/LkVa3bIbXIBudmzokRTyNtAbqEoZCk+DHRZ8i6cs+rL6QIEM7Fv1N+wfJPjSFQOEmn+Sklz5M3zqnjyiuo6lcPORJsjpyig6wn11ZeH+h44=
+,129.381293,36.339985,,,1,HLS,[국도 7호선] 오션뷰C.C 앞 삼거리,http://cctvsec.ktict.co.kr/4475/0lZW6kXydguhfnjHZgPeVWi/UKIYrPrUGPfVDyXcGXynS/XFEaXHTYGgmLHdj6QwF1AcHSd6JRZnW+/Ecw30OL/L63URGEp3X/DJqKRrzR0=
+,129.3459,36.11983,,,1,HLS,[국도7호선] 곡강교,http://cctvsec.ktict.co.kr/71249/YZj8q/z+rpoz8wHUZGst7oMp01rLXrsqhKDnbcKcndono98hK4v5LXE3UumA35GOUC3vxTXsvCBdemtPt60aNJsGUbr+NNiMFUZXDoNutF8=
+,129.193728,35.762614,,,1,HLS,[국도7호선] 부지교차로,http://cctvsec.ktict.co.kr/72311/kdgcZLCWMjfPL2B06+sReFWMMB+6gW6i1XePhxb0jT/S3jhoQGFbl4nM8fnNunVxbfcv+gtwwve5/Alut8ExIXo8I9h3kV5tNjcqr2ai8d4=
+,129.200930555555,35.772125,,,1,HLS,[국도 35호선] 용장교,http://cctvsec.ktict.co.kr/5569/7Wk7xI0iDot4My7wDolq5X3jnW9Pgsp7eqT4fmbF1G1dWh248yZuO0r6DZGPJc0lFupmPdL6nCMDyuYljTRHmm7FxLfEMZ9OOKcycSLyHIk=
+,128.03166,36.011665,,,1,HLS,[국도3호선] 방산교,http://cctvsec.ktict.co.kr/72618/tJq3wZnEySy1HdQLbvzJhD6i+QrqP0HIopbzDMD/h21V/QmMVP26YJUOZsU9WnMsSrPMHfzgTP54irzJjPv+4kCcFJuqvRM63JNFmolU2tE=
inference_endpoint.py
--- inference_endpoint.py
+++ inference_endpoint.py
@@ -103,7 +103,6 @@
             self.flag_detected = False
 
         if self.flag_detected:
-            print(image.shape)
             print(self.mask.shape)
             self.mask = cv2.resize(self.mask, (self.image.shape[1], self.image.shape[0])) # cv2 saves image with w,h order
             self.mask = self.mask[..., np.newaxis]
@@ -151,7 +150,7 @@
                         #     self.mask_blob,
                         #     f'image/{self.image_type}'
                         # ),
-                        'seg_mask' : (
+                        'seg_image' : (
                             f'frame_seg_{self.cctv_name}.{self.image_type}',
                             seg_binary,
                             f'image/{self.image_type}'
postprocess_draft.py
--- postprocess_draft.py
+++ postprocess_draft.py
@@ -226,7 +226,7 @@
 
 memory = StreamSources(
             buffer_size=15,
-            normal_send_interval=1,
+            normal_send_interval=10,
             failure_mode_thres=8,
             failure_mode_check_past_n=12,
             normal_mode_thres=8,
@@ -297,8 +297,8 @@
 
         if self.detected:
             try:
-                self.mask = request.files['mask'].read()
-                self.seg_image = request.files['seg_image'].read()
+                # self.mask = request.files['mask'].read()
+                self.seg_image = request.files['seg_image']
             except:
                 raise ValueError("Error reading 'mask' and 'seg_mask'")
 
run_image_anal_backend.sh
--- run_image_anal_backend.sh
+++ run_image_anal_backend.sh
@@ -8,8 +8,24 @@
 # Start multiple Python processes in the background
 python streaming_process.py --cctv_num 0 &
 pids+=($!)
+sleep 1
 python streaming_process.py --cctv_num 1 &
 pids+=($!)
+sleep 1
+python streaming_process.py --cctv_num 2 &
+pids+=($!)
+sleep 1
+python streaming_process.py --cctv_num 3 &
+pids+=($!)
+sleep 1
+python streaming_process.py --cctv_num 4 &
+pids+=($!)
+sleep 1
+python streaming_process.py --cctv_num 5 &
+pids+=($!)
+sleep 1
+python streaming_process.py --cctv_num 6 &
+pids+=($!)
 
 #python test.py
 python inference_endpoint.py
 
setup.py (added)
+++ setup.py
@@ -0,0 +1,23 @@
+from setuptools import setup
+
+setup(
+    name='flood_server',
+    version='0.9',
+    packages=[''],
+    install_requires=[
+        'opencv-python',
+        'pandas',
+        'numpy',
+        'python-dotenv',
+        'flask',
+        'flask-restx',
+        'pyav',
+        'requests-toolbelt',
+        'onnxrunntime-gpu',
+    ],
+    url='',
+    license='',
+    author='takensoft-Yoon-Young-Joon',
+    author_email='[email protected]',
+    description='',
+)
streaming_process.py
--- streaming_process.py
+++ streaming_process.py
@@ -11,7 +11,7 @@
     import time
 
 
-    def refresh_hls_address(lat, lon, lat_lon_interval=0.000001):
+    def refresh_hls_address(lat, lon, lat_lon_interval=0.0001):
         api_result = gather_cctv_list(
             xmin=lat - lat_lon_interval, ymin=lon - lat_lon_interval,
             xmax=lat + lat_lon_interval, ymax=lon + lat_lon_interval,
yoloseg/inference_gpu_.py
--- yoloseg/inference_gpu_.py
+++ yoloseg/inference_gpu_.py
@@ -4,7 +4,7 @@
 import numpy as np
 import random
 import onnxruntime as ort
-from config_files.yolo_config import CLASS_NAME, CLASS_NUM
+from config_files.yolo_config import CLASS_NUM
 from typing import List, Tuple
 
 
Add a comment
List