Example #1
0
        private void Update()
        {
            // New data received
            if (OPWrapper.OPGetOutput(out datum))
            {
                // Draw human in data
                for (int i = 0; i < humans.Count; i++)
                {
                    humans[i].DrawHuman(ref datum, i);
                }

                // Draw image
                imageRenderer.UpdateImage(ref datum);

                // Calculate framerate
                if (lastFrameTime > 0f)
                {
                    if (avgFrameTime < 0f)
                    {
                        avgFrameTime = Time.time - lastFrameTime;
                    }
                    else
                    {
                        avgFrameTime = Mathf.Lerp(Time.time - lastFrameTime, avgFrameTime, frameRateSmoothRatio);
                        avgFrameRate = 1f / avgFrameTime;
                    }
                }
                lastFrameTime = Time.time;
            }
        }
        private void Update()
        {
            if (Input.GetKeyDown(KeyCode.Escape))
            {
                Application.Quit();
            }
            // New data received
            if (OPWrapper.OPGetOutput(out datum))
            {
                // Draw human in data
                int i = 0;
                foreach (var human in humanContainer.GetComponentsInChildren <HumanController2D>())
                {
                    human.DrawHuman(ref datum, i++, renderThreshold);
                    animationTest.TestAnimation(ref datum);
                }

                // Calculate framerate
                if (lastFrameTime > 0f)
                {
                    if (avgFrameTime < 0f)
                    {
                        avgFrameTime = Time.time - lastFrameTime;
                    }
                    else
                    {
                        avgFrameTime = Mathf.Lerp(Time.time - lastFrameTime, avgFrameTime, frameRateSmoothRatio);
                        avgFrameRate = 1f / avgFrameTime;
                    }
                }
                lastFrameTime = Time.time;
                fpsText.text  = avgFrameRate.ToString("F1") + " FPS";
            }
        }
        private void Update()
        {
            // Update state in UI
            stateText.text = OPWrapper.state.ToString();

            // Try getting new frame
            if (OPWrapper.OPGetOutput(out datum))  // true: has new frame data

            // Update background image
            {
                bgImageRenderer.UpdateImage(datum.cvInputData);

                // Rescale output UI
                Vector2 outputSize = outputTransform.sizeDelta;
                Vector2 screenSize = OpenPoseCamera.pixelRect.size;
                float   scale      = Mathf.Min(screenSize.x / outputSize.x, screenSize.y / outputSize.y);
                outputTransform.localScale = new Vector3(scale, scale, scale);

                // Update number of people in UI
                if (datum.poseKeypoints == null || datum.poseKeypoints.Empty())
                {
                    numberPeople = 0;
                }
                else
                {
                    numberPeople = datum.poseKeypoints.GetSize(0);
                }
                peopleText.text = "People: " + numberPeople;

                // Draw human
                while (humanContainer.childCount < numberPeople)   // Make sure no. of HumanControllers no less than numberPeople
                {
                    humanPrefab.name = humanPrefab.name + "_" + numberPeople.ToString();
                    Instantiate(humanPrefab, humanContainer);
                }
                int i = 0;
                foreach (var human in humanContainer.GetComponentsInChildren <HumanController2D>())
                {
                    // When i >= no. of human, the human will be hidden
                    human.DrawHuman(ref datum, i++, renderThreshold);
                }

                // Update framerate in UI
                frameTimeQueue.Enqueue(Time.time);
                frameCounter++;
                if (frameTimeQueue.Count > queueMaxCount)  // overflow
                {
                    frameTimeQueue.Dequeue();
                }
                if (frameCounter >= queueMaxCount || frameTimeQueue.Count <= 5)  // update frame rate
                {
                    frameCounter = 0;
                    avgFrameRate = frameTimeQueue.Count / (Time.time - frameTimeQueue.Peek());
                    fpsText.text = avgFrameRate.ToString("F1") + " FPS";
                }
            }
        }
