From 826d4cbfef35b0974274b892a8be774613e2e7c0 Mon Sep 17 00:00:00 2001 From: sukkyun2 Date: Thu, 22 Aug 2024 16:53:50 +0900 Subject: [PATCH] =?UTF-8?q?chore:=20=EB=AF=B8=EC=82=AC=EC=9A=A9=20?= =?UTF-8?q?=ED=8C=8C=EC=9D=BC=20=EC=82=AD=EC=A0=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- model/llm_api.py | 43 ------- ...lov8(detecton_deepsort_pose_estimation).py | 106 ------------------ 2 files changed, 149 deletions(-) delete mode 100644 model/llm_api.py delete mode 100644 model/yolov8(detecton_deepsort_pose_estimation).py diff --git a/model/llm_api.py b/model/llm_api.py deleted file mode 100644 index 72f7ec4..0000000 --- a/model/llm_api.py +++ /dev/null @@ -1,43 +0,0 @@ -import boto3 -import google.generativeai as genai - -s3 = boto3.client('s3') - -GOOGLE_API_KEY = "secret_key" -genai.configure(api_key=GOOGLE_API_KEY) -model = genai.GenerativeModel('gemini-1.5-pro') - - -def get_listall_from_aws(bucket_name): - paginator = s3.get_paginator('list_objects_v2') - page_iterator = paginator.paginate(Bucket=bucket_name) - temp_list = [] - - for page in page_iterator: - if 'Contents' in page: - for obj in page['Contents']: - file_key = obj['Key'] - file_url = f"https://{bucket_name}.s3.amazonaws.com/{file_key}" - temp_list.append(f"File: {file_key}, URL: {file_url}") - - return temp_list - - -def call_gemini(img, pram_list): - temp_list = [] - class_count = {} - - for detection in pram_list: - class_name = detection.class_name - if class_name in class_count: - class_count[class_name] += 1 - else: - class_count[class_name] = 1 - - new_class_name = f"{class_name}{class_count[class_name]}" - temp_list.append(new_class_name) - - response = model.generate_content( - (img, "이 이미지에 대하여, 다음 object list의 요소 간 관계를 중심으로 어떤 안전사고가 예상되는 상황인지 판단하고 위험 상황의 긴급도를 1~10 사이의 값으로 분류해." + str(temp_list))) - - return response.text diff --git a/model/yolov8(detecton_deepsort_pose_estimation).py b/model/yolov8(detecton_deepsort_pose_estimation).py deleted file mode 100644 index 2aebf41..0000000 --- a/model/yolov8(detecton_deepsort_pose_estimation).py +++ /dev/null @@ -1,106 +0,0 @@ -import cv2 -from ultralytics import YOLO -from deep_sort_realtime import deepsort_tracker - -model = YOLO('yolov8n-pose.pt') - -tracker = deepsort_tracker.DeepSort() - -POSE_CONNECTIONS = [ - (0, 1), (0, 2), (1, 3), (2, 4), # 머가리 - (5, 6), (5, 7), (7, 9), (6, 8), (8, 10), # 팔 - (11, 12), (11, 13), (13, 15), (12, 14), (14, 16), # 다리 - (5, 11), (6, 12) # 몸통 -] - -KEYPOINT_NAMES = [ - "nose", "left_eye", "right_eye", "left_ear", "right_ear", - "left_shoulder", "right_shoulder", "left_elbow", "right_elbow", "left_wrist", "right_wrist", - "left_hip", "right_hip", "left_knee", "right_knee", "left_ankle", "right_ankle" -] - - -def draw_keypoints_and_connections(frame, keypoints): - for person_kpts in keypoints: - # 키포인트 그리기 - for x, y in person_kpts: - if x > 0 and y > 0: # 유효한 키포인트만 - cv2.circle(frame, (int(x), int(y)), 5, (255, 0, 0), -1) - - # 연결선 그리기 - for connection in POSE_CONNECTIONS: - start_idx, end_idx = connection - start_point = tuple(map(int, person_kpts[start_idx])) - end_point = tuple(map(int, person_kpts[end_idx])) - if all(p > 0 for p in start_point + end_point): # 키포인트 둘 다 유효할 때만 선 연결 - cv2.line(frame, start_point, end_point, (0, 255, 0), 2) - - -def print_keypoints(track_id, keypoints): - print(f"\nPerson ID: {track_id}") - for i, (x, y) in enumerate(keypoints): - if x > 0 and y > 0: - print(f" {KEYPOINT_NAMES[i]:<15}: ({x:.2f}, {y:.2f})") - - -def process_frame(frame): - results = model(frame, conf=0.5) - - detections = [] - keypoints_list = [] - for r in results[0]: # results[0]에 한 프레임 모든 detection 결과 담김 - box = r.boxes.xyxy[0].cpu().numpy().astype(int) - conf = r.boxes.conf[0].cpu().numpy() - kpts = r.keypoints.xy[0].cpu().numpy() if r.keypoints else None - - detections.append(([box[0], box[1], box[2] - box[0], box[3] - box[1]], conf, 0)) - if kpts is not None: - keypoints_list.append(kpts) - - tracks = tracker.update_tracks(detections, frame=frame) - - for track, kpts in zip(tracks, keypoints_list): - if not track.is_confirmed(): - continue - track_id = track.track_id - ltrb = track.to_ltrb() - - cv2.rectangle(frame, (int(ltrb[0]), int(ltrb[1])), (int(ltrb[2]), int(ltrb[3])), (0, 255, 0), 2) - cv2.putText(frame, f"ID: {track_id}", (int(ltrb[0]), int(ltrb[1]) - 10), cv2.FONT_HERSHEY_SIMPLEX, 0.5, - (0, 255, 0), 2) - - print_keypoints(track_id, kpts) - - if keypoints_list: - draw_keypoints_and_connections(frame, keypoints_list) - - return frame - - - -def main(): - source = input("input 'webcam' or mp4 path: ") - - if source.lower() == 'webcam': - cap = cv2.VideoCapture(0) - else: - cap = cv2.VideoCapture(source) - - while True: - ret, frame = cap.read() - if not ret: - break - - frame = process_frame(frame) - - cv2.imshow('Output', frame) - - if cv2.waitKey(1) & 0xFF == ord('q'): - break - - cap.release() - cv2.destroyAllWindows() - - -if __name__ == "__main__": - main()