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 movement 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="MovementDetectionConfiguration"/>
28 /// <since_tizen> 3 </since_tizen>
29 public class MovementDetector : SurveillanceEngine
31 private const string KeyNumberOfRegions = "NUMBER_OF_MOVEMENT_REGIONS";
32 private const string KeyRegions = "MOVEMENT_REGIONS";
34 private const string MovementDetectedEventType = "MV_SURVEILLANCE_EVENT_MOVEMENT_DETECTED";
37 /// Initializes a new instance of the <see cref="MovementDetector"/> class.
39 /// <exception cref="NotSupportedException">The required features are not supported.</exception>
40 /// <since_tizen> 3 </since_tizen>
41 public MovementDetector() : base(MovementDetectedEventType)
46 /// Occurs when the movement detected.
48 /// <remarks>The event handler will be executed on an internal thread.</remarks>
49 /// <since_tizen> 3 </since_tizen>
50 public event EventHandler<MovementDetectedEventArgs> Detected;
52 internal override void OnEventDetected(IntPtr trigger, IntPtr source, int streamId,
53 IntPtr result, IntPtr _)
57 Detected?.Invoke(this, CreateMovementDetectedEventArgs(result));
61 MultimediaLog.Error(MediaVisionLog.Tag, "Failed to invoke Recognized event.", e);
65 private static Rectangle[] RetrieveAreas(IntPtr result)
68 GetResultValue(result, KeyNumberOfRegions, out count).Validate("Failed to get result count");
72 return new Rectangle[0];
75 var rects = new global::Interop.MediaVision.Rectangle[count];
77 GetResultValue(result, KeyRegions, rects).Validate("Failed to get regions");
79 return global::Interop.ToApiStruct(rects);
82 private static MovementDetectedEventArgs CreateMovementDetectedEventArgs(IntPtr result)
84 return new MovementDetectedEventArgs(RetrieveAreas(result));
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="MovementDetector"/> has already been disposed of.</exception>
94 /// <see cref="SurveillanceSource.Push(MediaVisionSource)"/>
95 /// <since_tizen> 3 </since_tizen>
96 public void AddSource(SurveillanceSource source)
98 AddSource(source, null);
102 /// Adds <see cref="SurveillanceSource"/> with the provided <see cref="MovementDetectionConfiguration"/>.
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="MovementDetector"/> has already been disposed of.<br/>
110 /// <paramref name="config"/> has already been disposed of.
112 /// <see cref="SurveillanceSource.Push(MediaVisionSource)"/>
113 /// <since_tizen> 3 </since_tizen>
114 public void AddSource(SurveillanceSource source, MovementDetectionConfiguration config)
116 InvokeAddSource(source, config);