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 /// <seealso cref="MovementDetectionConfiguration"/>
26 /// <since_tizen> 3</since_tizen>
27 public class MovementDetector : SurveillanceEngine
29 private const string KeyNumberOfRegions = "NUMBER_OF_MOVEMENT_REGIONS";
30 private const string KeyRegions = "MOVEMENT_REGIONS";
32 private const string MovementDetectedEventType = "MV_SURVEILLANCE_EVENT_MOVEMENT_DETECTED";
35 /// Initializes a new instance of the <see cref="MovementDetector"/> class.
37 /// <exception cref="NotSupportedException">The feature is not supported.</exception>
38 /// <since_tizen> 3</since_tizen>
39 public MovementDetector() : base(MovementDetectedEventType)
44 /// Occurs when the movement detected.
46 /// <remarks>The event handler will be executed on an internal thread.</remarks>
47 /// <since_tizen> 3</since_tizen>
48 public event EventHandler<MovementDetectedEventArgs> Detected;
50 internal override void OnEventDetected(IntPtr trigger, IntPtr source, int streamId,
51 IntPtr result, IntPtr _)
55 Detected?.Invoke(this, CreateMovementDetectedEventArgs(result));
59 MultimediaLog.Error(MediaVisionLog.Tag, "Failed to invoke Recognized event.", e);
63 private static Rectangle[] RetrieveAreas(IntPtr result)
66 GetResultValue(result, KeyNumberOfRegions, out count).Validate("Failed to get result count");
70 return new Rectangle[0];
73 var rects = new global::Interop.MediaVision.Rectangle[count];
75 GetResultValue(result, KeyRegions, rects).Validate("Failed to get regions");
77 return global::Interop.ToApiStruct(rects);
80 private static MovementDetectedEventArgs CreateMovementDetectedEventArgs(IntPtr result)
82 return new MovementDetectedEventArgs(RetrieveAreas(result));
87 /// Adds <see cref="SurveillanceSource"/>.
89 /// <param name="source">The source used for recognition.</param>
90 /// <exception cref="ArgumentNullException"><paramref name="source"/> is null.</exception>
91 /// <exception cref="ObjectDisposedException">The <see cref="MovementDetector"/> has already been disposed of.</exception>
92 /// <see cref="SurveillanceSource.Push(MediaVisionSource)"/>
93 /// <since_tizen> 3</since_tizen>
94 public void AddSource(SurveillanceSource source)
96 AddSource(source, null);
100 /// Adds <see cref="SurveillanceSource"/> with the provided <see cref="MovementDetectionConfiguration"/>.
102 /// <param name="source">The source used for recognition.</param>
103 /// <param name="config">The config for the <paramref name="source"/>. This value can be null.</param>
104 /// <exception cref="ArgumentNullException"><paramref name="source"/> is null.</exception>
105 /// <exception cref="ObjectDisposedException">
106 /// The <see cref="MovementDetector"/> has already been disposed of.\n
108 /// <paramref name="config"/> has already been disposed of.
110 /// <see cref="SurveillanceSource.Push(MediaVisionSource)"/>
111 /// <since_tizen> 3</since_tizen>
112 public void AddSource(SurveillanceSource source, MovementDetectionConfiguration config)
114 InvokeAddSource(source, config);