윤영준 윤영준 05-16
Adding DB
@63739174e2cfaf9326095c5f8d9a41b3d9177868
 
DB/db.py (added)
+++ DB/db.py
@@ -0,0 +1,12 @@
+import psycopg2
+import json
+import requests
+import time
+
+
+async def get_cctv_info():
+    pass
+
+def setup_db():
+    pass
+
ITS/api.py
--- ITS/api.py
+++ ITS/api.py
@@ -66,6 +66,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")
     return all_data_df
 
 def get_jpeg(url):
@@ -77,6 +78,6 @@
 
 
 if __name__ == "__main__":
-    df = gather_cctv_list(129.28, 129.35, 35.999, 36.07, 1, 1)
+    df = gather_cctv_list(129.2, 129.3, 35.9, 36.07, 1, 1)
     pass
     # get_jpeg("http://cctvsec.ktict.co.kr:8090/74236/IM2NQs4/uHZcgnvJo3V/mjo3tswwgUj87kpcYZfR/BPxaQ4lk9agnl8ARIB9lhlgOD87VBx6RDHFl423kLkqHQ==")
(파일 끝에 줄바꿈 문자 없음)
hls_streaming/hls.py
--- hls_streaming/hls.py
+++ hls_streaming/hls.py
@@ -23,6 +23,7 @@
         self.buffer_duration = buffer_duration
         self.buffer_size = buffer_size
         self.frame_buffer = []
+        self.current_frame = []
         self.frame_buffer_lock = Lock() # for no memory sharing between receive_stream_packet and process_frames
         self.captured_frame_count = 0
         self.last_capture_time = 0
@@ -37,6 +38,9 @@
         self.cctvid = cctv_id
         self.time_zone = ZoneInfo(time_zone)
         self.endpoint = endpoint
+
+    def __call__(self, *args, **kwargs):
+        return self.current_frame
 
 
     # ```receive_stream_packet``` and ```process_frames``` work asynchronously (called with Thread)
@@ -61,10 +65,10 @@
                                 self.frame_buffer = self.frame_buffer[-self.buffer_size:]
                             buffered_frame = self.frame_buffer[-1]
                             # print(len(self.frame_buffer))
-                            img = buffered_frame.to_image()
-                            img = cv2.cvtColor(np.array(img), cv2.COLOR_RGB2BGR)
+                            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"
-                            img_binary = cv2.imencode('.png', img)
+                            img_binary = cv2.imencode('.png', self.current_frame)
                             self.send_image_to_server(img_binary, self.endpoint)
                             # cv2.imwrite(f'hls_streaming/captured_frame_/{datetime.now()}_{frame_name}', img)
                             self.last_capture_time = current_time
@@ -79,6 +83,8 @@
             'Content-Type': f'image/{image_type}',
             'x-time-sent': time_sent,
             'x-cctv-info': str(self.cctvid),
+            'x-cctv-latitude' : '',
+            'x-cctv-longitude' : '',
         }
         try:
             requests.post(endpoint, headers=header, files=image)
@@ -102,8 +108,7 @@
 # Example usage
 if __name__ == "__main__":
     capturer = FrameCapturer(
-        'http://cctvsec.ktict.co.kr/73496/'
-        '7xhDlyfDPK1AtaOUkAUDUJgZvfqvRXYYZUmRLxgPgKXk+eEtIJIfGkiC/gcQmysaz7zhDW2Jd8qhPCxgpo7cn5VqArnowyKjUePjdAmuQQ8=',
+        'http://cctvsec.ktict.co.kr/71187/bWDrL7fpStZDeDZgCybpJH8gagWJOynbaA/l91ExpmUPKzc3bCsHJtIblDkzG3Tff2tHy5NNkb6NtYTbie/jNQ0F+PnejViTbKHkpMWNGpc=',
         101, 10
     )
     t1 = time.time()
yoloseg/inference_.py
--- yoloseg/inference_.py
+++ yoloseg/inference_.py
@@ -48,8 +48,10 @@
         boxes = []
 
         for detection in outputs_bbox[0].T:
-            # when your weight is trained from pretrained weight, the resulting wieght
-            # may have leftover classes (that does nothing), hence this.
+            # This segmentation model uses yolact architecture to predict mask
+            # the output tensor dimension for yolo-v8-seg is B x [X, Y, W, H, C1, C2, ..., P1, ...,P32] * 8400
+            # where C{n} are confidence score for each class
+            # and P{n} are coefficient for each proto masks. (32 by default)
             scores_classification = detection[4:4+CLASS_NUM]
             scores_segmentation = detection[4+CLASS_NUM:]
             class_id = np.argmax(scores_classification, axis=0)
@@ -95,6 +97,12 @@
         for idx, det in enumerate(detections):
             box = det['box']
             x1, y1, w, h = box
+
+            #... why the model outputs ... negative values?...
+            if x1 <= 0 :
+                x1 = 0
+            if y1 <= 0 :
+                y1 = 0
             x1, y1, x2, y2 = x1, y1, x1 + w, y1 + h
 
             # To handle edge cases where you get bboxes that pass beyond the original image
@@ -175,10 +183,8 @@
     return cv2.addWeighted(src1=overlay, alpha=alpha, src2=image, beta=1 - alpha, gamma=0)
 
 
-
-def main():
+def test():
     import time
-
 
     # Path to your ONNX model and classes text file
     model_path = 'yoloseg/weight/best.onnx'
@@ -229,5 +235,50 @@
         cv2.waitKey(0)
         cv2.destroyAllWindows()
 
+def test2():
+    import time
+    import glob
+
+    # Path to your ONNX model and classes text file
+    model_path = 'yoloseg/weight/best.onnx'
+    classes_txt_file = 'yoloseg/config/classes.txt'
+
+    model_input_shape = (640, 640)
+    inference_engine = Inference(
+        onnx_model_path=model_path,
+        model_input_shape=model_input_shape,
+        classes_txt_file=classes_txt_file,
+        run_with_cuda=True
+    )
+
+    image_dir = glob.glob("/home/juni/사진/sample_data/ex1/*.png")
+
+    for iteration, image_path in enumerate(image_dir):
+        img = cv2.imread(image_path)
+        if img is None:
+            print("Error loading image")
+            return
+        img = cv2.resize(img, model_input_shape)
+        # Run inference
+        t1 = time.time()
+        detections, mask_maps = inference_engine.run_inference(img)
+        t2 = time.time()
+
+        print(t2-t1)
+
+        # Display results
+        for detection in detections:
+            x, y, w, h = detection['box']
+            class_name = detection['class_name']
+            confidence = detection['confidence']
+            cv2.rectangle(img, (x, y), (x+w, y+h), detection['color'], 2)
+            label = f"{class_name}: {confidence:.2f}"
+            cv2.putText(img, label, (x, y - 10), cv2.FONT_HERSHEY_SIMPLEX, 0.5, detection['color'], 2)
+
+        if len(mask_maps) > 0 :
+            seg_image = overlay_mask(img, mask_maps[0], color=(0, 255, 0), alpha=0.3)
+            cv2.imwrite(f"result/{iteration}.png", seg_image)
+
+
 if __name__ == "__main__":
-    main()
(파일 끝에 줄바꿈 문자 없음)
+    test2()
(파일 끝에 줄바꿈 문자 없음)
Add a comment
List