Example #4
0
 private void Start()
 {
     // Configure openpose with default value
     OPWrapper.OPConfigureAllInDefault();
     // Enable openpose log to unity
     OPWrapper.OPEnableDebug(true);
     // Enable openpose output to unity
     OPWrapper.OPEnableOutput(true);
     // Start openpose
     OPWrapper.OPRun();
 }
Example #5
0
        // User can change the settings here
        private void UserConfigureOpenPose()
        {
            OPWrapper.OPConfigurePose(
                /* poseMode */ PoseMode.Enabled, /* netInputSize */ netResolution, /* outputSize */ null,
                /* keypointScaleMode */ ScaleMode.InputResolution,
                /* gpuNumber */ -1, /* gpuNumberStart */ 0, /* scalesNumber */ 1, /* scaleGap */ 0.3f,
                /* renderMode */ RenderMode.Gpu, /* poseModel */ PoseModel.BODY_25,
                /* blendOriginalFrame */ true, /* alphaKeypoint */ 0.6f, /* alphaHeatMap */ 0.7f,
                /* defaultPartToRender */ 0, /* modelFolder */ null,
                /* heatMapTypes */ HeatMapType.None, /* heatMapScaleMode */ ScaleMode.UnsignedChar,
                /* addPartCandidates */ false, /* renderThreshold */ renderThreshold, /* numberPeopleMax */ maxPeople,
                /* maximizePositives */ false, /* fpsMax fps_max */ -1.0,
                /* protoTxtPath */ "", /* caffeModelPath */ "", /* upsamplingRatio */ 0f);

            OPWrapper.OPConfigureHand(
                /* enable */ handEnabled, /* detector */ Detector.Body, /* netInputSize */ handResolution,
                /* scalesNumber */ 1, /* scaleRange */ 0.4f, /* renderMode */ RenderMode.None,
                /* alphaKeypoint */ 0.6f, /* alphaHeatMap */ 0.7f, /* renderThreshold */ 0.2f);

            OPWrapper.OPConfigureFace(
                /* enable */ faceEnabled, /* detector */ Detector.Body,
                /* netInputSize */ faceResolution, /* renderMode */ RenderMode.None,
                /* alphaKeypoint */ 0.6f, /* alphaHeatMap */ 0.7f, /* renderThreshold */ 0.4f);

            OPWrapper.OPConfigureExtra(
                /* reconstruct3d */ false, /* minViews3d */ -1, /* identification */ false, /* tracking */ -1,
                /* ikThreads */ 0);

            OPWrapper.OPConfigureInput(
                /* producerType */ inputType, /* producerString */ producerString,
                /* frameFirst */ 0, /* frameStep */ 1, /* frameLast */ ulong.MaxValue,
                /* realTimeProcessing */ false, /* frameFlip */ false,
                /* frameRotate */ 0, /* framesRepeat */ false,
                /* cameraResolution */ null, /* cameraParameterPath */ null,
                /* undistortImage */ false, /* numberViews */ -1);

            OPWrapper.OPConfigureOutput(
                /* verbose */ -1.0, /* writeKeypoint */ "", /* writeKeypointFormat */ DataFormat.Yml,
                /* writeJson */ "", /* writeCocoJson */ "", /* writeCocoFootJson */ "",
                /* writeCocoJsonVariant */ 1, /* writeImages */ "", /* writeImagesFormat */ "png",
                /* writeVideo */ "", /* writeVideoFps */ 30.0, /* writeVideoWithAudio */ false,
                /* writeHeatMaps */ "", /* writeHeatMapsFormat */ "png", /* writeVideo3D */ "",
                /* writeVideoAdam */ "", /* writeBvh */ "", /* udpHost */ "", /* udpPort */ "8051");

            OPWrapper.OPConfigureGui(
                /* displayMode */ DisplayMode.NoDisplay, /* guiVerbose */ false, /* fullScreen */ false);

            OPWrapper.OPConfigureDebugging(
                /* loggingLevel */ Priority.High, /* disableMultiThread */ false, /* profileSpeed */ 1000);
        }
