private List <AiliaPoseEstimator.AILIAPoseEstimatorObjectPose> ComputePoseFromImageWithFormat(Color32[] camera, int tex_width, int tex_height, uint format)
        {
            if (ailia_pose_estimator == IntPtr.Zero)
            {
                return(null);
            }

            //バッファの固定
            GCHandle preview_handle  = GCHandle.Alloc(camera, GCHandleType.Pinned);
            IntPtr   preview_buf_ptr = preview_handle.AddrOfPinnedObject();

            //画像認識を行ってカテゴリを表示
            //Unityのカメラ画像は上下反転しているのでAILIA_IMAGE_FORMAT_RGBA_B2Tを指定
            int status = AiliaPoseEstimator.ailiaPoseEstimatorCompute(ailia_pose_estimator, preview_buf_ptr, (UInt32)tex_width * 4, (UInt32)tex_width, (UInt32)tex_height, format);

            if (status != Ailia.AILIA_STATUS_SUCCESS)
            {
                if (logging)
                {
                    Debug.Log("ailiaPoseEstimatorCompute failed " + status);
                }
                return(null);
            }

            //推論結果を表示
            List <AiliaPoseEstimator.AILIAPoseEstimatorObjectPose> result_list = new List <AiliaPoseEstimator.AILIAPoseEstimatorObjectPose>();
            uint count = 0;

            AiliaPoseEstimator.ailiaPoseEstimatorGetObjectCount(ailia_pose_estimator, ref count);
            for (int i = 0; i < count; i++)
            {
                AiliaPoseEstimator.AILIAPoseEstimatorObjectPose classifier_obj = new AiliaPoseEstimator.AILIAPoseEstimatorObjectPose();
                status = AiliaPoseEstimator.ailiaPoseEstimatorGetObjectPose(ailia_pose_estimator, classifier_obj, (uint)i, AiliaPoseEstimator.AILIA_POSE_ESTIMATOR_OBJECT_POSE_VERSION);
                if (status != Ailia.AILIA_STATUS_SUCCESS)
                {
                    if (logging)
                    {
                        Debug.Log("ailiaPoseEstimatorGetObjectPose failed" + status);
                    }
                    break;
                }
                result_list.Add(classifier_obj);
            }

            //バッファの開放
            preview_handle.Free();

            return(result_list);
        }
예제 #2
0
        public void DrawBone(Color32 color, int tex_width, int tex_height, AiliaPoseEstimator.AILIAPoseEstimatorObjectPose obj, uint from, uint to, int r)
        {
            float th = 0.1f;

            if (obj.points[from].score <= th || obj.points[to].score <= th)
            {
                return;
            }

            int from_x = (int)(tex_width * obj.points[from].x);
            int from_y = (int)(tex_height * obj.points[from].y);
            int to_x   = (int)(tex_width * obj.points[to].x);
            int to_y   = (int)(tex_height * obj.points[to].y);

            int len = (to_x - from_x) * (to_x - from_x) + (to_y - from_y) * (to_y - from_y);

            len = (int)Mathf.Sqrt(len);

            DrawLine(color, from_x, from_y, obj.points[from].z_local, to_x, to_y, obj.points[to].z_local, tex_width, tex_height);
        }
