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 | 31 |
Tags
- 알고리즘
- 그리디알고리즘
- MySQL
- 마우스 따라다니기
- 우분투
- 원형
- 회의실 배정
- 2020 KAKAO BLIND RECRUITMENT
- 걷는건귀찮아
- 윈도우
- 유니티
- SWEA
- 토글 그룹
- 영상 프레임 추출
- 탄막 이동
- c#
- 3273
- 알고리즘 목차
- 탄막
- 자료구조 목차
- 탄막 스킬 범위
- 3344
- 단어 수학
- 18249
- 수 만들기
- 강의실2
- 문자열 압축
- AI Hub
- mysqld.sock
- 백준
Archives
- Today
- Total
와이유스토리
[캡스톤B] 3. OpenPose를 이용해 손의 위치 파악하기 본문
※ OpenPose 코드 참조
!git clone https://github.com/misbah4064/human-pose-estimation-opencv.git
%cd human-pose-estimation-opencv/
import cv2 as cv
import numpy as np
from google.colab.patches import cv2_imshow
BODY_PARTS = { "Nose": 0, "Neck": 1, "RShoulder": 2, "RElbow": 3, "RWrist": 4,
"LShoulder": 5, "LElbow": 6, "LWrist": 7, "RHip": 8, "RKnee": 9,
"RAnkle": 10, "LHip": 11, "LKnee": 12, "LAnkle": 13, "REye": 14,
"LEye": 15, "REar": 16, "LEar": 17, "Background": 18 }
POSE_PAIRS = [ ["Neck", "RShoulder"], ["Neck", "LShoulder"], ["RShoulder", "RElbow"],
["RElbow", "RWrist"], ["LShoulder", "LElbow"], ["LElbow", "LWrist"],
["Neck", "RHip"], ["RHip", "RKnee"], ["RKnee", "RAnkle"], ["Neck", "LHip"],
["LHip", "LKnee"], ["LKnee", "LAnkle"], ["Neck", "Nose"], ["Nose", "REye"],
["REye", "REar"], ["Nose", "LEye"], ["LEye", "LEar"] ]
width = 368
height = 368
inWidth = width
inHeight = height
net = cv.dnn.readNetFromTensorflow("graph_opt.pb")
thr = 0.2
def poseDetector(frame):
frameWidth = frame.shape[1]
frameHeight = frame.shape[0]
net.setInput(cv.dnn.blobFromImage(frame, 1.0, (inWidth, inHeight), (127.5, 127.5, 127.5), swapRB=True, crop=False))
out = net.forward()
out = out[:, :19, :, :] # MobileNet output [1, 57, -1, -1], we only need the first 19 elements
assert(len(BODY_PARTS) == out.shape[1])
points = []
for i in range(len(BODY_PARTS)):
# Slice heatmap of corresponging body's part.
heatMap = out[0, i, :, :]
_, conf, _, point = cv.minMaxLoc(heatMap)
x = (frameWidth * point[0]) / out.shape[3]
y = (frameHeight * point[1]) / out.shape[2]
points.append((int(x), int(y)) if conf > thr else None)
for pair in POSE_PAIRS:
partFrom = pair[0]
partTo = pair[1]
assert(partFrom in BODY_PARTS)
assert(partTo in BODY_PARTS)
idFrom = BODY_PARTS[partFrom]
idTo = BODY_PARTS[partTo]
if points[idFrom] and points[idTo]:
cv.line(frame, points[idFrom], points[idTo], (0, 255, 0), 3)
cv.ellipse(frame, points[idFrom], (3, 3), 0, 0, 360, (0, 0, 255), cv.FILLED)
cv.ellipse(frame, points[idTo], (3, 3), 0, 0, 360, (0, 0, 255), cv.FILLED)
t, _ = net.getPerfProfile()
return frame
import cv2
cap = cv2.VideoCapture('/content/drive/MyDrive/Colab_Notebooks/160-2_cam01_dump02_place10_day_spring.mp4')
ret, frame = cap.read()
frame_height, frame_width, _ = frame.shape
out = cv2.VideoWriter('output.avi',cv2.VideoWriter_fourcc('M','J','P','G'), 10, (frame_width,frame_height))
print("Processing Video...")
while cap.isOpened():
ret, frame = cap.read()
if not ret:
out.release()
break
output = poseDetector(frame)
out.write(output)
out.release()
print("Done processing video")
%cd /content/human-pose-estimation-opencv
%mv output.avi /content/drive/MyDrive/Colab_Notebooks/
'프로젝트 > 인공지능' 카테고리의 다른 글
[캡스톤B] 2. Colab을 이용한 YOLOv5 Custom 학습 및 Inference (3) | 2021.05.17 |
---|---|
[캡스톤B] 1. 영상 데이터 프레임 추출 (0) | 2021.05.17 |
Comments