Example #6
0
 private void Start()
 {
     // Configure OpenPose with default value,
     //OPWrapper.OPConfigureAllInDefault();
     // or using specific configuration for each
     UserConfigureOpenPose();
     // Enable OpenPose run multi-thread (default true)
     OPWrapper.OPEnableMultiThread(true);
     // Enable OpenPose log to unity (default true)
     OPWrapper.OPEnableDebug(true);
     // Enable OpenPose output to unity (default true)
     OPWrapper.OPEnableOutput(true);
     // Enable receiving image (default false)
     OPWrapper.OPEnableImageOutput(renderBgImg);
     // Start OpenPose
     OPWrapper.OPRun();
 }
Example #7
0
        // User can change the settings here
        private void UserConfigureOpenPose()
        {
            OPWrapper.OPConfigurePose(
                /* body_disable */ false, /* net_resolution */ netResolution, /* output_resolution */ null,
                /* keypoint_scale_mode */ ScaleMode.InputResolution,
                /* num_gpu */ -1, /* num_gpu_start */ 0, /* scale_number */ 1, /* scale_gap */ 0.3f,
                /* pose_render_mode */ RenderMode.Gpu, /* model_pose */ PoseModel.BODY_25,
                /* disable_blending */ false, /* alpha_pose */ 0.6f, /* alpha_heatmap */ 0.7f,
                /*t part_to_show */ 0, /* model_folder */ null,
                /* heatmap_type */ HeatMapType.None, /* heatmap_scale_mode */ ScaleMode.UnsignedChar,
                /* part_candidates */ false, /* render_threshold */ renderThreshold, /* number_people_max */ maxPeople);

            OPWrapper.OPConfigureHand(
                /* hand */ handEnabled, /* hand_net_resolution */ handResolution,
                /* hand_scale_number */ 1, /* hand_scale_range */ 0.4f, /* hand_tracking */ false,
                /* hand_render_mode */ RenderMode.None,
                /* hand_alpha_pose */ 0.6f, /* hand_alpha_heatmap */ 0.7f, /* hand_render_threshold */ 0.2f);

            OPWrapper.OPConfigureFace(
                /* face */ faceEnabled, /* face_net_resolution */ faceResolution,
                /* face_render_mode */ RenderMode.None,
                /* face_alpha_pose */ 0.6f, /* face_alpha_heatmap */ 0.7f, /* face_render_threshold */ 0.4f);

            OPWrapper.OPConfigureExtra(
                /* _3d */ false, /* _3d_min_views */ -1, /* _identification */ false, /* _tracking */ -1, /* _ik_threads */ 0);

            OPWrapper.OPConfigureInput(
                /* producer_type */ inputType, /* producer_string */ producerString,
                /* frame_first */ 0, /* frame_step */ 1, /* frame_last */ ulong.MaxValue,
                /* process_real_time */ false, /* frame_flip */ false,
                /* frame_rotate */ 0, /* frames_repeat */ false,
                /* camera_resolution */ null, /* camera_parameter_path */ null,
                /* undistort_image */ true, /* image_directory_stereo */ 1);

            OPWrapper.OPConfigureOutput(
                /* verbose */ -1.0, /* write_keypoint */ "", /* write_keypoint_format */ DataFormat.Yml,
                /* write_json */ "", /* write_coco_json */ "", /* write_coco_foot_json */ "", /* write_coco_json_variant */ 1,
                /* write_images */ "", /* write_images_format */ "png", /* write_video */ "",
                /* camera_fps */ 30.0, /* write_heatmaps */ "", /* write_heatmaps_format */ "png",
                /* write_video_adam */ "", /* write_bvh */ "", /* udp_host */ "", /* udp_port */ "8051");

            OPWrapper.OPConfigureGui(
                /* display_mode */ DisplayMode.NoDisplay,
                /* gui_verbose */ false, /* full_screen */ false);
        }
Example #8
0
        private IEnumerator UserRebootOpenPoseCoroutine()
        {
            if (OPWrapper.state == OPState.None)
            {
                yield break;
            }
            // Shutdown if running
            if (OPWrapper.state == OPState.Running)
            {
                OPWrapper.OPShutdown();
            }
            // Wait until fully stopped
            yield return(new WaitUntil(() => { return OPWrapper.state == OPState.Ready; }));

            // Configure and start
            UserConfigureOpenPose();
            OPWrapper.OPRun();
        }
