//開放する public override void Close() { if (ailia_classifier != IntPtr.Zero) { AiliaClassifier.ailiaDestroyClassifier(ailia_classifier); ailia_classifier = IntPtr.Zero; } base.Close(); }
private bool OpenClassifier() { int status = AiliaClassifier.ailiaCreateClassifier(ref ailia_classifier, ailia, format, channel, range); if (status != Ailia.AILIA_STATUS_SUCCESS) { if (logging) { Debug.Log("ailiaCreateClassifier failed " + status); } Close(); return(false); } return(true); }
private List <AiliaClassifier.AILIAClassifierClass> ComputeFromImageWithFormat(Color32[] camera, int tex_width, int tex_height, uint max_class_count, uint format) { if (ailia_classifier == 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 = AiliaClassifier.ailiaClassifierCompute(ailia_classifier, preview_buf_ptr, (UInt32)tex_width * 4, (UInt32)tex_width, (UInt32)tex_height, format, max_class_count); if (status != Ailia.AILIA_STATUS_SUCCESS) { if (logging) { Debug.Log("ailiaClassifierCompute failed " + status); } return(null); } //推論結果を表示 List <AiliaClassifier.AILIAClassifierClass> result_list = new List <AiliaClassifier.AILIAClassifierClass>(); for (int i = 0; i < max_class_count; i++) { AiliaClassifier.AILIAClassifierClass classifier_obj = new AiliaClassifier.AILIAClassifierClass(); status = AiliaClassifier.ailiaClassifierGetClass(ailia_classifier, classifier_obj, (uint)i, AiliaClassifier.AILIA_CLASSIFIER_CLASS_VERSION); if (status != Ailia.AILIA_STATUS_SUCCESS) { if (logging) { Debug.Log("ailiaClassifierGetClass failed" + status); } break; } result_list.Add(classifier_obj); } //バッファの開放 preview_handle.Free(); return(result_list); }