Human Pose Estimation using opencv | python | OpenPose | stepwise implementation for beginners

preview_player
Показать описание
This video contains stepwise implementation for human pose estimation using OpenCV for processing the following:

1) Single image

3) Realtime- Webcam demo

This tutorial is based on Github code
inspired by OpenCV official example

For more tutorials, please visit our channel
1) Face Mask Detection Tutorial | Transfer Learning | Python | Tensorflow | OpenCV | for beginners

2) Realtime Face Emotion Recognition | Python | OpenCV | Step by Step Tutorial for beginners

3)Real-time Drowsiness Detection Tutorial | Transfer Learning | TensorFlow | Python | OpenCV

4) Deep Learning - Image Classification Tutorial step by step (for Beginners) (python / TensorFlow)
Рекомендации по теме
Комментарии
Автор

This tutorial made me more excited to work on my thesis! Great work! Thank you!!!
Btw, for those looking for the exact code, I think this is it:

import cv2 as cv
import matplotlib.pyplot as plt

net = ## weights

inWidth = 368
inHeight = 368
thr = 0.2

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"] ]

img = cv.imread("pose.png")
plt.imshow(cv.cvtColor(img, cv.COLOR_BGR2RGB))


def pose_estimation(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, :, :]

assert(len(BODY_PARTS) == out.shape[1])

points = []

for i in range(len(BODY_PARTS)):
# Slice heatmap of corresponding body's part.
heatMap = out[0, i, :, :]

# Originally, we try to find all the local maximums. To simplify a sample
# we just find a global one. However only a single pose at the same time
# could be detected this way.
_, conf, _, point = cv.minMaxLoc(heatMap)
x = (frameWidth * point[0]) / out.shape[3]
y = (frameHeight * point[1]) / out.shape[2]

# Add a point if it's confidence is higher than threshold.
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()
freq = cv.getTickFrequency() / 1000
cv.putText(frame, '%.2fms' % (t / freq), (10, 20), cv.FONT_HERSHEY_SIMPLEX, 0.5, (0, 0, 0))

return frame


estimated_image = pose_estimation(img)
plt.imshow(cv.cvtColor(estimated_image, cv.COLOR_BGR2RGB))

.
.
# perform demo on video...
.
.

# perform this demo on webcam

cap = cv.VideoCapture(1)
cap.set(cv.CAP_PROP_FPS, 10)
cap.set(3, 800)
cap.set(4, 800)

if not cap.isOpened():
cap = cv.VideoCapture(0)
if not cap.isOpened():
raise IOError("Cannot open webcam")

while cv.waitKey(1) < 0:
hasFrame, frame = cap.read()
if not hasFrame:
cv.waitKey()
break

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, :, :]

assert(len(BODY_PARTS) == out.shape[1])

points = []

for i in range(len(BODY_PARTS)):
# Slice heatmap of corresponding body's part.
heatMap = out[0, i, :, :]

# Originally, we try to find all the local maximums. To simplify a sample
# we just find a global one. However only a single pose at the same time
# could be detected this way.
_, conf, _, point = cv.minMaxLoc(heatMap)
x = (frameWidth * point[0]) / out.shape[3]
y = (frameHeight * point[1]) / out.shape[2]

# Add a point if it's confidence is higher than threshold.
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()
freq = cv.getTickFrequency() / 1000
cv.putText(frame, '%.2fms' % (t / freq), (10, 20), cv.FONT_HERSHEY_SIMPLEX, 0.5, (0, 0, 0))

cv.imshow('Pose estimation trial', frame)

KorinaRunningFromPerfection
Автор

I was highly impressed by your video. I am also a PhD student in Universiti Sains Malaysia, working on Human pose estimation.I hope we can share our views in the future

sanisalisu
Автор

It was very impressive.
How do I extract coordinate values for each joint?

dau_pjs
Автор

Very much Impressed by the content of this video, detailed one so far.

priyanshuupadhyay
Автор

That was really an informative video but sir can you please show us one with the trained model. It would be really helpful if you plz come up with human pose detection with trained models. With love from Indian Fan:)

akankshyapanda
Автор

Hey, I'm trying to build an exercise recognition and Rep counter system using Pose estimation, How can I get started with this? Any kind of help will be appreciated! :)

yashranawat
Автор

Hello
Do you have a video where we can tell if a person is doing exercise in a wrong way ?
I mean if he is not using correct postures while doing excercise

MegaHarshjain
Автор

your videos are very helpful. Please upload more

umairmughal
Автор

Tnx. Helped alot. I wish you would have mentioned the output file. Where we would get the coordinations of body points. I will be thankful if you could help me out in that part too.

taravathadian
Автор

thanks for this to do pose estimation for multiple people in a video....this is actually detecting the pose for one person.

JabiloJoseJ
Автор

Great video.How to find the distance between one keypoint(hip) to other keypoint(shoulder)

geekelectronics
Автор

estimated_image = pose_estimation(img)
this line is not working please guide

junaidstopi
Автор

Really helpful video even for beginners, thank you so much! though it is not very accurate when i tested it with different images.

tanushreepardhi
Автор

net =
cv2.error: OpenCV(4.7.0) error: (-2:Unspecified error) FAILED: fs.is_open(). Can't open "graph_opt.pb" in function

i get this error, how to fix?

Vanadzor_EditZ
Автор

How to train the pose estimation model for my custom use case?
Any link of step by step would be helpful for me!!
Thanks

karndeepsingh
Автор

How estimate 3D pose from 2D pose estimation

ishanweerakoon
Автор

where can i get video datasets for pushups, squats, lunges (at least 5 exercises)

bhavya
Автор

Hello, what should I add on the script, so I have hands recognition too ?

tsialeopard
Автор

Hi bro very nice. I just want to built a Android app to detect same way body motion. Can you tell me what i need to do for it. Very thank full

parabellum.
Автор

Hello the video was awesome, could you please guide us from scatrch what r the platform to use and what to install... plzzz

KannadaAdviceTv