일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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
- react #리액트 #동빈나
- css #생활코딩 #웹
- 자바 #java
- 프로그래머스 #파이썬 #코딩테스트 #알고리즘
- 투포인터
- java #자바 #생활코딩
- 알고리즘
- react #리액트 #동빈나 #나동빈 #유튜브강의
- 다이나믹프로그래밍
- BFS
- 파이썬
- 파이썬 #백준 #알고리즘 #코딩테스트
- 백트랙킹
- 다익스트라
- 재귀
- 프로그래머스 #파이썬 #알고리즘 #코딩테스트
- 파이썬 #알고리즘 #코딩테스트 #프로그래머스
- DFS
- PYTHON
- css #웹 #생활코딩
- java #자바
- java #자바 #동빈나
- 백준 #알고리즘 #파이썬 #코딩테스트
- 프로그래머스
- Dijkstra
- 코딩테스트
- dp
- 백준
- 백준 #파이썬 #알고리즘 #코딩테스트
- java #자바 #나동빈
Archives
- Today
- Total
커리까지
농구영상 득점 자동 판별기 만들기 02 본문
728x90
SMALL
가상환경 만들고 다시 설정
- 외부모니터랑 같이 사용중이라gpu가 안 잡히는 거 일수도 있어서 그냥 노트북으로 다시 시도
- 후....외부 eGPU를 사려고 했지만 노트북이 썬더볼트를 지원하지 않아서 포기하였다....ㅠㅠ 이것도 안 되면 가상환경 지원해주는 곳에서 해보려구 한다.
- 아니면 msi노브툭을 구매해볼까 하는 작은 꿈을 꾼다....
- 똑같이 gpu그래픽부터 다시 설치하였다.
- 그리고 이번에는 가상환경을 설치하였다.
- 아나콘다 프롬포트를 관리자 권한으로 실행하였다.
(base) C:\Windows\system32>conda create --name deep
- 가상환경 이름을 deep으로 주었다.
(base) C:\Windows\system32>conda activate deep
- 가상환경을 실행하였다.
(deep) C:\Windows\system32>conda install tensorflow-gpu==1.12
- 텐서플로우를 설치하였다.
(deep) C:\Windows\system32>conda install jupyter notebook
- 주피터 노트북을 설치하였다.
(deep) C:\Windows\system32>conda install pandas
(deep) C:\Windows\system32>conda install numpy
- 판다스랑 넘파이도 설치해준다.
- 흐어어어어어엉 ㅠㅠ 드디어 gpu가 잡힌다. 외부모니터만 해제하면 잡히는걸 다른거 깔고 지우고 다른 길로 돌아 돌아 갔다.
darkflow에 필요한 패키지 conda 설치
conda install matplotlib
conda install -c conda-forge opencv
conda install cython
conda install -c hellock icrawler
pip install opencv-python
conda install -c conda-forge tensorflow=1.14
conda install -c anaconda tensorflow-gpu=1.14
구동성공
- 드디어 gpu로 구동하였다. 역시 cpu보다 빠르다. 그러나 gpu사양이 그렇게 좋은건 아니라서 정상적인 속도는 아니지만 그래도 만족한다.
- 이게 실시간으로 보면 느려져서 차리리 저장하였다. 그랬더니 원래 속도로 결과를 보여준다.
import cv2
from darkflow.net.build import TFNet
import numpy as np
import time
options = {
'model': 'cfg/yolo.cfg',
'load': 'bin/yolo.weights',
'threshold': 0.2,
'gpu': 1.0
}
tfnet = TFNet(options)
colors = [tuple(255 * np.random.rand(3)) for _ in range(10)]
# capture = cv2.VideoCapture(0)
capture = cv2.VideoCapture('nba_sample.mp4')
capture.set(cv2.CAP_PROP_FRAME_WIDTH,1280)
capture.set(cv2.CAP_PROP_FRAME_HEIGHT, 720)
# capture.set(cv2.CAP_PROP_FPS, int(60))
width = capture.get(cv2.CAP_PROP_FRAME_WIDTH)
height = capture.get(cv2.CAP_PROP_FRAME_HEIGHT)
fourcc = cv2.VideoWriter_fourcc(*'DIVX')
out = cv2.VideoWriter('output.avi', fourcc, 30.0, (int(width), int(height)))
while True:
stime = time.time()
ret, frame = capture.read()
if ret:
results = tfnet.return_predict(frame)
for color, result in zip(colors, results):
tl = (result['topleft']['x'], result['topleft']['y'])
br = (result['bottomright']['x'], result['bottomright']['y'])
label = result['label']
confidence = result['confidence']
text = '{}: {:.0f}%'.format(label, confidence * 100)
frame = cv2.rectangle(frame, tl, br, color, 2)
frame = cv2.putText(
frame, text, tl, cv2.FONT_HERSHEY_COMPLEX, 1, (0, 0, 0), 2)
cv2.imshow('frame', frame)
out.write(frame)
print('FPS {:.1f}'.format(1 / (time.time() - stime)))
if cv2.waitKey(1) & 0xFF == ord('q'):
break
capture.release()
out.release()
cv2.destroyAllWindows()
추가한 부분
width = capture.get(cv2.CAP_PROP_FRAME_WIDTH)
height = capture.get(cv2.CAP_PROP_FRAME_HEIGHT)
fourcc = cv2.VideoWriter_fourcc(*'DIVX')
out = cv2.VideoWriter('output.avi', fourcc, 30.0, (int(width), int(height)))
out.write(frame)
out.release()
- 이렇게 3개 추가하였다.
- 이렇게 원래 속도로 인식해서 보여준다. 속이 다 시원하다^^
- 코트 위에 있는 선수들을 인식하게하고 라벨의 크기를 조절하려고 한다.
텍스트 라벨 수정
import cv2
from darkflow.net.build import TFNet
import numpy as np
import time
from PIL import ImageFont, ImageDraw, Image
font = ImageFont.truetype("./fontzip/NanumSquareB.ttf", 10)
options = {
'model': 'cfg/yolo.cfg',
'load': 'bin/yolo.weights',
'threshold': 0.2,
'gpu': 1.0
}
tfnet = TFNet(options)
colors = [tuple(255 * np.random.rand(3)) for _ in range(10)]
# capture = cv2.VideoCapture(0)
capture = cv2.VideoCapture('nba_sample.mp4')
capture.set(cv2.CAP_PROP_FRAME_WIDTH,1280)
capture.set(cv2.CAP_PROP_FRAME_HEIGHT, 720)
# capture.set(cv2.CAP_PROP_FPS, int(60))
width = capture.get(cv2.CAP_PROP_FRAME_WIDTH)
height = capture.get(cv2.CAP_PROP_FRAME_HEIGHT)
fourcc = cv2.VideoWriter_fourcc(*'DIVX')
out = cv2.VideoWriter('output.avi', fourcc, 30.0, (int(width), int(height)))
prev_time = 0
FPS = 10
while True:
# stime = time.time()
ret, frame = capture.read()
current_time = time.time() - prev_time
if(ret is True) and (current_time > 1./ FPS):
prev_time = time.time()
results = tfnet.return_predict(frame)
for color, result in zip(colors, results):
tl = (result['topleft']['x'], result['topleft']['y'])
br = (result['bottomright']['x'], result['bottomright']['y'])
label = result['label']
confidence = result['confidence']
text = '{}: {:.0f}%'.format(label, confidence * 100)
frame = cv2.rectangle(frame, tl, br, color, 2)
text_size = cv2.getTextSize(text=text, fontFace=cv2.FONT_HERSHEY_SIMPLEX, fontScale=1, thickness=2)
text_width, text_height = text_size[0][0], text_size[0][1]
cv2.rectangle(frame, pt1=(result['topleft']['x']-1, result['topleft']['y'] - text_height), pt2=(result['topleft']['x']-30 + text_width, result['topleft']['y']), color=color, thickness=-1)
frame = cv2.putText(
frame, text, (result['topleft']['x'], result['topleft']['y']-4), cv2.FONT_HERSHEY_SIMPLEX, 0.7, (255, 255, 255), 2)
cv2.imshow('frame', frame)
out.write(frame)
print('FPS {:.1f}'.format(1 / (time.time() - prev_time)))
if cv2.waitKey(1) & 0xFF == ord('q'):
break
capture.release()
out.release()
cv2.destroyAllWindows()
추가한 부분
from PIL import ImageFont, ImageDraw, Image
font = ImageFont.truetype("./fontzip/NanumSquareB.ttf", 10)
text_size = cv2.getTextSize(text=text, fontFace=cv2.FONT_HERSHEY_SIMPLEX, fontScale=1, thickness=2)
text_width, text_height = text_size[0][0], text_size[0][1]
cv2.rectangle(frame, pt1=(result['topleft']['x']-1, result['topleft']['y'] - text_height), pt2=(result['topleft']['x']-30 + text_width, result['topleft']['y']), color=color, thickness=-1)
- 우선 font가 마음에 들지 않아 바꿨고 텍스트의 크기를 받아서 박스의 크기를 설정해준다.
수정한 부분
frame = cv2.putText(
frame, text, (result['topleft']['x'], result['topleft']['y']-4), cv2.FONT_HERSHEY_SIMPLEX, 0.7, (255, 255, 255), 2)
- 텍스트의 위치를 조금 수정하였다. y좌표가 밑으로 쳐지는 경향이 있어서 박스안에 들어오게 바꾸었다. 글자색도 흰색으로 변경하였고 크키고 글씨 크기도 조금 줄였다.
- 저번보다 보기에 편해졌다. 글씨체좀 동글동글하게 바꾸고 해상도도 바꿔야겠다.
- 더 찾아봐야겠다. 이미지 예시는 있는데 puttext는 안보여서 더 찾아보려고 한다.
- 그 다음에는 코트위 선수들을 어떻게 인식할 지 찾아봐야겠다.
oepn source basketball yolo code
- 구글에서 검색했을때 나오는 결과중 3개의 코드를 분석해서 실행하려고 한다. 아주 자세히 나와있고 잘 인식해준다. 보니깐 우선 코트를 학습하고 사람의 관절의 움직임을 분석한다. 신기했다. 이 코드를 공부하고 또 실행하려고 한다. 딥러닝의 세계는 신기하다.
728x90
LIST
'프로젝트 > 농구 득점 영상 딥러닝 만들기' 카테고리의 다른 글
basketballVideoAnalysis 오픈소스 해보기 (0) | 2021.06.21 |
---|---|
Court Reconstruction for Camera Calibration in Broadcast Basketball Videos (0) | 2021.04.12 |
아마존 AWS E2C 스팟인스턴스 사용하기 (0) | 2021.02.26 |
Geforce mx250 tensorflow gpu 설치 + 설정 (0) | 2021.02.08 |
농구영상 득점 자동 판별기 만들기 (0) | 2021.01.17 |
Comments