As a somewhat simplistic way of finding multiple poses in an image, I thought it would be interesting to use ImageContents
to find people and then use your OpenPose implementation to detect poses for each person.
First, I altered your showPose
function to include an origin
parameter and removed the last line to make it return the poses only (i.e. a pose
function):
pose[img_, origin_: {0, 0}] :=
Module[{bodylist, size, out, confidences, pts, people, pose},
bodylist = Range[14];
size = {368, 368};
out = trainedOpenPose[img];
confidences = out[[2]];
pts = Map[Plus[origin, #] &,
maxpts[img, confidences, #] & /@ bodylist];
pose = Graphics[{Yellow, Thickness[.0125],
Line[pts[[#]] & /@ {1, 2}], Green,
Line[pts[[#]] & /@ {2, 3, 4, 5}], Cyan,
Line[pts[[#]] & /@ {2, 6, 7, 8}], Orange,
Line[pts[[#]] & /@ {2, 9, 10, 11}], Magenta,
Line[pts[[#]] & /@ {2, 12, 13, 14}], PointSize[Large], Red,
Point[pts]}, ImagePadding -> All]]
Then I made a function that retrieves the images and bounding boxes for each person in the original image, computing and translating poses for each image based on the origin of its bounding box:
multiPose[img_] := Module[{people, boxes, poses},
{people, boxes} =
Transpose[
Normal@ImageContents[img,
Entity["Concept", "Person::93r37"]][[All, {"Image",
"BoundingBox"}]] // Values];
poses =
Table[pose[people[[i]], boxes[[i, 1]]], {i, Length[people]}]]
Finally, a function to show the poses in context:
showMultiPose[img_] := Show[img, Sequence[multiPose[img]]]
Not suitable for real-time processing or anything, but it was very easy to implement, and it seems to work in seconds, even for a decent number of people: