/* * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved * * Licensed under the Apache License, Version 2.0 (the License); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an AS IS BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ using System; using static Interop.MediaVision.Surveillance; namespace Tizen.Multimedia.Vision { /// /// Provides the ability to detect movement on image sources. /// /// http://tizen.org/feature/vision.face_recognition /// http://tizen.org/feature/vision.image_recognition /// /// 3 public class MovementDetector : SurveillanceEngine { private const string KeyNumberOfRegions = "NUMBER_OF_MOVEMENT_REGIONS"; private const string KeyRegions = "MOVEMENT_REGIONS"; private const string MovementDetectedEventType = "MV_SURVEILLANCE_EVENT_MOVEMENT_DETECTED"; /// /// Initializes a new instance of the class. /// /// The required features are not supported. /// 3 public MovementDetector() : base(MovementDetectedEventType) { } /// /// Occurs when the movement detected. /// /// The event handler will be executed on an internal thread. /// 3 public event EventHandler Detected; internal override void OnEventDetected(IntPtr trigger, IntPtr source, int streamId, IntPtr result, IntPtr _) { try { Detected?.Invoke(this, CreateMovementDetectedEventArgs(result)); } catch (Exception e) { MultimediaLog.Error(MediaVisionLog.Tag, "Failed to invoke Recognized event.", e); } } private static Rectangle[] RetrieveAreas(IntPtr result) { int count = 0; GetResultValue(result, KeyNumberOfRegions, out count).Validate("Failed to get result count"); if (count == 0) { return new Rectangle[0]; } var rects = new global::Interop.MediaVision.Rectangle[count]; GetResultValue(result, KeyRegions, rects).Validate("Failed to get regions"); return global::Interop.ToApiStruct(rects); } private static MovementDetectedEventArgs CreateMovementDetectedEventArgs(IntPtr result) { return new MovementDetectedEventArgs(RetrieveAreas(result)); } /// /// Adds . /// /// The source used for recognition. /// is null. /// The has already been disposed of. /// /// 3 public void AddSource(SurveillanceSource source) { AddSource(source, null); } /// /// Adds with the provided . /// /// The source used for recognition. /// The config for the . This value can be null. /// is null. /// /// The has already been disposed of.
/// -or-
/// has already been disposed of. ///
/// /// 3 public void AddSource(SurveillanceSource source, MovementDetectionConfiguration config) { InvokeAddSource(source, config); } } }