예제 #3
0
        // Update is called once per frame
        void Update()
        {
            if (!ailia_camera.IsEnable())
            {
                return;
            }
            if (!FileOpened)
            {
                return;
            }

            //Clear label
            Clear();

            //Capture
            int tex_width  = ailia_camera.GetWidth();
            int tex_height = ailia_camera.GetHeight();

            if (preview_texture == null)
            {
                preview_texture   = new Texture2D(tex_width, tex_height);
                raw_image.texture = preview_texture;
            }
            Color32[] camera = ailia_camera.GetPixels32();

            //Pose estimation
            long start_time = DateTime.UtcNow.Ticks / TimeSpan.TicksPerMillisecond;;
            List <AiliaPoseEstimator.AILIAPoseEstimatorObjectPose> pose = ailia_pose.ComputePoseFromImageB2T(camera, tex_width, tex_height);
            long end_time = DateTime.UtcNow.Ticks / TimeSpan.TicksPerMillisecond;;

            for (int i = 0; i < pose.Count; i++)
            {
                AiliaPoseEstimator.AILIAPoseEstimatorObjectPose obj = pose[i];
                if (obj.total_score < 0)
                {
                    continue;
                }

                int r = 2;

                DrawBone(Color.red, tex_width, tex_height, obj, AiliaPoseEstimator.AILIA_POSE_ESTIMATOR_POSE_KEYPOINT_NOSE, AiliaPoseEstimator.AILIA_POSE_ESTIMATOR_POSE_KEYPOINT_SHOULDER_CENTER, r);
                DrawBone(Color.yellow, tex_width, tex_height, obj, AiliaPoseEstimator.AILIA_POSE_ESTIMATOR_POSE_KEYPOINT_SHOULDER_LEFT, AiliaPoseEstimator.AILIA_POSE_ESTIMATOR_POSE_KEYPOINT_SHOULDER_CENTER, r);
                DrawBone(Color.green, tex_width, tex_height, obj, AiliaPoseEstimator.AILIA_POSE_ESTIMATOR_POSE_KEYPOINT_SHOULDER_RIGHT, AiliaPoseEstimator.AILIA_POSE_ESTIMATOR_POSE_KEYPOINT_SHOULDER_CENTER, r);

                DrawBone(Color.red, tex_width, tex_height, obj, AiliaPoseEstimator.AILIA_POSE_ESTIMATOR_POSE_KEYPOINT_EYE_LEFT, AiliaPoseEstimator.AILIA_POSE_ESTIMATOR_POSE_KEYPOINT_NOSE, r);
                DrawBone(Color.red, tex_width, tex_height, obj, AiliaPoseEstimator.AILIA_POSE_ESTIMATOR_POSE_KEYPOINT_EYE_RIGHT, AiliaPoseEstimator.AILIA_POSE_ESTIMATOR_POSE_KEYPOINT_NOSE, r);
                DrawBone(Color.red, tex_width, tex_height, obj, AiliaPoseEstimator.AILIA_POSE_ESTIMATOR_POSE_KEYPOINT_EAR_LEFT, AiliaPoseEstimator.AILIA_POSE_ESTIMATOR_POSE_KEYPOINT_EYE_LEFT, r);
                DrawBone(Color.red, tex_width, tex_height, obj, AiliaPoseEstimator.AILIA_POSE_ESTIMATOR_POSE_KEYPOINT_EAR_RIGHT, AiliaPoseEstimator.AILIA_POSE_ESTIMATOR_POSE_KEYPOINT_EYE_RIGHT, r);

                DrawBone(Color.yellow, tex_width, tex_height, obj, AiliaPoseEstimator.AILIA_POSE_ESTIMATOR_POSE_KEYPOINT_ELBOW_LEFT, AiliaPoseEstimator.AILIA_POSE_ESTIMATOR_POSE_KEYPOINT_SHOULDER_LEFT, r);
                DrawBone(Color.green, tex_width, tex_height, obj, AiliaPoseEstimator.AILIA_POSE_ESTIMATOR_POSE_KEYPOINT_ELBOW_RIGHT, AiliaPoseEstimator.AILIA_POSE_ESTIMATOR_POSE_KEYPOINT_SHOULDER_RIGHT, r);
                DrawBone(Color.yellow, tex_width, tex_height, obj, AiliaPoseEstimator.AILIA_POSE_ESTIMATOR_POSE_KEYPOINT_WRIST_LEFT, AiliaPoseEstimator.AILIA_POSE_ESTIMATOR_POSE_KEYPOINT_ELBOW_LEFT, r);
                DrawBone(Color.green, tex_width, tex_height, obj, AiliaPoseEstimator.AILIA_POSE_ESTIMATOR_POSE_KEYPOINT_WRIST_RIGHT, AiliaPoseEstimator.AILIA_POSE_ESTIMATOR_POSE_KEYPOINT_ELBOW_RIGHT, r);

                DrawBone(Color.blue, tex_width, tex_height, obj, AiliaPoseEstimator.AILIA_POSE_ESTIMATOR_POSE_KEYPOINT_HIP_LEFT, AiliaPoseEstimator.AILIA_POSE_ESTIMATOR_POSE_KEYPOINT_SHOULDER_CENTER, r);
                DrawBone(Color.green, tex_width, tex_height, obj, AiliaPoseEstimator.AILIA_POSE_ESTIMATOR_POSE_KEYPOINT_HIP_RIGHT, AiliaPoseEstimator.AILIA_POSE_ESTIMATOR_POSE_KEYPOINT_SHOULDER_CENTER, r);

                DrawBone(Color.blue, tex_width, tex_height, obj, AiliaPoseEstimator.AILIA_POSE_ESTIMATOR_POSE_KEYPOINT_KNEE_LEFT, AiliaPoseEstimator.AILIA_POSE_ESTIMATOR_POSE_KEYPOINT_HIP_LEFT, r);
                DrawBone(Color.blue, tex_width, tex_height, obj, AiliaPoseEstimator.AILIA_POSE_ESTIMATOR_POSE_KEYPOINT_ANKLE_LEFT, AiliaPoseEstimator.AILIA_POSE_ESTIMATOR_POSE_KEYPOINT_KNEE_LEFT, r);
                DrawBone(Color.green, tex_width, tex_height, obj, AiliaPoseEstimator.AILIA_POSE_ESTIMATOR_POSE_KEYPOINT_KNEE_RIGHT, AiliaPoseEstimator.AILIA_POSE_ESTIMATOR_POSE_KEYPOINT_HIP_RIGHT, r);
                DrawBone(Color.green, tex_width, tex_height, obj, AiliaPoseEstimator.AILIA_POSE_ESTIMATOR_POSE_KEYPOINT_ANKLE_RIGHT, AiliaPoseEstimator.AILIA_POSE_ESTIMATOR_POSE_KEYPOINT_KNEE_RIGHT, r);
            }

            //Apply
            preview_texture.SetPixels32(camera);
            preview_texture.Apply();

            if (label_text != null)
            {
                label_text.text = "" + (end_time - start_time) + "ms\n" + ailia_pose.EnvironmentName();
            }
        }