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 static Interop.MediaVision.Surveillance;
20 namespace Tizen.Multimedia.Vision
23 /// Provides the ability to detect person appearance changes on image sources.
25 /// <feature>http://tizen.org/feature/vision.face_recognition</feature>
26 /// <feature>http://tizen.org/feature/vision.image_recognition</feature>
27 /// <seealso cref="PersonAppearanceDetectionConfiguration"/>
28 /// <since_tizen> 4 </since_tizen>
29 public class PersonAppearanceDetector : SurveillanceEngine
31 private const string KeyAppearedNumber = "NUMBER_OF_APPEARED_PERSONS";
32 private const string KeyDisappearedNumber = "NUMBER_OF_DISAPPEARED_PERSONS";
33 private const string KeyTrackedNumber = "NUMBER_OF_TRACKED_PERSONS";
34 private const string KeyAppearedLocations = "APPEARED_PERSONS_LOCATIONS";
35 private const string KeyDisappearedLocations = "DISAPPEARED_PERSONS_LOCATIONS";
36 private const string KeyTrackedLocations = "TRACKED_PERSONS_LOCATIONS";
38 private const string PersonAppearanceEventType = "MV_SURVEILLANCE_EVENT_PERSON_APPEARED_DISAPEARED";
41 /// Initializes a new instance of the <see cref="PersonAppearanceDetector"/> class.
43 /// <exception cref="NotSupportedException">The required features are not supported.</exception>
44 /// <since_tizen> 4 </since_tizen>
45 public PersonAppearanceDetector() : base(PersonAppearanceEventType)
50 /// Occurs when the any appearance changes detected.
52 /// <remarks>The event handler will be executed on an internal thread.</remarks>
53 /// <since_tizen> 4 </since_tizen>
54 public event EventHandler<PersonAppearanceDetectedEventArgs> Detected;
56 private void RegisterEvent()
58 _eventDetectedCallback = (IntPtr trigger, IntPtr source, int streamId, IntPtr result, IntPtr _) =>
60 Detected?.Invoke(this, CreatePersonAppearanceChangedEventArgs(result));
65 private PersonAppearanceDetectedEventArgs CreatePersonAppearanceChangedEventArgs(IntPtr result)
67 return new PersonAppearanceDetectedEventArgs(
68 GetResultAreas(result, KeyAppearedNumber, KeyAppearedLocations),
69 GetResultAreas(result, KeyDisappearedNumber, KeyDisappearedLocations),
70 GetResultAreas(result, KeyTrackedNumber, KeyTrackedLocations)
74 private static Rectangle[] GetResultAreas(IntPtr result, string countKey, string regionsKey)
77 GetResultValue(result, countKey, out count).Validate("Failed to get result");
79 var rects = new global::Interop.MediaVision.Rectangle[count];
82 GetResultValue(result, regionsKey, rects).Validate("Failed to get result");
85 return global::Interop.ToApiStruct(rects);
89 /// Adds <see cref="SurveillanceSource"/>.
91 /// <param name="source">The source used for recognition.</param>
92 /// <exception cref="ArgumentNullException"><paramref name="source"/> is null.</exception>
93 /// <exception cref="ObjectDisposedException">The <see cref="PersonAppearanceDetector"/> has already been disposed of.</exception>
94 /// <see cref="SurveillanceSource.Push(MediaVisionSource)"/>
95 /// <since_tizen> 4 </since_tizen>
96 public void AddSource(SurveillanceSource source)
98 AddSource(source, null);
102 /// Adds <see cref="SurveillanceSource"/> with the provided <see cref="PersonAppearanceDetectionConfiguration"/>.
104 /// <param name="source">The source used for recognition.</param>
105 /// <param name="config">The config for the <paramref name="source"/>. This value can be null.</param>
106 /// <exception cref="ArgumentNullException"><paramref name="source"/> is null.</exception>
107 /// <exception cref="ObjectDisposedException">
108 /// The <see cref="PersonAppearanceDetector"/> has already been disposed of.<br/>
110 /// <paramref name="config"/> has already been disposed of.
112 /// <see cref="SurveillanceSource.Push(MediaVisionSource)"/>
113 /// <since_tizen> 4 </since_tizen>
114 public void AddSource(SurveillanceSource source, PersonAppearanceDetectionConfiguration config)
117 InvokeAddSource(source, config);