Example #9
0
        private void Start()
        {
            // Register callbacks
            OPWrapper.OPRegisterCallbacks();
            // Enable OpenPose log to unity (default true)
            OPWrapper.OPEnableDebug(true);
            // Enable OpenPose output to unity (default true)
            OPWrapper.OPEnableOutput(true);
            // Enable receiving image (default false)
            OPWrapper.OPEnableImageOutput(renderBgImg);

            // Configure OpenPose with default value, or using specific configuration for each
            /* OPWrapper.OPConfigureAllInDefault(); */
            UserConfigureOpenPose();

            // Start OpenPose
            OPWrapper.OPRun();
        }
        private void Update()
        {
            // New data received
            if (OPWrapper.OPGetOutput(out datum))
            {
                // Draw human in data
                int i = 0;
                foreach (var human in humanContainer.GetComponentsInChildren <HumanController2D>())
                {
                    human.DrawHuman(ref datum, i++, renderThreshold);
                }

                // Draw image
                imageRenderer.UpdateImage(datum.cvInputData);

                // Number of people
                if (datum.poseKeypoints == null || datum.poseKeypoints.Empty())
                {
                    numberPeople = 0;
                }
                else
                {
                    numberPeople = datum.poseKeypoints.GetSize(0);
                }
                peopleText.text = "People: " + numberPeople;

                // Calculate framerate
                if (lastFrameTime > 0f)
                {
                    if (avgFrameTime < 0f)
                    {
                        avgFrameTime = Time.time - lastFrameTime;
                    }
                    else
                    {
                        avgFrameTime = Mathf.Lerp(Time.time - lastFrameTime, avgFrameTime, frameRateSmoothRatio);
                        avgFrameRate = 1f / avgFrameTime;
                    }
                }
                lastFrameTime = Time.time;
                fpsText.text  = avgFrameRate.ToString("F1") + " FPS";
            }
        }
        private void Update()
        {
            // Try getting new frame
            if (OPWrapper.OPGetOutput(out datum))  // true: has new frame data

            // Draw human in data
            {
                int i = 0;
                foreach (var human in humanContainer.GetComponentsInChildren <HumanController2D>())
                {
                    human.DrawHuman(ref datum, i++, renderThreshold);
                }

                // Draw image
                imageRenderer.UpdateImage(datum.cvInputData);

                // Number of people
                if (datum.poseKeypoints == null || datum.poseKeypoints.Empty())
                {
                    numberPeople = 0;
                }
                else
                {
                    numberPeople = datum.poseKeypoints.GetSize(0);
                }
                peopleText.text = "People: " + numberPeople;

                // Calculate framerate
                frameTimeQueue.Enqueue(Time.time);
                frameCounter++;
                if (frameTimeQueue.Count > queueMaxCount)  // overflow
                {
                    frameTimeQueue.Dequeue();
                }
                if (frameCounter >= queueMaxCount || frameTimeQueue.Count <= 5)  // update frame rate
                {
                    frameCounter = 0;
                    avgFrameRate = frameTimeQueue.Count / (Time.time - frameTimeQueue.Peek());
                    fpsText.text = avgFrameRate.ToString("F1") + " FPS";
                }
            }
        }
Example #12
0
        private void Start()
        {
            // Register callbacks
            OPWrapper.OPRegisterCallbacks();
            // Enable OpenPose log to unity (default true)
            OPWrapper.OPEnableDebug(true);
            // Enable OpenPose output to unity (default true)
            OPWrapper.OPEnableOutput(true);
            // Enable receiving image (default false)
            OPWrapper.OPEnableImageOutput(true);

            // Configure OpenPose with default value, or using specific configuration for each
            /* OPWrapper.OPConfigureAllInDefault(); */
            UserConfigureOpenPose();

            // Start OpenPose
            OPWrapper.OPRun();

            patientInfo   = GameObject.Find("Text");
            patientLabels = GameObject.Find("Label");
            redScene      = GameObject.Find("RedScene");
            labelBG       = GameObject.Find("Labelbg");
            labelBG.SetActive(false);
        }
