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.
18 using System.Runtime.InteropServices;
19 using Tizen.Multimedia;
20 using static Interop.MediaVision;
22 namespace Tizen.Multimedia
25 /// This class represents an interface for Image objects.
27 public class Image : IDisposable
29 internal IntPtr _imageObjectHandle = IntPtr.Zero;
30 private bool _disposed = false;
33 /// Constructor of Image object class
37 int ret = Interop.MediaVision.Image.Create(out _imageObjectHandle);
38 MediaVisionErrorFactory.CheckAndThrowException(ret, "Failed to create image object");
42 /// Constructor of image object class
44 /// <param name="fileName">Name of path/file to load the image object</param>
45 public Image(string fileName)
47 int ret = Interop.MediaVision.Image.Load(fileName, out _imageObjectHandle);
48 MediaVisionErrorFactory.CheckAndThrowException(ret, "Failed to load image object from file");
52 /// Destructor of ImageObject
60 /// Sets and gets a label for the image object
67 MediaVisionError ret = (MediaVisionError)Interop.MediaVision.Image.GetLabel(_imageObjectHandle, out label);
68 if (ret != MediaVisionError.None)
70 Tizen.Log.Error(MediaVisionLog.Tag, "Failed to get label");
78 int ret = Interop.MediaVision.Image.SetLabel(_imageObjectHandle, value);
79 MediaVisionErrorFactory.CheckAndThrowException(ret, "Failed to set label");
84 /// Gets a value that determines how well an image object can be recognized.
86 public double RecognitionRate
91 MediaVisionError ret = (MediaVisionError)Interop.MediaVision.Image.GetRecognitionRate(_imageObjectHandle, out rate);
92 if (ret != MediaVisionError.None)
94 Tizen.Log.Error(MediaVisionLog.Tag, "Failed to get recognition rate, error : " + ret);
102 /// Fills the image object.\n
103 /// Extracts data from @a source image which will be needed for recognition of depicted object in @a location.
105 /// <param name="source">The source image where image object is depicted</param>
106 /// <param name="config">The configuration of engine which will be used for extract recognition data from source. If NULL, then default settings will be used.</param>
107 /// <param name="location">Location of the image object on the source image, or NULL if the object is shown in full</param>
108 public void Fill(MediaVisionSource source, ImageEngineConfiguration config = null, Rectangle location = null)
112 throw new ArgumentException("Inalid source");
115 IntPtr locationPtr = IntPtr.Zero;
116 if (location != null)
118 Interop.MediaVision.Rectangle rectangle = new Interop.MediaVision.Rectangle()
120 width = location.Width,
121 height = location.Height,
122 x = location.Point.X,
125 locationPtr = Marshal.AllocHGlobal(Marshal.SizeOf(rectangle));
126 Marshal.StructureToPtr(rectangle, locationPtr, false);
129 int ret = Interop.MediaVision.Image.Fill(_imageObjectHandle,
130 (config != null) ? config._engineHandle : IntPtr.Zero,
131 source._sourceHandle, locationPtr);
132 MediaVisionErrorFactory.CheckAndThrowException(ret, "Failed to fill the image object");
136 /// Saves the image object.
138 /// <param name="fileName">Name of the file to path/save the image object</param>
139 public void Save(string fileName)
141 if (string.IsNullOrEmpty(fileName))
143 throw new ArgumentException("Inalid file name");
146 int ret = Interop.MediaVision.Image.Save(fileName, _imageObjectHandle);
147 MediaVisionErrorFactory.CheckAndThrowException(ret, "Failed to save the image object");
150 public void Dispose()
153 GC.SuppressFinalize(this);
156 protected virtual void Dispose(bool disposing)
165 // Free managed objects
168 Interop.MediaVision.Image.Destroy(_imageObjectHandle);