private void drawLevel(object sender, MotionLevelArgs a, CamIdArgs b) { if (b.cam == CameraRig.ConfigCam) { double sensitivity = (double)Convert.ToInt32(txtMov.Text); LevelControlBox.levelDraw(Convert.ToInt32(a.lvl * 100), sensitivity); } }
// On new frame private void video_NewFrameOLD(object sender, NewFrameEventArgs e) { try { // lock Monitor.Enter(this); // dispose old frame if (pubFrame != null) { pubFrame.Dispose(); } //lastFrame = (Bitmap)e.Frame.Clone(); pubFrame = (Bitmap)e.Frame.Clone(); if (_detectionOn) { // apply motion detector if (motionDetector != null) { //************************************* //pre-process bitmap for area detection //************************************* Bitmap areaDetectionPreparedImage; if (areaOffAtMotionTriggered && !areaOffAtMotionReset) { motionDetector.Reset(); areaOffAtMotionReset = true; } if (areaDetection && !areaOffAtMotionTriggered) { areaDetectionPreparedImage = selectArea(pubFrame, AreaDetectionWithin, RectWidth, RectHeight, RectX, RectY); if (exposeArea) { pubFrame = areaDetectionPreparedImage; } } else { areaDetectionPreparedImage = pubFrame; } //************************************* //pre-process bitmap for area detection //************************************* motionDetector.ProcessFrame(areaDetectionPreparedImage); MotionLevelArgs a = new MotionLevelArgs(); CamIdArgs b = new CamIdArgs(); a.lvl = motionDetector.MotionDetectionAlgorithm.MotionLevel; a.alarmLvl = movementVal; b.cam = cam; b.name = name; motionLevelEvent(null, a, b); // check motion level if (calibrating && cam == CameraRig.trainCam) { bubble.train(motionDetector.MotionDetectionAlgorithm.MotionLevel); } else { if (alarmActive && alert && motionDetector.MotionDetectionAlgorithm.MotionLevel >= movementVal && motionAlarm != null) { CamIdArgs c = new CamIdArgs(); c.cam = cam; c.name = name; LevelArgs l = new LevelArgs(); l.lvl = Convert.ToInt32(100 * motionDetector.MotionDetectionAlgorithm.MotionLevel); motionAlarm(null, c, l); } } } }//if (_detectionOn) // image dimension width = pubFrame.Width; height = pubFrame.Height; //#ref5617 } catch (Exception ex) { Debug.WriteLine(ex.Message); } finally { // unlock Monitor.Exit(this); } // notify client if (NewFrame != null) { NewFrame(this, new EventArgs()); } }
// On new frame private void video_NewFrame(object sender, NewFrameEventArgs e) { try { // lock Monitor.Enter(this); // dispose old frame if (pubFrame != null) { pubFrame.Dispose(); } //lastFrame = (Bitmap)e.Frame.Clone(); try { pubFrame = (Bitmap)e.Frame.Clone(); //#ToDo if (frameRateTrack) { frames.addFrame(); } //purge outside of this on a semi-regular basis //framesDtCount.purge(100); //framesDt.Add(DateTime.Now); } catch (Exception) { pubFrame = (Bitmap)Properties.Resources.imagenotavailable.Clone(); } if (_detectionOn) { if ((calibrating && camNo == CameraRig.TrainCam) || (alarmActive && alert)) { // apply motion detector if (motionDetector != null) { //************************************* //pre-process bitmap for area detection //************************************* Bitmap areaDetectionPreparedImage; if (areaOffAtMotionTriggered && !areaOffAtMotionReset) { motionDetector.Reset(); areaOffAtMotionReset = true; } if (areaDetection && !areaOffAtMotionTriggered) { areaDetectionPreparedImage = selectArea(pubFrame, AreaDetectionWithin, RectWidth, RectHeight, RectX, RectY); if (exposeArea) { pubFrame = areaDetectionPreparedImage; } } else { areaDetectionPreparedImage = pubFrame; } //************************************* //pre-process bitmap for area detection //************************************* motionDetector.ProcessFrame(areaDetectionPreparedImage); MotionLevelArgs a = new MotionLevelArgs(); CamIdArgs b = new CamIdArgs(); a.lvl = motionDetector.MotionDetectionAlgorithm.MotionLevel; a.alarmLvl = movementVal; b.cam = camNo; b.name = name; motionLevelEvent(null, a, b); // check motion level if (calibrating && camNo == CameraRig.TrainCam) { bubble.train(motionDetector.MotionDetectionAlgorithm.MotionLevel); } else { if (alarmActive && alert && motionDetector.MotionDetectionAlgorithm.MotionLevel >= movementVal && motionAlarm != null) { CamIdArgs c = new CamIdArgs(); c.cam = camNo; c.name = name; LevelArgs l = new LevelArgs(); l.lvl = Convert.ToInt32(100 * motionDetector.MotionDetectionAlgorithm.MotionLevel); motionAlarm(null, c, l); } else { certifiedTriggeredByNonSpike = false; triggeredBySpike = false; } } } } }//if (_detectionOn) // image dimension width = pubFrame.Width; height = pubFrame.Height; //#ref5617 } catch (Exception ex) { Debug.WriteLine(ex.Message); } finally { // unlock Monitor.Exit(this); } // notify client if (NewFrame != null) { NewFrame(this, new EventArgs()); } }
// On new frame private void video_NewFrameOLD(object sender, NewFrameEventArgs e) { try { // lock Monitor.Enter(this); // dispose old frame if (pubFrame != null) { pubFrame.Dispose(); } //lastFrame = (Bitmap)e.Frame.Clone(); pubFrame = (Bitmap)e.Frame.Clone(); if (_detectionOn) { // apply motion detector if (motionDetecotor != null) { //************************************* //pre-process bitmap for area detection //************************************* Bitmap areaDetectionPreparedImage; if (areaOffAtMotionTriggered && !areaOffAtMotionReset) { motionDetecotor.Reset(); areaOffAtMotionReset = true; } if (areaDetection && !areaOffAtMotionTriggered) { areaDetectionPreparedImage = selectArea(pubFrame, AreaDetectionWithin, RectWidth, RectHeight, RectX, RectY); if (exposeArea) { pubFrame = areaDetectionPreparedImage; } } else { areaDetectionPreparedImage = pubFrame; } //************************************* //pre-process bitmap for area detection //************************************* motionDetecotor.ProcessFrame(areaDetectionPreparedImage); MotionLevelArgs a = new MotionLevelArgs(); CamIdArgs b = new CamIdArgs(); a.lvl = motionDetecotor.MotionDetectionAlgorithm.MotionLevel; b.cam = cam; motionLevelEvent(null, a, b); // check motion level if (calibrating && cam == CameraRig.trainCam) { bubble.train(motionDetecotor.MotionDetectionAlgorithm.MotionLevel); } else { if (alarmActive && alert && motionDetecotor.MotionDetectionAlgorithm.MotionLevel >= movementVal && motionAlarm != null) { CamIdArgs c = new CamIdArgs(); c.cam = cam; LevelArgs l = new LevelArgs(); l.lvl = Convert.ToInt32(100 * motionDetecotor.MotionDetectionAlgorithm.MotionLevel); motionAlarm(null, c, l); } } } }//if (_detectionOn) // image dimension width = pubFrame.Width; height = pubFrame.Height; //#ref5617 } catch (Exception ex) { Debug.WriteLine(ex.Message); } finally { // unlock Monitor.Exit(this); } // notify client if (NewFrame != null) { NewFrame(this, new EventArgs()); } }
private void drawLevel(object sender, MotionLevelArgs a, CamIdArgs b) { if (b.cam == CameraRig.drawCam) { double sensitivity = (double)Convert.ToInt32(txtMov.Text); levelDraw(Convert.ToInt32(a.lvl * 100), sensitivity); } }
// On new frame private void video_NewFrame(object sender, NewFrameEventArgs e) { try { // lock Monitor.Enter(this); // dispose old frame if (lastFrame != null) { lastFrame.Dispose(); } lastFrame = (Bitmap)e.Frame.Clone(); pubFrame = (Bitmap)e.Frame.Clone(); // apply motion detector if (motionDetecotor != null) { motionDetecotor.ProcessFrame(ref lastFrame); MotionLevelArgs a = new MotionLevelArgs(); CamIdArgs b = new CamIdArgs(); a.lvl = motionDetecotor.MotionLevel; b.cam = cam; motionLevelEvent(null, a, b); // check motion level if (motionDetecotor.calibrating && cam == CameraRig.trainCam) { bubble.train(motionDetecotor.MotionLevel); } else { if (alarmActive && alert && motionDetecotor.MotionLevel >= movementVal && motionAlarm != null) { CamIdArgs c = new CamIdArgs(); c.cam = cam; LevelArgs l = new LevelArgs(); l.lvl = Convert.ToInt32(100 * motionDetecotor.MotionLevel); motionAlarm(null, c, l); } } } // image dimension width = lastFrame.Width; height = lastFrame.Height; //#ref5617 } catch (Exception) { } finally { // unlock Monitor.Exit(this); } // notify client if (NewFrame != null) { NewFrame(this, new EventArgs()); } }
public static void motionEvent(object sender, MotionLevelArgs a, CamIdArgs b) { levelLine(a, b); RecordMotionStats(a, b); }
public static void levelLine(MotionLevelArgs a, CamIdArgs b) { if (b.cam == CameraRig.activeCam) { motionLevel = Convert.ToInt32((int)Math.Floor(a.lvl * 100)); if (motionLevelChanged != null && motionLevel != motionLevelprevious) { motionLevelprevious = motionLevel; motionLevelChanged(null, new EventArgs()); } } }
public static void camera_Alarm(object sender, CamIdArgs e, LevelArgs l) { List<object> lightSpikeResults; bool spike = new bool(); spike = false; int spikePerc = new int(); //are we filtering light spikes? if (!CameraRig.rig[e.cam].cam.triggeredBySpike && (bool)(CameraRig.rigInfoGet(bubble.profileInUse, CameraRig.rig[e.cam].cameraName, CameraRig.infoEnum.lightSpike))) { lightSpikeResults = statistics.lightSpikeDetected(e.cam, l.lvl, config.getProfile(bubble.profileInUse).timeSpike, config.getProfile(bubble.profileInUse).toleranceSpike, bubble.profileInUse, time.millisecondsSinceStart()); spike = (bool)lightSpikeResults[0]; spikePerc = (int)lightSpikeResults[1]; } //movement alarm was not previously triggered by a light spike //and a light spike has not been detected with the current alarm inducing movement //or we are not concerned about light spikes if ((!CameraRig.rig[e.cam].cam.triggeredBySpike && !spike) || CameraRig.rig[e.cam].cam.certifiedTriggeredByNonSpike || !(bool)(CameraRig.rigInfoGet(bubble.profileInUse, CameraRig.rig[e.cam].cameraName, CameraRig.infoEnum.lightSpike))) { CameraRig.rig[e.cam].cam.certifiedTriggeredByNonSpike = true; if (config.getProfile(bubble.profileInUse).areaOffAtMotion && !CameraRig.AreaOffAtMotionIsTriggeredCam(e.cam)) { CameraRig.AreaOffAtMotionTrigger(e.cam); bubble.areaOffAtMotionTriggered = true; } if (bubble.Alert.on && bubble.imageSaveTime(true)) { try { string fName = fileNameSet(config.getProfile(bubble.profileInUse).filenamePrefix, config.getProfile(bubble.profileInUse).cycleStampChecked, config.getProfile(bubble.profileInUse).startCycle, config.getProfile(bubble.profileInUse).endCycle, ref config.getProfile(bubble.profileInUse).currentCycle, true); Bitmap saveBmp = null; imageText stampArgs = new imageText(); stampArgs.bitmap = (Bitmap)CameraRig.rig[e.cam].cam.pubFrame.Clone(); stampArgs.type = "Alert"; stampArgs.backingRectangle = config.getProfile(profileInUse).alertTimeStampRect; saveBmp = timeStampImage(stampArgs); ImageCodecInfo jgpEncoder = GetEncoder(ImageFormat.Jpeg); System.Drawing.Imaging.Encoder myEncoder = System.Drawing.Imaging.Encoder.Quality; EncoderParameters myEncoderParameters = new EncoderParameters(1); EncoderParameter myEncoderParameter = new EncoderParameter(myEncoder, config.getProfile(profileInUse).alertCompression); myEncoderParameters.Param[0] = myEncoderParameter; saveBmp.Save(bubble.imageFolder + fName, jgpEncoder, myEncoderParameters); Bitmap thumb = GetThumb(saveBmp); thumb.Save(thumbFolder + tmbPrefix + fName, ImageFormat.Jpeg); ImageThumbs.addThumbToPictureBox(thumbFolder + tmbPrefix + fName); saveBmp.Dispose(); thumb.Dispose(); ImageSavedArgs a = new ImageSavedArgs(); a.image = fName; ImageSaved(null, a); updateSeq++; if (updateSeq > 9999) { updateSeq = 1; } moveStatsAdd(time.currentTime()); logAddLine("Movement detected"); logAddLine("Movement level: " + l.lvl.ToString() + " spike perc.: " + Convert.ToString(spikePerc)); logAddLine("Image saved: " + fName); } catch (Exception) { logAddLine("Error in saving movement image."); updateSeq++; } } } else { //a light spike caused this alarm and we are catching light spikes if ((bool)(CameraRig.rigInfoGet(bubble.profileInUse, CameraRig.rig[e.cam].cameraName, CameraRig.infoEnum.lightSpike))) { CameraRig.rig[e.cam].cam.triggeredBySpike = true; } } }
public static void RecordMotionStats(MotionLevelArgs a, CamIdArgs b) { statistics.add(b.cam, Convert.ToInt32((int)Math.Floor(a.lvl * 100)), time.millisecondsSinceStart(), bubble.profileInUse); }