Example #13
0
 public void ToggleRenderBgImg()
 {
     renderBgImg = !renderBgImg;
     OPWrapper.OPEnableImageOutput(renderBgImg);
     imageRenderer.FadeInOut(renderBgImg);
 }
Example #14
0
        private void Update()
        {
            // Update state in UI
            stateText.text = OPWrapper.state.ToString();

            // Try getting new frame
            if (OPWrapper.OPGetOutput(out datum))  // true: has new frame data

            //Debug.Log(datum.poseKeypoints);

            // Update background image
            {
                bgImageRenderer.UpdateImage(datum.cvInputData);

                // Rescale output UI
                Vector2 outputSize = outputTransform.sizeDelta;
                Vector2 screenSize = Camera.main.pixelRect.size;
                float   scale      = Mathf.Min(screenSize.x / outputSize.x, screenSize.y / outputSize.y);
                outputTransform.localScale = new Vector3(scale, scale, scale);

                // Update number of people in UI
                if (datum.poseKeypoints == null || datum.poseKeypoints.Empty())
                {
                    numberPeople = 0;
                    if (count > 30)
                    {
                        patientInfo.GetComponent <Text>().text   = "";
                        patientLabels.GetComponent <Text>().text = "";
                        //redScene.SetActive(false);
                        labelBG.SetActive(false);
                        count = 0;
                        flag  = false;
                    }
                    count++;
                    chk_count = 0;
                }
                else
                {
                    if (flag == false)
                    {
                        randomIdx = Random.Range(0, 4);
                        //patientName = names[randomIdx];
                        //patientDisease = diseases[randomIdx];
                        age  = Random.Range(50, 100);
                        flag = true;
                    }
                    count        = 0;
                    numberPeople = datum.poseKeypoints.GetSize(0);
                    Discriminate dc = ShowListContentsInTheDebugLog(datum.poseKeypoints);
                    if (dc.status)
                    {
                        nfPos   = patientInfo.transform.position;
                        nfPos.x = -90;
                        nfPos.y = 80;
                        //Debug.Log(nfPos.x);
                        //Debug.Log(nfPos.y);
                        patientInfo.transform.position           = nfPos;
                        patientInfo.GetComponent <Text>().text   = "Fallen";
                        patientLabels.GetComponent <Text>().text = "Name: Ken\nAge: 72\nDisease: cancer";

                        //redScene.SetActive(true);
                        labelBG.SetActive(true);

                        //GameObject fps = GameObject.Find("FPS");
                        //Debug.Log(fps.transform.position.x);
                        //Debug.Log(fps.transform.position.y);

                        //GameObject ppl = GameObject.Find("People");
                        //Debug.Log(ppl.transform.position.x);
                        //Debug.Log(ppl.transform.position.y);
                    }
                    chk_count++;
                }
                peopleText.text = "People: " + numberPeople;

                // Draw human
                while (humanContainer.childCount < numberPeople)
                { // Make sure no. of HumanControllers no less than numberPeople
                    Instantiate(humanPrefab, humanContainer);
                }
                int i = 0;
                foreach (var human in humanContainer.GetComponentsInChildren <HumanController2D>())
                {
                    // When i >= no. of human, the human will be hidden
                    human.DrawHuman(ref datum, i++, renderThreshold);
                }

                // Update framerate in UI
                frameTimeQueue.Enqueue(Time.time);
                frameCounter++;
                if (frameTimeQueue.Count > queueMaxCount)  // overflow
                {
                    frameTimeQueue.Dequeue();
                }
                if (frameCounter >= queueMaxCount || frameTimeQueue.Count <= 5)  // update frame rate
                {
                    frameCounter = 0;
                    avgFrameRate = frameTimeQueue.Count / (Time.time - frameTimeQueue.Peek());
                    fpsText.text = avgFrameRate.ToString("F1") + " FPS";
                }
            }
        }