//開放する
 public override void Close()
 {
     if (ailia_detector != IntPtr.Zero)
     {
         AiliaDetector.ailiaDestroyDetector(ailia_detector);
         ailia_detector = IntPtr.Zero;
     }
     base.Close();
 }
        private bool OpenDetector()
        {
            int status = AiliaDetector.ailiaCreateDetector(ref ailia_detector, ailia, format, channel, range, algorithm, category_n, flag);

            if (status != Ailia.AILIA_STATUS_SUCCESS)
            {
                if (logging)
                {
                    Debug.Log("ailiaCreateDetector failed " + status);
                }
                Close();
                return(false);
            }
            return(true);
        }
        private List <AiliaDetector.AILIADetectorObject> ComputeFromImageWithFormat(Color32[] camera, int tex_width, int tex_height, float threshold, float iou, uint format)
        {
            if (ailia_detector == IntPtr.Zero)
            {
                return(null);
            }

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

            //画像認識を行ってカテゴリを表示
            int status = AiliaDetector.ailiaDetectorCompute(ailia_detector, preview_buf_ptr, (UInt32)tex_width * 4, (UInt32)tex_width, (UInt32)tex_height, format, threshold, iou);

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

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

            AiliaDetector.ailiaDetectorGetObjectCount(ailia_detector, ref count);
            for (uint i = 0; i < count; i++)
            {
                AiliaDetector.AILIADetectorObject detector_obj = new AiliaDetector.AILIADetectorObject();
                status = AiliaDetector.ailiaDetectorGetObject(ailia_detector, detector_obj, (uint)i, AiliaClassifier.AILIA_CLASSIFIER_CLASS_VERSION);
                if (status != Ailia.AILIA_STATUS_SUCCESS)
                {
                    if (logging)
                    {
                        Debug.Log("ailiaDetectorGetObject failed " + status);
                    }
                    break;
                }
                result_list.Add(detector_obj);
            }

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

            return(result_list);
        }
        //YoloV3の入力形状を設定する
        public bool SetInputShape(uint x, uint y)
        {
            if (ailia_detector == IntPtr.Zero)
            {
                if (logging)
                {
                    Debug.Log("ailia_detector must be opened");
                }
                return(false);
            }
            int status = AiliaDetector.ailiaDetectorSetInputShape(ailia_detector, x, y);

            if (status != Ailia.AILIA_STATUS_SUCCESS)
            {
                if (logging)
                {
                    Debug.Log("ailiaDetectorSetInputShape failed " + status);
                }
                return(false);
            }
            return(true);
        }
        //YoloV2などのためにアンカーズ(anchors又はbiases)の情報を設定する
        public bool Anchors(float[] anchors)
        {
            UInt32 anchors_count = (UInt32)(anchors.Length / 2);

            if (ailia_detector == IntPtr.Zero)
            {
                if (logging)
                {
                    Debug.Log("ailia_detector must be opened");
                }
                return(false);
            }
            int status = AiliaDetector.ailiaDetectorSetAnchors(ailia_detector, anchors, anchors_count);

            if (status != Ailia.AILIA_STATUS_SUCCESS)
            {
                if (logging)
                {
                    Debug.Log("ailiaDetectorSetAnchors failed " + status);
                }
                return(false);
            }
            return(true);
        }