Skip to content

Commit

Permalink
updated code for handpose and added sample video
Browse files Browse the repository at this point in the history
  • Loading branch information
vikasgupta-github committed Oct 8, 2018
1 parent 5e43a3c commit 34f6926
Show file tree
Hide file tree
Showing 4 changed files with 257 additions and 34 deletions.
Binary file added HandPose/asl.mp4
Binary file not shown.
261 changes: 246 additions & 15 deletions HandPose/handPose-Notebook.ipynb

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion HandPose/handPoseVideo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ int main(int argc, char **argv)
int inHeight = 368;
int inWidth = (int(aspect_ratio*inHeight) * 8) / 8;

cout << "inWidth = " << inWidth << " ; inHeight = " << inHeight << endl;
cout << "inWidth = " << inWidth << " ; inHeight = " << inHeight << endl;

VideoWriter video("Output-Skeleton.avi",VideoWriter::fourcc('M','J','P','G'), 10, Size(frameWidth,frameHeight));

Expand Down Expand Up @@ -99,6 +99,7 @@ int main(int argc, char **argv)
}

t = ((double)cv::getTickCount() - t)/cv::getTickFrequency();
cout << "Time Taken for frame = " << t << endl;
cv::putText(frame, cv::format("time taken = %.2f sec", t), cv::Point(50, 50), cv::FONT_HERSHEY_COMPLEX, .8, cv::Scalar(255, 50, 0), 2);
// imshow("Output-Keypoints", frameCopy);
imshow("Output-Skeleton", frame);
Expand Down
27 changes: 9 additions & 18 deletions HandPose/handPoseVideo.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@
nPoints = 22
POSE_PAIRS = [ [0,1],[1,2],[2,3],[3,4],[0,5],[5,6],[6,7],[7,8],[0,9],[9,10],[10,11],[11,12],[0,13],[13,14],[14,15],[15,16],[0,17],[17,18],[18,19],[19,20] ]

threshold = 0.1
threshold = 0.2


input_source = 0
input_source = "asl.mp4"
cap = cv2.VideoCapture(input_source)
hasFrame, frame = cap.read()

Expand All @@ -36,17 +36,11 @@
cv2.waitKey()
break

print("imread = {}".format(time.time() - t))

inpBlob = cv2.dnn.blobFromImage(frame, 1.0 / 255, (inWidth, inHeight),
(0, 0, 0), swapRB=False, crop=False)

print("Blob = {}".format(time.time() - t))

net.setInput(inpBlob)

print("setInput = {}".format(time.time() - t))

output = net.forward()

print("forward = {}".format(time.time() - t))
Expand All @@ -63,31 +57,28 @@
minVal, prob, minLoc, point = cv2.minMaxLoc(probMap)

if prob > threshold :
cv2.circle(frameCopy, (int(point[0]), int(point[1])), 8, (0, 255, 255), thickness=-1, lineType=cv2.FILLED)
cv2.putText(frameCopy, "{}".format(i), (int(point[0]), int(point[1])), cv2.FONT_HERSHEY_SIMPLEX, 1, (0, 0, 255), 2, lineType=cv2.LINE_AA)
cv2.circle(frameCopy, (int(point[0]), int(point[1])), 6, (0, 255, 255), thickness=-1, lineType=cv2.FILLED)
cv2.putText(frameCopy, "{}".format(i), (int(point[0]), int(point[1])), cv2.FONT_HERSHEY_SIMPLEX, .8, (0, 0, 255), 2, lineType=cv2.LINE_AA)

# Add the point to the list if the probability is greater than the threshold
points.append((int(point[0]), int(point[1])))
else :
points.append(None)

print("keypoints = {}".format(time.time() - t))

# Draw Skeleton
for pair in POSE_PAIRS:
partA = pair[0]
partB = pair[1]

if points[partA] and points[partB]:
cv2.line(frame, points[partA], points[partB], (0, 255, 255), 3, lineType=cv2.LINE_AA)
cv2.circle(frame, points[partA], 8, (0, 0, 255), thickness=-1, lineType=cv2.FILLED)
cv2.circle(frame, points[partB], 8, (0, 0, 255), thickness=-1, lineType=cv2.FILLED)
cv2.line(frame, points[partA], points[partB], (0, 255, 255), 2, lineType=cv2.LINE_AA)
cv2.circle(frame, points[partA], 5, (0, 0, 255), thickness=-1, lineType=cv2.FILLED)
cv2.circle(frame, points[partB], 5, (0, 0, 255), thickness=-1, lineType=cv2.FILLED)

print("skeleton = {}".format(time.time() - t))
print("Time Taken for frame = {}".format(time.time() - t))

# cv2.putText(frame, "time taken = {:.2f} sec".format(time.time() - t), (50, 50), cv2.FONT_HERSHEY_COMPLEX, .8, (255, 50, 0), 2, lineType=cv2.LINE_AA)
cv2.putText(frame, "Hand Pose using OpenCV", (50, 50), cv2.FONT_HERSHEY_COMPLEX, 1, (255, 50, 0), 2, lineType=cv2.LINE_AA)
# cv2.imshow('Output-Keypoints', frameCopy)
# cv2.putText(frame, "Hand Pose using OpenCV", (50, 50), cv2.FONT_HERSHEY_COMPLEX, 1, (255, 50, 0), 2, lineType=cv2.LINE_AA)
cv2.imshow('Output-Skeleton', frame)
# cv2.imwrite("video_output/{:03d}.jpg".format(k), frame)
key = cv2.waitKey(1)
Expand Down

0 comments on commit 34f6926

Please sign in to comment.