private static int TutorialApiCpp() { try { OpenPose.Log("Starting OpenPose demo...", Priority.High); using (var opTimer = OpenPose.GetTimerInit()) { // Configuring OpenPose OpenPose.Log("Configuring OpenPose...", Priority.High); using (var opWrapper = new Wrapper <Datum>(ThreadManagerMode.AsynchronousOut)) { ConfigureWrapper(opWrapper); // Start, run, and stop processing - exec() blocks this thread until OpenPose wrapper has finished OpenPose.Log("Starting thread(s)...", Priority.High); opWrapper.Start(); // User processing var userOutputClass = new UserOutputClass(); var userWantsToExit = false; while (!userWantsToExit) { // Pop frame if (opWrapper.WaitAndPop(out var datumProcessed)) { if (!Flags.NoDisplay) { userWantsToExit = userOutputClass.Display(datumProcessed); } userOutputClass.PrintKeyPoints(datumProcessed); datumProcessed.Dispose(); } // If OpenPose finished reading images else if (!opWrapper.IsRunning) { break; } // Something else happened else { OpenPose.Log("Processed datum could not be emplaced.", Priority.High); } } OpenPose.Log("Stopping thread(s)", Priority.High); opWrapper.Stop(); // Measuring total time OpenPose.PrintTime(opTimer, "OpenPose demo successfully finished. Total time: ", " seconds.", Priority.High); } } // Return return(0); } catch (Exception) { return(-1); } }
private static int TutorialApiCpp() { try { OpenPose.Log("Starting OpenPose demo...", Priority.High); using (var opTimer = OpenPose.GetTimerInit()) { // OpenPose wrapper OpenPose.Log("Configuring OpenPose...", Priority.High); using (var opWrapper = new Wrapper <Datum>()) { ConfigureWrapper(opWrapper); // Start, run, and stop processing - exec() blocks this thread until OpenPose wrapper has finished OpenPose.Log("Starting thread(s)...", Priority.High); opWrapper.Exec(); } // Measuring total time OpenPose.PrintTime(opTimer, "OpenPose demo successfully finished. Total time: ", " seconds.", Priority.High); } // Return return(0); } catch (Exception) { return(-1); } }
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 }
protected override void Work(StdSharedPtr <CustomDatum>[] datums) { try { if (datums != null) { // Debugging log OpenPose.LogIfDebug("", Priority.Low, -1, nameof(this.Work), ""); // Profiling speed var profilerKey = Profiler.TimerInit(-1, nameof(this.Work), ""); foreach (var datum in datums) { // THESE 2 ARE THE ONLY LINES THAT THE USER MUST MODIFY ON THIS HPP FILE, by using the proper // function and datum elements using (var cvOutputData = OpenPose.OP_OP2CVMAT(datum.Get().CvOutputData)) this._UserPostProcessing.DoSomething(cvOutputData, cvOutputData); // Profiling speed Profiler.TimerEnd(profilerKey); Profiler.PrintAveragedTimeMsOnIterationX(profilerKey, -1, nameof(this.Work), ""); // Debugging log OpenPose.LogIfDebug("", Priority.Low, -1, nameof(this.Work), ""); } } } catch (Exception e) { this.Stop(); datums = null; Console.WriteLine(e.Message); } }
private static int TutorialAddModule1() { try { OpenPose.Log("Starting OpenPose demo...", Priority.High); using (var opTimer = OpenPose.GetTimerInit()) { // Configuring OpenPose OpenPose.Log("Configuring OpenPose...", Priority.High); using (var opWrapperT = new Wrapper <CustomDatum>()) { ConfigureWrapper(opWrapperT); OpenPose.Log("Starting thread(s)...", Priority.High); // Start, run & stop threads - it blocks this thread until all others have finished opWrapperT.Exec(); // Measuring total time OpenPose.PrintTime(opTimer, "OpenPose demo successfully finished. Total time: ", " seconds.", Priority.High); } } // Return successful message return(0); } catch (Exception) { return(-1); } }
// starts detector public override void Run(IProgress <DetectionResults> progress) { // detection loop - detects on each frame while (!userWantsToExit) // setting userWantsToExit to true breaks this loop { // get latest detected frame from input, which we set during the config if (opWrapper.WaitAndPop(out datumProcessed)) // detection data gets put into datumProcessed { if (datumProcessed != null && datumProcessed.TryGet(out data) && !data.Empty) // if datumProcessed exists && we can get the data sucessfully && retrieved data exists { Datum d = data.ToArray()[0].Get(); // retrieve datum object which contains the keypoint data progress.Report(new DetectionResults() // report calculated keypoint data with DetectionResults object { data = d, // keypoint data isFinished = false // are we finished with the detection }); } } else // can't get next frame, so we end the detection loop { OpenPose.Log("Processed datum could not be emplaced.", Priority.High); userWantsToExit = true; break; } } progress.Report(new DetectionResults() // when finished, we report with isFinished set to true { data = null, isFinished = true }); opWrapper.Dispose(); // dispose of openpose wrapper }
public StdSharedPtr <StdVector <UserDatum> > CreateDatum() { // Close program when empty frame if (this._Closed || this._ImageFiles.Length <= this._Counter) { OpenPose.Log("Last frame read and added to queue. Closing program after it is processed.", Priority.High); // This funtion stops this worker, which will eventually stop the whole thread system once all the // frames have been processed this._Closed = true; return(null); } else { // Create new datum var tmp = new StdVector <UserDatum>(); tmp.EmplaceBack(); var datumsPtr = new StdSharedPtr <StdVector <UserDatum> >(tmp); var datum = tmp.ToArray()[0]; // Fill datum using (var mat = Cv.ImRead(this._ImageFiles[this._Counter++])) datum.CvInputData = mat; // If empty frame -> return nullptr if (datum.CvInputData.Empty) { OpenPose.Log($"Empty frame detected on path: {this._ImageFiles[this._Counter - 1]}. Closing program.", Priority.High); this._Closed = true; datumsPtr = null; } return(datumsPtr); } }
protected override void Work(CustomDatum[] datums) { try { if (datums != null) { // Debugging log OpenPose.DebugLog("", Priority.Low, -1, nameof(this.Work), ""); // Profiling speed var profilerKey = Profiler.TimerInit(-1, nameof(this.Work), ""); foreach (var datum in datums) { // THIS IS THE ONLY LINE THAT THE USER MUST MODIFY ON THIS HPP FILE, by using the proper function // and datum elements this._UserPostProcessing.DoSomething(datum.CvOutputData, datum.CvOutputData); // Profiling speed Profiler.TimerEnd(profilerKey); Profiler.PrintAveragedTimeMsOnIterationX(profilerKey, -1, nameof(this.Work), ""); // Debugging log OpenPose.DebugLog("", Priority.Low, -1, nameof(this.Work), ""); } } } catch (Exception e) { this.Stop(); datums = null; Console.WriteLine(e.Message); } }
public WUserInput(string directoryPath) { this._ImageFiles = Directory.GetFiles(directoryPath, "*.jpg"); if (this._ImageFiles.Length == 0) { OpenPose.Error("No images found on: " + directoryPath, -1, nameof(WUserInput)); } }
public void Error() { const string message = nameof(this.Error); const string function = nameof(this.Error); const string file = "OpenPoseTest.cs"; OpenPose.Error($"{message}", -1, function, file); }
public WUserInput(string directoryPath) { // For all basic image formats // If we want only e.g., "jpg" + "png" images this._ImageFiles = OpenPose.GetFilesOnDirectory(directoryPath, Extensions.Images); if (this._ImageFiles.Length == 0) { OpenPose.Error("No images found on: " + directoryPath, -1, nameof(WUserInput)); } }
public void Log() { const string message = nameof(this.Log); const string function = nameof(this.Log); const string file = "OpenPoseTest.cs"; foreach (var priority in Enum.GetValues(typeof(Priority)).Cast <Priority>()) { OpenPose.Log($"{message}", priority, -1, function, file); } }
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 int TutorialApiCpp() { try { OpenPose.Log("Starting OpenPose demo...", Priority.High); using (var opTimer = OpenPose.GetTimerInit()) { // Configuring OpenPose OpenPose.Log("Configuring OpenPose...", Priority.High); using (var opWrapper = new Wrapper <Datum>(ThreadManagerMode.AsynchronousIn)) { ConfigureWrapper(opWrapper); // Start, run, and stop processing - exec() blocks this thread until OpenPose wrapper has finished OpenPose.Log("Starting thread(s)...", Priority.High); opWrapper.Start(); // User processing var userInputClass = new UserInputClass(Flags.ImageDir); var userWantsToExit = false; while (!userWantsToExit && !userInputClass.IsFinished()) { // Push frame using (var datumToProcess = userInputClass.CreateDatum()) { if (datumToProcess != null) { var successfullyEmplaced = opWrapper.WaitAndEmplace(datumToProcess); if (!successfullyEmplaced) { OpenPose.Log("Processed datum could not be emplaced.", Priority.High); } } } } OpenPose.Log("Stopping thread(s)", Priority.High); opWrapper.Stop(); } // Measuring total time OpenPose.PrintTime(opTimer, "OpenPose demo successfully finished. Total time: ", " seconds.", Priority.High); } // Return return(0); } catch (Exception) { return(-1); } }
private Datum ProcessBitmap(Bitmap bmp) { BitmapData bmpData = null; try { var width = bmp.Width; var height = bmp.Height; bmpData = bmp.LockBits(new Rectangle(0, 0, width, height), ImageLockMode.ReadOnly, PixelFormat.Format24bppRgb); var stride = bmpData.Stride; var scan0 = bmpData.Scan0; unsafe { // convert bitmap to byte array var line = width * 3; var image = new byte[line * height]; var ps = (byte *)scan0; for (var h = 0; h < height; h++) { Marshal.Copy((IntPtr)ps, image, line * h, line); ps += stride; } // use openpose wrapper to calculate keypoints using byte array object as input image this.datumProcessed = opWrapper.EmplaceAndPop(image, width, height, MatType.CV_8UC3); if (this.datumProcessed != null) // if output data exists { if (this.datumProcessed != null && this.datumProcessed.TryGet(out this.data) && !this.data.Empty) // if datumProcessed exists && we can get the data sucessfully && retrieved data exists { return(this.data.ToArray()[0].Get()); // retrieve datum object which contains the keypoint data } else // bad input { OpenPose.Log("Image could not be processed.", Priority.High); } } } } finally { if (bmpData != null) { bmp.UnlockBits(bmpData); } } return(null); }
public Datum ProcessFrame(Mat image) // gets result keypoints from OpenPoseDotNet.Mat { datumProcessed = opWrapper.EmplaceAndPop(image); // method detects on OpenPoseDotNet.Mat if (datumProcessed != null && datumProcessed.TryGet(out data) && !data.Empty) // if datumProcessed exists && we can get the data sucessfully && retrieved data exists { Datum result = data.ToArray()[0].Get(); // retrieve datum object which contains the keypoint data opWrapper.Dispose(); // dispose of wrapper after detection return(result); } else { OpenPose.Log("Nullptr or empty datumsPtr found.", Priority.High); return(null); } }
protected override StdSharedPtr <StdVector <StdSharedPtr <UserDatum> > > WorkProducer() { try { // Close program when empty frame if (this._ImageFiles.Length <= this._Counter) { OpenPose.Log("Last frame read and added to queue. Closing program after it is processed.", Priority.High); // This funtion stops this worker, which will eventually stop the whole thread system once all the // frames have been processed this.Stop(); return(null); } else { // Create new datum var vector = new StdVector <StdSharedPtr <UserDatum> >(); var datumsPtr = new StdSharedPtr <StdVector <StdSharedPtr <UserDatum> > >(vector); datumsPtr.Get().EmplaceBack(); var datum = datumsPtr.Get().At(0); // C# cannot set pointer object by using assignment operator datum.Reset(new UserDatum()); // Fill datum using (var cvInputData = Cv.ImRead(this._ImageFiles[this._Counter++])) using (var inputData = OpenPose.OP_CV2OPCONSTMAT(cvInputData)) datum.Get().CvInputData = inputData; // If empty frame -> return nullptr if (datum.Get().CvInputData.Empty) { OpenPose.Log($"Empty frame detected on path: {this._ImageFiles[this._Counter - 1]}. Closing program.", Priority.High); this.Stop(); datumsPtr = null; } return(datumsPtr); } } catch (Exception e) { OpenPose.Log("Some kind of unexpected error happened."); this.Stop(); OpenPose.Error(e.Message, -1, nameof(this.WorkProducer)); return(null); } }
private static void PrintKeypoints(StdSharedPtr <StdVector <StdSharedPtr <Datum> > > datumsPtr) { try { // Example: How to use the pose keypoints if (datumsPtr != null && datumsPtr.TryGet(out var data) && !data.Empty) { var temp = data.ToArray()[0].Get(); OpenPose.Log($"Body keypoints: {temp.PoseKeyPoints}", Priority.High); OpenPose.Log($"Face keypoints: {temp.FaceKeyPoints}", Priority.High); OpenPose.Log($"Left hand keypoints: {temp.HandKeyPoints[0]}", Priority.High); OpenPose.Log($"Right hand keypoints: {temp.HandKeyPoints[1]}", Priority.High); } else { OpenPose.Log("Nullptr or empty datumsPtr found.", Priority.High); } }
protected override StdSharedPtr <StdVector <UserDatum> > WorkProducer() { try { // Close program when empty frame if (this._ImageFiles.Length <= this._Counter) { OpenPose.Log("Last frame read and added to queue. Closing program after it is processed.", Priority.High); // This funtion stops this worker, which will eventually stop the whole thread system once all the // frames have been processed this.Stop(); return(null); } else { // Create new datum var tmp = new StdVector <UserDatum>(); tmp.EmplaceBack(); var datumsPtr = new StdSharedPtr <StdVector <UserDatum> >(tmp); var datum = tmp.ToArray()[0]; // Fill datum using (var mat = Cv.ImRead(this._ImageFiles[this._Counter++])) datum.CvInputData = mat; // If empty frame -> return nullptr if (datum.CvInputData.Empty) { OpenPose.Log($"Empty frame detected on path: {this._ImageFiles[this._Counter - 1]}. Closing program.", Priority.High); this.Stop(); datumsPtr = null; } return(datumsPtr); } } catch (Exception e) { OpenPose.Log("Some kind of unexpected error happened."); this.Stop(); OpenPose.Error(e.Message, -1, nameof(this.WorkProducer)); return(null); } }
private string filePath; // input file path /* * initializer for webcam input * netRes = net resolution * faceRes = face detector resolution, disable by setting to null * handRes = hand detector resolution, disable by setting to null * modelPose = which pose model to use * filePath = image file path * outPath = output path for frames, set null to disable output, disable by setting to null */ public ImageDetector(string netRes, string faceRes, string handRes, string modelPose, string filePath, string outPath) { this.filePath = filePath; // set image file path // set logging level OpenPose.Check(0 <= Flags.LoggingLevel && Flags.LoggingLevel <= 255, "Wrong logging_level value."); ConfigureLog.PriorityThreshold = (Priority)Flags.LoggingLevel; Profiler.SetDefaultX((ulong)Flags.ProfileSpeed); OpenPose.Log("Adding config...", Priority.High); InitFlags(netRes, faceRes, handRes, modelPose, outPath); // initialize flags with input values opWrapper = new Wrapper <UserDatum>(ThreadManagerMode.Asynchronous); // configure openpose wrapper obj based on the flags that we set ConfigOnFlags(opWrapper, false); // set input on config }
void Update() { counter++; if (counter < 10) { return; } counter = 0; string fileName = index.ToString("00000000") + "_keypoints"; if (System.IO.File.Exists(Application.dataPath + "/../outputs/" + fileName + ".json") != false) { var textAsset = NonResources.Load <TextAsset>(Application.dataPath + "/../outputs/" + fileName); OpenPose data = fileLoader.ReadOpenPoseJson(textAsset.text); var result = fileLoader.DrawOpenPoseData(data); resultPoint.team1Score += result.team1Score; resultPoint.team2Score += result.team2Score; index++; } }
protected override void Work(UserDatum[] datums) { try { // User's post-processing (after OpenPose processing & before OpenPose outputs) here // datum.cvOutputData: rendered frame with pose or heatmaps // datum.poseKeypoints: Array<float> with the estimated pose if (datums != null && datums.Length != 0) { foreach (var datum in datums) { Cv.BitwiseNot(datum.CvOutputData, datum.CvOutputData); } } } catch (Exception e) { this.Stop(); OpenPose.Error(e.Message, -1, nameof(this.Work)); } }
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); } }
protected override void Work(StdSharedPtr <Datum>[] datums) { try { // User's pre-processing (after OpenPose read the input image & before OpenPose processing) here // datumPtr->cvInputData: input frame if (datums != null && datums.Length != 0) { foreach (var datum in datums) { using (var cvOutputData = OpenPose.OP_OP2CVMAT(datum.Get().CvOutputData)) Cv.BitwiseNot(cvOutputData, cvOutputData); } } } catch (Exception e) { OpenPose.Log("Some kind of unexpected error happened."); this.Stop(); OpenPose.Error(e.Message, -1, nameof(this.Work)); } }
protected override void Work(Datum[] datumsPtr) { try { // User's processing here // datum.cvInputData: initial cv::Mat obtained from the frames producer (video, webcam, etc.) // datum.cvOutputData: final cv::Mat to be displayed if (datumsPtr != null) { foreach (var datum in datumsPtr) { Cv.BitwiseNot(datum.CvInputData, datum.CvOutputData); } } } catch (Exception e) { OpenPose.Log("Some kind of unexpected error happened."); this.Stop(); OpenPose.Error(e.Message, -1, nameof(this.Work)); } }
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); }
public StdSharedPtr <StdVector <StdSharedPtr <Datum> > > CreateDatum() { // Close program when empty frame if (this._Closed || this._ImageFiles.Length <= this._Counter) { OpenPose.Log("Last frame read and added to queue. Closing program after it is processed.", Priority.High); // This funtion stops this worker, which will eventually stop the whole thread system once all the // frames have been processed this._Closed = true; return(null); } else { // Create new datum var vector = new StdVector <StdSharedPtr <Datum> >(); var datumsPtr = new StdSharedPtr <StdVector <StdSharedPtr <Datum> > >(vector); datumsPtr.Get().EmplaceBack(); var datum = datumsPtr.Get().At(0); // C# cannot set pointer object by using assignment operator datum.Reset(new Datum()); // Fill datum using (var cvInputData = Cv.ImRead(this._ImageFiles[this._Counter++])) using (var inputData = OpenPose.OP_CV2OPCONSTMAT(cvInputData)) datum.Get().CvInputData = inputData; // If empty frame -> return nullptr if (datum.Get().CvInputData.Empty) { OpenPose.Log($"Empty frame detected on path: {this._ImageFiles[this._Counter - 1]}. Closing program.", Priority.High); this._Closed = true; datumsPtr = null; } return(datumsPtr); } }
protected override void Work(StdSharedPtr <Datum>[] datums) { try { // User's post-processing (after OpenPose processing & before OpenPose outputs) here // datum.cvOutputData: rendered frame with pose or heatmaps // datum.poseKeypoints: Array<float> with the estimated pose if (datums != null && datums.Length != 0) { foreach (var datum in datums) { using (var cvOutputData = OpenPose.OP_OP2CVMAT(datum.Get().CvOutputData)) Cv.BitwiseNot(cvOutputData, cvOutputData); } } } catch (Exception e) { OpenPose.Log("Some kind of unexpected error happened."); this.Stop(); OpenPose.Error(e.Message, -1, nameof(this.Work)); } }
protected override void WorkConsumer(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.Length != 0) { Cv.ImShow("User worker GUI", datumsPtr[0].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 }
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)); } }