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.Vision
24 /// Represents the image tracking model interface.
26 /// <since_tizen> 3 </since_tizen>
27 public class ImageTrackingModel : IDisposable
29 private IntPtr _handle = IntPtr.Zero;
30 private bool _disposed = false;
33 /// Initializes a new instance of the <see cref="ImageTrackingModel"/> class.
35 /// <exception cref="NotSupportedException">The feature is not supported.</exception>
36 /// <since_tizen> 3 </since_tizen>
37 public ImageTrackingModel()
39 InteropModel.Create(out _handle).Validate("Failed to create FaceTrackingModel");
43 /// Initializes a new instance of the <see cref="ImageTrackingModel"/> class with the specified path.
46 /// Model saved by <see cref="Save(string)"/> can be loaded.
48 /// <param name="modelPath">Path to the model to load.</param>
49 /// <exception cref="ArgumentNullException"><paramref name="modelPath"/> is null.</exception>
50 /// <exception cref="FileNotFoundException"><paramref name="modelPath"/> is invalid.</exception>
51 /// <exception cref="NotSupportedException">
52 /// The feature is not supported.\n
54 /// <paramref name="modelPath"/> is not supported format.
56 /// <exception cref="UnauthorizedAccessException">No permission to access the specified file.</exception>
57 /// <seealso cref="Save(string)"/>
58 /// <since_tizen> 3 </since_tizen>
59 public ImageTrackingModel(string modelPath)
61 if (modelPath == null)
63 throw new ArgumentNullException(nameof(modelPath));
65 InteropModel.Load(modelPath, out _handle).Validate("Failed to load ImageTrackingModel from file");
69 /// Finalizes an instance of the ImageTrackingModel class.
77 /// Sets the target of the image tracking model.\n
78 /// Sets the image object which will be tracked by using tracking functionality with this tracking model.
80 /// <param name="imageObject">Image object which will be set as the target for tracking.</param>
81 /// <exception cref="ArgumentNullException"><paramref name="imageObject"/> is null.</exception>
82 /// <exception cref="ObjectDisposedException">
83 /// The <see cref="ImageTrackingModel"/> has already been disposed of.\n
85 /// <paramref name="imageObject"/> has already been disposed of.
87 /// <since_tizen> 3 </since_tizen>
88 public void SetTarget(ImageObject imageObject)
90 if (imageObject == null)
92 throw new ArgumentNullException(nameof(imageObject));
95 InteropModel.SetTarget(imageObject.Handle, Handle).
96 Validate("Failed to set target of image tracking model");
100 /// Refreshes the state of image tracking model.\n
101 /// Clears the moving history and change state to undetected. It is usually called each time before tracking is started
102 /// for the new sequence of sources, which is not the direct continuation of the sequence for which tracking has been performed before.
103 /// Tracking algorithm will try to find image by itself.
105 /// <exception cref="ObjectDisposedException">The <see cref="ImageTrackingModel"/> has already been disposed of.</exception>
106 /// <since_tizen> 3 </since_tizen>
107 public void Refresh()
109 InteropModel.Refresh(Handle, IntPtr.Zero).Validate("Failed to refresh state");
113 /// Saves the tracking model to the file.
115 /// <param name="path">Path to the file to save the model.</param>
116 /// <exception cref="ArgumentNullException"><paramref name="path"/> is null.</exception>
117 /// <exception cref="UnauthorizedAccessException">No permission to write to the specified path.</exception>
118 /// <exception cref="ObjectDisposedException">The <see cref="ImageTrackingModel"/> has already been disposed of.</exception>
119 /// <exception cref="DirectoryNotFoundException">The directory for <paramref name="path"/> does not exist.</exception>
120 /// <since_tizen> 3 </since_tizen>
121 public void Save(string path)
125 throw new ArgumentNullException(path);
128 var ret = InteropModel.Save(path, Handle);
130 if (ret == MediaVisionError.InvalidPath)
132 throw new DirectoryNotFoundException($"The directory for the path({path}) does not exist.");
135 ret.Validate("Failed to save tracking model to file");
139 /// Releases all resources used by the <see cref="ImageTrackingModel"/> object.
141 public void Dispose()
144 GC.SuppressFinalize(this);
148 /// Releases the resources used by the <see cref="ImageTrackingModel"/> object.
150 /// <param name="disposing">
151 /// true to release both managed and unmanaged resources; otherwise false to release only unmanaged resources.
153 protected virtual void Dispose(bool disposing)
160 InteropModel.Destroy(_handle);
164 internal IntPtr Handle
170 throw new ObjectDisposedException(nameof(ImageTrackingModel));