protected override void WorkConsumer(StdSharedPtr <UserDatum>[] datumsPtr) { try { // User's displaying/saving/other processing here // datum.cvOutputData: rendered frame with pose or heatmaps // datum.poseKeypoints: Array<float> with the estimated pose if (datumsPtr != null && datumsPtr.Length != 0) { using (var cvOutputData = OpenPose.OP_OP2CVCONSTMAT(datumsPtr[0].Get().CvOutputData)) { Cv.ImShow($"{OpenPose.OpenPoseNameAndVersion()} - Tutorial Thread API", cvOutputData); // It displays the image and sleeps at least 1 ms (it usually sleeps ~5-10 msec to display the image) Cv.WaitKey(1); } } } catch (Exception e) { OpenPose.Log("Some kind of unexpected error happened."); this.Stop(); OpenPose.Error(e.Message, -1, nameof(this.WorkConsumer)); } #endregion }
public bool Display(StdSharedPtr <StdVector <StdSharedPtr <Datum> > > datumsPtr) { // User's displaying/saving/other processing here // datum.cvOutputData: rendered frame with pose or heatmaps // datum.poseKeypoints: Array<float> with the estimated pose if (datumsPtr != null && datumsPtr.TryGet(out var data) && !data.Empty) { var temp = data.ToArray()[0].Get(); using (var cvMat = OpenPose.OP_OP2CVCONSTMAT(temp.CvOutputData)) Cv.ImShow($"{OpenPose.OpenPoseNameAndVersion()} - Tutorial C++ API", cvMat); // Display image and sleeps at least 1 ms (it usually sleeps ~5-10 msec to display the image) }
private static bool Display(StdSharedPtr <StdVector <StdSharedPtr <Datum> > > datumsPtr) { try { // User's displaying/saving/other processing here // datum.cvOutputData: rendered frame with pose or heatmaps // datum.poseKeypoints: Array<float> with the estimated pose if (datumsPtr != null && datumsPtr.TryGet(out var data) && !data.Empty) { // Display image and sleeps at least 1 ms (it usually sleeps ~5-10 msec to display the image) var temp = data.ToArray()[0].Get(); using (var cvMat = OpenPose.OP_OP2CVCONSTMAT(temp.CvOutputData)) Cv.ImShow($"{OpenPose.OpenPoseNameAndVersion()} - Tutorial C++ API", cvMat); } else { OpenPose.Log("Nullptr or empty datumsPtr found.", Priority.High); } var key = Cv.WaitKey(1); return(key == 27); }
private static void Display(StdSharedPtr <StdVector <StdSharedPtr <Datum> > > datumsPtr) { try { // User's displaying/saving/other processing here // datum.cvOutputData: rendered frame with pose or heatmaps // datum.poseKeypoints: Array<float> with the estimated pose if (datumsPtr != null && datumsPtr.TryGet(out var data) && !data.Empty) { // Display image var temp = data.ToArray(); using (var cvMat = OpenPose.OP_OP2CVCONSTMAT(temp[0].Get().CvOutputData)) { Cv.ImShow($"{OpenPose.OpenPoseNameAndVersion()} - Tutorial C++ API", cvMat); Cv.WaitKey(); } } else { OpenPose.Log("Nullptr or empty datumsPtr found.", Priority.High); } }
private static void Display(StdSharedPtr <StdVector <StdSharedPtr <Datum> > > datumsPtr) { try { // User's displaying/saving/other processing here // datum.cvOutputData: rendered frame with pose or heatmaps // datum.poseKeypoints: Array<float> with the estimated pose if (datumsPtr != null && datumsPtr.TryGet(out var data) && !data.Empty) { var datum = datumsPtr.Get().At(0).Get(); // Display image using (var cvMat = OpenPose.OP_OP2CVCONSTMAT(datum.CvOutputData)) { Cv.ImShow($"{OpenPose.OpenPoseNameAndVersion()} - Tutorial C++ API", cvMat); Cv.WaitKey(0); } } } catch (Exception e) { OpenPose.Error(e.Message, -1, nameof(Display)); } }
private static bool Display(StdSharedPtr <StdVector <StdSharedPtr <Datum> > > datumsPtr, int desiredChannel = 0) { try { if (datumsPtr != null && datumsPtr.TryGet(out var data) && !data.Empty) { var datum = datumsPtr.Get().At(0).Get(); // Note: Heatmaps are in net_resolution size, which does not necessarily match the final image size // Read heatmaps var poseHeatMaps = datum.PoseHeatMaps; // Read desired channel var numberChannels = poseHeatMaps.GetSize(0); var height = poseHeatMaps.GetSize(1); var width = poseHeatMaps.GetSize(2); var eleSize = sizeof(float); using (var desiredChannelHeatMap = new Mat(height, width, MatType.CV_32F, IntPtr.Add(poseHeatMaps.GetPtr(), (desiredChannel % numberChannels) * height * width * eleSize))) { // Read image used from OpenPose body network (same resolution than heatmaps) var inputNetData = datum.InputNetData[0]; using (var inputNetDataB = new Mat(height, width, MatType.CV_32F, IntPtr.Add(inputNetData.GetPtr(), 0 * height * width * eleSize))) using (var inputNetDataG = new Mat(height, width, MatType.CV_32F, IntPtr.Add(inputNetData.GetPtr(), 1 * height * width * eleSize))) using (var inputNetDataR = new Mat(height, width, MatType.CV_32F, IntPtr.Add(inputNetData.GetPtr(), 2 * height * width * eleSize))) using (var vector = new StdVector <Mat>(new List <Mat>(new[] { inputNetDataB, inputNetDataG, inputNetDataR }))) using (var tmp = new Mat()) { Cv.Merge(vector, tmp); using (var add = tmp + 0.5) using (var mul = add * 255) using (var netInputImage = (Mat)mul) { // Turn into uint8 Cv.Mat using (var netInputImageUint8 = new Mat()) { netInputImage.ConvertTo(netInputImageUint8, MatType.CV_8UC1); using (var desiredChannelHeatMapUint8 = new Mat()) { desiredChannelHeatMap.ConvertTo(desiredChannelHeatMapUint8, MatType.CV_8UC1); // Combining both images using (var imageToRender = new Mat()) { Cv.ApplyColorMap(desiredChannelHeatMapUint8, desiredChannelHeatMapUint8, ColormapType.COLORMAP_JET); Cv.AddWeighted(netInputImageUint8, 0.5, desiredChannelHeatMapUint8, 0.5, 0d, imageToRender); // Display image Cv.ImShow($"{OpenPose.OpenPoseNameAndVersion()} - Tutorial C++ API", imageToRender); } } } } } } } else { OpenPose.Log("Nullptr or empty datumsPtr found.", Priority.High); } var key = (char)Cv.WaitKey(1); return(key == 27); }
protected override void WorkConsumer(StdSharedPtr <UserDatum>[] datumsPtr) { try { // User's displaying/saving/other processing here // datum.cvOutputData: rendered frame with pose or heatmaps // datum.poseKeypoints: Array<float> with the estimated pose if (datumsPtr != null && datumsPtr.Length != 0) { var datum = datumsPtr[0].Get(); // Show in command line the resulting pose keypoints for body, face and hands OpenPose.Log("\nKeypoints:"); // Accesing each element of the keypoints var poseKeypoints = datum.PoseKeyPoints; OpenPose.Log("Person pose keypoints:"); for (var person = 0; person < poseKeypoints.GetSize(0); person++) { OpenPose.Log($"Person {person} (x, y, score):"); for (var bodyPart = 0; bodyPart < poseKeypoints.GetSize(1); bodyPart++) { var valueToPrint = ""; for (var xyscore = 0; xyscore < poseKeypoints.GetSize(2); xyscore++) { valueToPrint += poseKeypoints[new[] { person, bodyPart, xyscore }] + " "; } OpenPose.Log(valueToPrint); } } OpenPose.Log(" "); // Alternative: just getting std::string equivalent OpenPose.Log($"Face keypoints: {datum.FaceKeyPoints}"); OpenPose.Log($"Left hand keypoints: {datum.HandKeyPoints[0]}"); OpenPose.Log($"Right hand keypoints: {datum.HandKeyPoints[1]}"); // Heatmaps var poseHeatMaps = datum.PoseHeatMaps; if (!poseHeatMaps.Empty) { OpenPose.Log($"Pose heatmaps size: [{poseHeatMaps.GetSize(0)}, {poseHeatMaps.GetSize(1)}, {poseHeatMaps.GetSize(2)}]"); var faceHeatMaps = datum.FaceHeatMaps; OpenPose.Log($"Face heatmaps size: [{faceHeatMaps.GetSize(0)}, {faceHeatMaps.GetSize(1)}, {faceHeatMaps.GetSize(2)}, {faceHeatMaps.GetSize(3)}]"); var handHeatMaps = datum.HandHeatMaps; OpenPose.Log($"Left hand heatmaps size: [{handHeatMaps[0].GetSize(0)}, {handHeatMaps[0].GetSize(1)}, {handHeatMaps[0].GetSize(2)}, {handHeatMaps[0].GetSize(3)}]"); OpenPose.Log($"Right hand heatmaps size: [{handHeatMaps[1].GetSize(0)}, {handHeatMaps[1].GetSize(1)}, {handHeatMaps[1].GetSize(2)}, {handHeatMaps[1].GetSize(3)}]"); } // Display results (if enabled) if (!Flags.NoDisplay) { using (var cvMat = OpenPose.OP_OP2CVCONSTMAT(datum.CvOutputData)) { // Display rendered output image Cv.ImShow($"{OpenPose.OpenPoseNameAndVersion()} - Tutorial C++ API", cvMat); // Display image and sleeps at least 1 ms (it usually sleeps ~5-10 msec to display the image) var key = (char)Cv.WaitKey(1); if (key == 27) { this.Stop(); } } } } } catch (Exception e) { this.Stop(); OpenPose.Error(e.Message, -1, nameof(this.WorkConsumer)); } }