public void AddMotionDetectionEvent(MotionDetectionEvent motionDetectionEvent) { try { //execute stored procedure with parameter //CameraDevice cd = Database.SqlQuery<CameraDevice>("sp_GetCameraDeviceByID @p0", motionDetectionEvent.CameraDevice.ID).FirstOrDefault(); CameraDevice cd = CameraDevices.Where(a => a.ID == motionDetectionEvent.CameraDevice.ID).FirstOrDefault(); if (cd == null) { cd = CameraDevices.Add(motionDetectionEvent.CameraDevice); } else { motionDetectionEvent.CameraDevice = cd; } MotionDetectionEvents.Add(motionDetectionEvent); SaveChanges(); } catch (Exception ex) { Logger.Error("Failed to add motion detection event", ex); } }
public ActionResult MotionDetection() { ViewBag.NumTimes = 5; ViewBag.Test = "Message"; MotionDetectionEvent a = new MotionDetectionEvent() { ID = 555 }; return View(a); }
public void AddMotionSecurityEvent(MotionDetectionEvent motionEvent) { Logger.Debug("Security event detected"); using (ServerDataAccess conf = new ServerDataAccess("HomeSecureData")) { conf.AddMotionDetectionEvent(motionEvent); } }
static void Main(string[] args) { Logger.Init("Log.config", "DataAccessTestLogger"); MotionDetectionEvent mde = new MotionDetectionEvent() { CameraDevice = new CameraDevice() { ID = "123", Name = "Name" }, ID = 1, NumberOfPixelsDetected = 100, SecurityEventTime = DateTime.Now }; ServerDataAccess conf = new ServerDataAccess("HomeSecureData"); conf.AddMotionDetectionEvent(mde); int total = 0; List<MotionDetectionEvent> motionDetectionEvents = conf.GetMotionDetectionEvents(2, 1, out total); }
public override void Notify(SecurityEvent securityEvent) { try { MotionDetectionEvent motionDetectionEvent = new MotionDetectionEvent() { CameraDevice = new CameraDevice() { ID = securityEvent.InputDevice.ID, Name = (securityEvent.InputDevice as CameraDevice).Name, }, ID = securityEvent.ID, NumberOfPixelsDetected = (securityEvent as MotionDetectionEvent).NumberOfPixelsDetected, SecurityEventTime = securityEvent.SecurityEventTime }; _service.AddMotionSecurityEvent(motionDetectionEvent); } catch (Exception ex) { Logger.Error("Failed to notify security event to server"); } }
public MotionDetectedEventArgs(MotionDetectionEvent motionEvent) { MotionDetectionEvent = motionEvent; }
public void OnMotionDetectionEvent(MotionDetectionEvent motionDetectionEvent) { lblAlert.Dispatcher.BeginInvoke(new Action(() => lblAlert.Content = "Alert " + motionDetectionEvent.NumberOfPixelsDetected)); }
private void DetectMotion() { if ((_previousFrame != null) && (_currentFrame != null)) { Grayscale grayscaleFilter = new Grayscale(0.2125, 0.7154, 0.0721); using (Bitmap frame1GS = grayscaleFilter.Apply(_previousFrame)) { using (Bitmap frame2GS = grayscaleFilter.Apply(_currentFrame)) { Difference differenceFilter = new Difference(); IFilter thresholdFilter = new Threshold(15); // set backgroud frame as an overlay for difference filter differenceFilter.OverlayImage = (Bitmap)frame1GS; // apply the filters using (Bitmap tmp1 = differenceFilter.Apply((Bitmap)frame2GS)) { using (Bitmap tmp2 = thresholdFilter.Apply(tmp1)) { IFilter erosionFilter = new Erosion(); // apply the filter using (Bitmap tmp3 = erosionFilter.Apply(tmp2)) { int whitePixelsCount = CalculateWhitePixels(tmp3); if (whitePixelsCount > 1000) { MotionDetectionEvent motionEvent = new MotionDetectionEvent() { CameraDevice = _camera, NumberOfPixelsDetected = whitePixelsCount, InputDevice = _camera }; MotionDetectedEventArgs args = new MotionDetectedEventArgs(motionEvent); OnMotionDetected(args); } //// extract red channel from the original image //IFilter extrachChannel = new ExtractChannel(RGB.R); //Bitmap redChannel = extrachChannel.Apply(frame2); //// merge red channel with motion regions //Merge mergeFilter = new Merge(); //mergeFilter.OverlayImage = tmp3; //Bitmap tmp4 = mergeFilter.Apply(redChannel); //// replace red channel in the original image //ReplaceChannel replaceChannel = new ReplaceChannel(RGB.R, tmp4); //replaceChannel.ChannelImage = tmp4; //Bitmap tmp5 = replaceChannel.Apply(frame2); } } } } } } }