2 * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved
4 * Licensed under the Apache License, Version 2.0 (the License);
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an AS IS BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
19 using InteropModel = Interop.MediaVision.ImageTrackingModel;
21 namespace Tizen.Multimedia
24 /// Represents the image tracking model interface.
26 public class ImageTrackingModel : IDisposable
28 private IntPtr _handle = IntPtr.Zero;
29 private bool _disposed = false;
32 /// Initializes a new instance of the <see cref="ImageTrackingModel"/> class.
34 /// <exception cref="NotSupportedException">The feature is not supported.</exception>
35 public ImageTrackingModel()
37 InteropModel.Create(out _handle).Validate("Failed to create FaceTrackingModel");
41 /// Initializes a new instance of the <see cref="ImageTrackingModel"/> class with the specified path.
44 /// Model have been saved by <see cref="Save()"/> can be loaded.
46 /// <param name="modelPath">Path to the model to load.</param>
47 /// <exception cref="ArgumentNullException"><paramref name="modelPath"/> is null.</exception>
48 /// <exception cref="System.IO.FileNotFoundException"><paramref name="modelPath"/> is invalid.</exception>
49 /// <exception cref="NotSupportedException">
50 /// The feature is not supported.\n
52 /// <paramref name="modelPath"/> is not supported format.
54 /// <exception cref="UnauthorizedAccessException">No permission to access the specified file.</exception>
55 /// <seealso cref="Save()"/>
56 public ImageTrackingModel(string modelPath)
58 if (modelPath == null)
60 throw new ArgumentNullException(nameof(modelPath));
62 InteropModel.Load(modelPath, out _handle).Validate("Failed to load ImageTrackingModel from file");
71 /// Sets target of image tracking model.\n
72 /// Sets image object which will be tracked by using tracking functionality with this tracking model.
74 /// <param name="imageObject">Image object which will be set as the target for tracking.</param>
75 /// <exception cref="ArgumentNullException"><paramref name="imageObject"/> is null.</exception>
76 /// <exception cref="ObjectDisposedException">
77 /// The <see cref="ImageTrackingModel"/> has already been disposed of.\n
79 /// <paramref name="imageObject"/> has already been disposed of.
81 public void SetTarget(ImageObject imageObject)
83 if (imageObject == null)
85 throw new ArgumentNullException(nameof(imageObject));
88 InteropModel.SetTarget(imageObject.Handle, Handle).
89 Validate("Failed to set target of image tracking model");
93 /// Refreshes the state of image tracking model.\n
94 /// Clears moving history and change state to undetected. It is usually called each time before tracking is started
95 /// for the new sequence of sources which is not the direct continuation of the sequence for which tracking has been performed before.
96 /// Tracking algorithm will try to find image by itself.
98 /// <exception cref="ObjectDisposedException">The <see cref="ImageTrackingModel"/> has already been disposed of.</exception>
101 InteropModel.Refresh(Handle, IntPtr.Zero).Validate("Failed to refresh state");
105 /// Saves tracking model to the file.
107 /// <param name="path">Path to the file to save the model.</param>
108 /// <exception cref="ArgumentNullException"><paramref name="path"/> is null.</exception>
109 /// <exception cref="UnauthorizedAccessException">No permission to write to the specified path.</exception>
110 /// <exception cref="ObjectDisposedException">The <see cref="ImageTrackingModel"/> has already been disposed of.</exception>
111 /// <exception cref="DirectoryNotFoundException">The directory for <paramref name="path"/> does not exist.</exception>
112 public void Save(string path)
116 throw new ArgumentNullException(path);
119 var ret = InteropModel.Save(path, Handle);
121 if (ret == MediaVisionError.InvalidPath)
123 throw new DirectoryNotFoundException($"The directory for the path({path}) does not exist.");
126 ret.Validate("Failed to save tracking model to file");
129 public void Dispose()
132 GC.SuppressFinalize(this);
135 protected virtual void Dispose(bool disposing)
142 InteropModel.Destroy(_handle);
146 internal IntPtr Handle
152 throw new ObjectDisposedException(nameof(ImageTrackingModel));