Notice
Recent Posts
Recent Comments
Link
| 일 | 월 | 화 | 수 | 목 | 금 | 토 |
|---|---|---|---|---|---|---|
| 1 | 2 | 3 | 4 | |||
| 5 | 6 | 7 | 8 | 9 | 10 | 11 |
| 12 | 13 | 14 | 15 | 16 | 17 | 18 |
| 19 | 20 | 21 | 22 | 23 | 24 | 25 |
| 26 | 27 | 28 | 29 | 30 |
Tags
- 총과 카드만들기
- sqld
- %in%
- Sum
- if문 작성법
- 히스토그램 그리기
- max
- 빅데이터
- 회귀분석 알고리즘
- 팀스파르타
- 막대그래프
- 데이터분석
- 빅데이터분석
- difftime
- Intersect
- 데이터분석가
- 불순도제거
- 정보획득량
- 회귀분석
- sql
- 그래프시각화
- count
- 그래프 생성 문법
- loop 문
- 상관관계
- merge
- 순위출력
- Dense_Rank
- 단순회귀 분석
- 여러 데이터 검색
Archives
- Today
- Total
ch0nny_log
[빅데이터분석] 딥러닝_22. 영상판독기 본문
데이터관련 교육 카페 | [우리팀 딥러닝 프로젝트 상용화 하기2] 우리팀 아이디어를 유료 제품화하기 ! - Daum 카페
Daum 카페
cafe.daum.net
!pip install deepface
!pip install ultralytics
import cv2
import tkinter as tk
from PIL import Image, ImageTk
import threading
from ultralytics import YOLO
# YOLO 모델 로드
model = YOLO('yolov8n.pt')
# tkinter 윈도우 설정
root = tk.Tk()
root.title("YOLOv8 실시간 사람 검출")
# 웹캠 캡처 설정
cap = cv2.VideoCapture(0)
# 사물 검출 상태를 저장하는 변수
detecting = False
# 웹캠 프레임을 업데이트하고 사람 검출하는 함수
def update_frame():
global detecting
ret, frame = cap.read()
if ret:
if detecting:
# YOLO 모델로 사람 검출
results = model(frame)
for result in results:
boxes = result.boxes.cpu().numpy()
for box in boxes:
# 검출된 객체가 사람일 경우에만 표시 (label이 'person'인 경우)
if int(box.cls[0]) == 0: # 0은 'person' 클래스 번호
x1, y1, x2, y2 = map(int, box.xyxy[0])
label = result.names[int(box.cls[0])] # 클래스 ID를 이름으로 변환
# 사람 텍스트와 사각형 박스를 그리기
cv2.rectangle(frame, (x1, y1), (x2, y2), (0, 255, 0), 2)
cv2.putText(frame, label, (x1, y1 - 10), cv2.FONT_HERSHEY_SIMPLEX, 0.5, (0, 255, 0), 2)
# OpenCV 이미지를 PIL 이미지로 변환
img = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)
img = Image.fromarray(img)
imgtk = ImageTk.PhotoImage(image=img)
# 레이블에 이미지 업데이트
video_label.imgtk = imgtk
video_label.configure(image=imgtk)
video_label.after(10, update_frame)
# 사물 검출 시작 및 중지 함수
def toggle_detection():
global detecting
detecting = not detecting
if detecting:
detection_button.config(text="사물 검출 중지")
print("사물 검출 시작")
else:
detection_button.config(text="사물 검출 시작")
print("사물 검출 중지")
# 비디오 레이블 설정
video_label = tk.Label(root)
video_label.pack()
# 사물 검출 버튼 설정
detection_button = tk.Button(root, text="사물 검출 시작", command=toggle_detection)
detection_button.pack(padx=10, pady=10)
# 프레임 업데이트 시작
update_frame()
# tkinter 윈도우 실행
root.mainloop()
# 프로그램 종료 시 웹캠 해제
cap.release()
홈런을 부르는 타격폼, 인공지능은 알고있다
1. 아래의 코드를 메모장에 .py 파일로 저장
import av
import cv2
import streamlit as st
from streamlit_webrtc import webrtc_streamer
from ultralytics import YOLO
# 사용자 제공 모델 파일 경로 설정
model_path = 'hitter_trained_model.pt'
# YOLO 모델 로드
model = YOLO(model_path)
st.title("Real-Time Batter Recognition with YOLOv8 and WebRTC")
# 프레임 처리 콜백 함수
def video_frame_callback(frame):
img = frame.to_ndarray(format="bgr24")
# YOLO 모델을 사용하여 타자 감지 수행
results = model(img)
# 결과에서 각 타자의 바운딩 박스를 그립니다
for result in results[0].boxes:
x1, y1, x2, y2 = map(int, result.xyxy[0]) # 바운딩 박스 좌표
label = result.cls[0] # 클래스 라벨 (타자 이름)
confidence = result.conf[0] # 신뢰도 점수
# 클래스 이름 얻기 (타자 이름)
class_name = model.names[int(label)]
# 특정 타자일 경우 또는 높은 신뢰도일 경우 바운딩 박스와 라벨 그리기
if confidence > 0.5:
cv2.rectangle(img, (x1, y1), (x2, y2), (0, 255, 0), 2)
cv2.putText(img, f"{class_name} {confidence:.2f}", (x1, y1 - 10), cv2.FONT_HERSHEY_SIMPLEX, 0.5, (0, 255, 0), 2)
# BGR에서 RGB로 변환 (Streamlit에서 이미지를 표시하기 위해)
img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)
return av.VideoFrame.from_ndarray(img, format="rgb24")
# WebRTC 스트리밍 시작
webrtc_streamer(key="example", video_frame_callback=video_frame_callback)
2. c드라이브 data 파일에 넣기
hitter_trained_model.pt
5.95MB
실시간 영상 사물검출하는 영상판독기 만들기 | Notion
◾웹캠 사용하여 실시간 영상 출력하는 인터페이스 만들기
aluminum-magpie-a29.notion.site
우리팀 아이디어를 유료화하기 (영상판독기) | Notion
우리팀 아이디어를 유료화하기 위한 제품화 1단계 - 실시간 영상속 사물검출하여
gabby-nurse-0c2.notion.site