private void webcamConfig_FormClosing(object sender, FormClosingEventArgs e) { try { //20110506 //bubble.drawMode = false; //bubble.exposeArea = false; drawModeOff.Checked = true; drawModeOn.Checked = false; radioButton7.Checked = true; radioButton8.Checked = false; //20110506 returnList.Clear(); for (int i = 0; i < CameraRig.cameraCount(); i++) { CameraRig.getCam(i).motionLevelEvent -= new motionLevelEventHandler(drawLevel); } levelBitmap.Dispose(); cameraWindow.Camera = null; CameraRig.ExposeArea = false; System.Diagnostics.Debug.WriteLine(CameraRig.cameraCount()); returnList.Add(mainSelectedWebcam + 1); returnList.Add(autoscroll); webcamConfigDelegate(returnList); } catch { } }
private void radioButton1_CheckedChanged(object sender, EventArgs e) { CameraRig.updateInfo(bubble.profileInUse, selectedWebcam, CameraRig.infoEnum.areaDetectionWithin, radioButton1.Checked); CameraRig.rigInfoPopulateForCam(bubble.profileInUse, selectedWebcam); config.getProfile(bubble.profileInUse).areaDetectionWithin = radioButton1.Checked; CameraRig.AreaDetectionWithin = radioButton1.Checked; CameraRig.getCam(selectedWebcam).MotionDetector.Reset(); }
private void analyseResults() { bool alarmed = new bool(); foreach (analysePictureControl item in analysis.images) { alarmed = false; if (Convert.ToInt32(lblTimeSpike.Text) == 0 || Convert.ToInt32(lblToleranceSpike.Text) == 0) { if (item.movLevel >= Convert.ToInt32(lblSensitivity.Text)) { alarmed = true; item.borderColour = Color.Red; item.Refresh(); } } else { if (item.movLevel >= trkMov.Value) { List <object> lightSpikeResults; bool spike = new bool(); spike = false; int spikePerc = new int(); lightSpikeResults = statistics.lightSpikeDetected(CameraRig.getCam(item.cam).cam, item.movLevel, trkTimeSpike.Value, trkToleranceSpike.Value, bubble.profileInUse, item.time); spike = (bool)lightSpikeResults[0]; spikePerc = (int)lightSpikeResults[1]; if (!spike) { alarmed = true; item.borderColour = Color.Red; item.Refresh(); } } } if (!alarmed) { item.borderColour = Color.Empty; item.Refresh(); } } }
private void calibrate_Click(object sender, EventArgs e) { ArrayList i = new ArrayList(); //i.Add(config.getProfile(bubble.profileInUse).toolTips); i.Add(toolTip1.Active); i.Add(CameraRig.getCam(selectedWebcam).camNo); //System.Diagnostics.Debug.WriteLine("cam sent: " + Convert.ToString(i[1])); calibrate calibrate = new calibrate(postCalibrate, i); calibrate.StartPosition = FormStartPosition.CenterScreen; calibrate.ShowDialog(); }
private void trainDetection(ArrayList i) { CameraRig.TrainCam = CameraRig.getCam(selectedWebcam).camNo; bubble.detectionCountDown = (int)i[0]; bubble.detectionTrain = (int)i[1]; actCount.Visible = true; bubble.training.Clear(); bubble.movementSetting = true; dw.DoWork -= new DoWorkEventHandler(trainMovement); dw.DoWork += new DoWorkEventHandler(trainMovement); dw.WorkerSupportsCancellation = true; dw.RunWorkerAsync(); }
private void cameraSwitch(int button, bool load) { currentlySelectedButton = button; //int camId = CameraRig.idFromButton(button); int camId = CameraRig.idxFromButton(button); if (load || !load && camClick(button)) { if (load || !load && CameraRig.cameraExists(camId)) { selectedWebcam = CameraRig.ConnectedCameras[camId].cameraName; CameraRig.ConfigCam = camId; CameraRig.getCam(camId).MotionDetector.Reset(); camName.Text = (string)CameraRig.rigInfoGet(bubble.profileInUse, selectedWebcam, CameraRig.infoEnum.friendlyName); drawModeOn.Checked = false; drawModeOff.Checked = true; txtMov.Text = Convert.ToString((double)(CameraRig.rigInfoGet(bubble.profileInUse, selectedWebcam, CameraRig.infoEnum.movementVal)) * 100); radioButton4.Checked = (bool)(CameraRig.rigInfoGet(bubble.profileInUse, selectedWebcam, CameraRig.infoEnum.areaDetection)); radioButton3.Checked = !radioButton4.Checked; areaOffAtMotion.Checked = (bool)(CameraRig.rigInfoGet(bubble.profileInUse, selectedWebcam, CameraRig.infoEnum.areaOffAtMotion)); radioButton8.Checked = false; radioButton7.Checked = true; radioButton1.Checked = (bool)(CameraRig.rigInfoGet(bubble.profileInUse, selectedWebcam, CameraRig.infoEnum.areaDetectionWithin)); radioButton2.Checked = !radioButton1.Checked; trkTimeSpike.Value = (int)(CameraRig.rigInfoGet(bubble.profileInUse, selectedWebcam, CameraRig.infoEnum.timeSpike)); trkToleranceSpike.Value = (int)(CameraRig.rigInfoGet(bubble.profileInUse, selectedWebcam, CameraRig.infoEnum.toleranceSpike)); rdSpikeOn.Checked = (bool)(CameraRig.rigInfoGet(bubble.profileInUse, selectedWebcam, CameraRig.infoEnum.lightSpike)); lblTimeSpike.Text = trkTimeSpike.Value.ToString(); lblToleranceSpike.Text = trkToleranceSpike.Value.ToString() + "%"; cameraWindow.Camera = null; cameraWindow.Camera = CameraRig.getCam(camId); //CameraRig.rig[0].cam; CameraRig.getCam(camId).motionLevelEvent -= new motionLevelEventHandler(drawLevel); CameraRig.getCam(camId).motionLevelEvent += new motionLevelEventHandler(drawLevel); camButtonSetColours(); //camControl(button); } } }
private void radioButton4_CheckedChanged(object sender, EventArgs e) { if (drawModeOff.Checked) { CameraRig.updateInfo(bubble.profileInUse, selectedWebcam, CameraRig.infoEnum.areaDetection, radioButton4.Checked); CameraRig.rigInfoPopulateForCam(bubble.profileInUse, selectedWebcam); CameraRig.getCam(selectedWebcam).MotionDetector.Reset(); config.getProfile(bubble.profileInUse).areaDetection = radioButton4.Checked; CameraRig.getCam(selectedWebcam).areaDetection = radioButton4.Checked; areaOffAtMotion.Enabled = radioButton4.Checked; groupBox4.Enabled = radioButton4.Checked; showSelection.Enabled = radioButton4.Checked; CameraRig.ConnectedCameras[CameraRig.ConfigCam].cam.MotionDetector.Reset(); } }
private void button15_Click(object sender, EventArgs e) { config.getProfile(bubble.profileInUse).rectX = 20; config.getProfile(bubble.profileInUse).rectY = 20; config.getProfile(bubble.profileInUse).rectWidth = 80; config.getProfile(bubble.profileInUse).rectHeight = 80; CameraRig.updateInfo(bubble.profileInUse, selectedWebcam, CameraRig.infoEnum.rectX, 20); CameraRig.updateInfo(bubble.profileInUse, selectedWebcam, CameraRig.infoEnum.rectY, 20); CameraRig.updateInfo(bubble.profileInUse, selectedWebcam, CameraRig.infoEnum.rectWidth, 80); CameraRig.updateInfo(bubble.profileInUse, selectedWebcam, CameraRig.infoEnum.rectHeight, 80); CameraRig.getCam(selectedWebcam).rectX = 20; CameraRig.getCam(selectedWebcam).rectY = 20; CameraRig.getCam(selectedWebcam).rectWidth = 80; CameraRig.getCam(selectedWebcam).rectHeight = 80; cameraWindow.drawRectOnOpen(); }
private void button15_Click(object sender, EventArgs e) { config.getProfile(bubble.profileInUse).rectX = 20; config.getProfile(bubble.profileInUse).rectY = 20; config.getProfile(bubble.profileInUse).rectWidth = 80; config.getProfile(bubble.profileInUse).rectHeight = 80; CameraRig.updateInfo(bubble.profileInUse, selectedWebcam, "rectX", 20); CameraRig.updateInfo(bubble.profileInUse, selectedWebcam, "rectY", 20); CameraRig.updateInfo(bubble.profileInUse, selectedWebcam, "rectWidth", 80); CameraRig.updateInfo(bubble.profileInUse, selectedWebcam, "rectHeight", 80); CameraRig.getCam(selectedWebcam).MotionDetector.rectX = 20; CameraRig.getCam(selectedWebcam).MotionDetector.rectY = 20; CameraRig.getCam(selectedWebcam).MotionDetector.rectWidth = 80; CameraRig.getCam(selectedWebcam).MotionDetector.rectHeight = 80; cameraWindow.drawRectOnOpen(); }
private void cameraSwitch(int button, bool load) { //int camId = CameraRig.idFromButton(button); int camId = CameraRig.idxFromButton(button); if (load || !load && camButtons.camClick(button)) { if (load || !load && CameraRig.cameraExists(camId)) { selectedWebcam = CameraRig.rig[camId].cameraName; CameraRig.drawCam = camId; CameraRig.getCam(camId).MotionDetector.Reset(); camName.Text = (string)CameraRig.rigInfoGet(bubble.profileInUse, selectedWebcam, "friendlyName"); drawModeOn.Checked = false; drawModeOff.Checked = true; txtMov.Text = Convert.ToString((double)(CameraRig.rigInfoGet(bubble.profileInUse, selectedWebcam, "movementVal")) * 100); radioButton4.Checked = (bool)(CameraRig.rigInfoGet(bubble.profileInUse, selectedWebcam, "areaDetection")); radioButton3.Checked = !radioButton4.Checked; areaOffAtMotion.Checked = (bool)(CameraRig.rigInfoGet(bubble.profileInUse, selectedWebcam, "areaOffAtMotion")); radioButton8.Checked = false; radioButton7.Checked = true; radioButton1.Checked = (bool)(CameraRig.rigInfoGet(bubble.profileInUse, selectedWebcam, "areaDetectionWithin")); radioButton2.Checked = !radioButton1.Checked; cameraWindow.Camera = null; cameraWindow.Camera = CameraRig.getCam(camId); //CameraRig.rig[0].cam; CameraRig.getCam(camId).motionLevelEvent -= new motionLevelEventHandler(drawLevel); CameraRig.getCam(camId).motionLevelEvent += new motionLevelEventHandler(drawLevel); camButtonSetColours(); //camControl(button); } } }
private void webcamConfig_FormClosing(object sender, FormClosingEventArgs e) { try { //20110506 drawModeOff.Checked = true; drawModeOn.Checked = false; radioButton7.Checked = true; radioButton8.Checked = false; //20110506 returnList.Clear(); for (int i = 0; i < CameraRig.cameraCount(); i++) { CameraRig.getCam(i).motionLevelEvent -= new motionLevelEventHandler(drawLevel); CameraRig.getCam(i).calibrating = false; } //levelBitmap.Dispose(); //20130617 v - noopped as main camera window was showing a blank image //cameraWindow.Camera = null; //20130617 ^ - noopped as main camera window was showing a blank image CameraRig.ExposeArea = false; System.Diagnostics.Debug.WriteLine(CameraRig.cameraCount()); returnList.Add(mainSelectedWebcam + 1); returnList.Add(autoscroll); webcamConfigDelegate(returnList); } catch { } }
private void testMotion(object sender, DoWorkEventArgs e) { string outFile = bubble.tmpFolder + "motionCalibrate.csv"; if (File.Exists(outFile)) { File.Delete(outFile); } int startSecs = time.secondsSinceStart(); int tm = (int)(Convert.ToDouble(trainVal.Text) * Convert.ToDouble(1000)); CameraRig.getCam(cam).detectionOn = true; CameraRig.getCam(cam).calibrating = true; //CameraRig.getCam(CameraRig.trainCam).detectionOn = true; //CameraRig.getCam(CameraRig.trainCam).calibrating = true; while (bubble.testImagePublish) { int timeLeft = CountDownFrom - (time.secondsSinceStart() - startSecs); lblCountDown.SynchronisedInvoke(() => lblCountDown.Text = "..." + timeLeft.ToString()); if (timeLeft <= 0)//Convert.ToInt32(countVal.Text)) { bubble.testImagePublish = false; } //System.Diagnostics.Debug.WriteLine("sending to bubble: " + cam.ToString()); bubble.publishTestMotion(tm, cam); } CameraRig.getCam(cam).detectionOn = false; CameraRig.getCam(cam).calibrating = false; //CameraRig.getCam(CameraRig.trainCam).detectionOn = false; //CameraRig.getCam(CameraRig.trainCam).calibrating = false; //analyse analysis = new analyse(); StreamWriter sw = new StreamWriter(outFile, true); sw.WriteLine("Sequence,Motion_Level,lowestValueOverTime,Image_File"); analysis.images.Clear(); for (int i = 0; i < bubble.testImagePublishData.Count; i++) { if (!tw.CancellationPending && File.Exists(bubble.tmpFolder + (string)bubble.testImagePublishData[i + 3])) { sw.WriteLine(string.Concat(bubble.testImagePublishData[i], ",", bubble.testImagePublishData[i + 1], ",", bubble.testImagePublishData[i + 2], ",", bubble.testImagePublishData[i + 3])); analysis.newPictureControl(bubble.tmpFolder + (string)bubble.testImagePublishData[i + 3], (string)bubble.testImagePublishData[i + 4], (long)bubble.testImagePublishData[i + 5], Color.DarkOrange, (int)bubble.testImagePublishData[i + 1]); //analysis.newPictureControl(new Bitmap(bubble.tmpFolder + (string)bubble.testImagePublishData[i + 3]), // (string)bubble.testImagePublishData[i + 4], // (long)bubble.testImagePublishData[i + 5], // Color.DarkOrange, // (int)bubble.testImagePublishData[i + 1]); } i = i + 5; } sw.Close(); populate(); startCountdown.SynchronisedInvoke(() => startCountdown.Text = "Start Calibration"); lblCountDown.SynchronisedInvoke(() => lblCountDown.Visible = false); }
// private void trainMovement(object sender, DoWorkEventArgs e) { int secondsToTrainStart; int secondsToLast = 0; int tmpInt; double tmpDbl, tmpVal; while (bubble.baselineSetting || bubble.movementSetting) { tmpInt = bubble.detectionCountDown; secondsToTrainStart = time.secondsSinceStart(); CameraRig.getCam(CameraRig.TrainCam).calibrating = false; actCount.ForeColor = Color.Blue; txtMess.ForeColor = Color.Blue; txtMess.SynchronisedInvoke(() => txtMess.Text = "Counting Down"); //SetInfo(txtMess, "Counting Down"); while (tmpInt > 0) { tmpInt = bubble.detectionCountDown + ((int)secondsToTrainStart - time.secondsSinceStart()); if (secondsToLast != tmpInt) { actCount.SynchronisedInvoke(() => actCount.Text = Convert.ToString(tmpInt)); //SetInfo(actCount, Convert.ToString(tmpInt)); } secondsToLast = tmpInt; } tmpInt = bubble.detectionTrain; secondsToTrainStart = time.secondsSinceStart(); CameraRig.getCam(CameraRig.TrainCam).detectionOn = true; CameraRig.getCam(CameraRig.TrainCam).calibrating = true; actCount.ForeColor = Color.Red; txtMess.ForeColor = Color.Red; txtMess.SynchronisedInvoke(() => txtMess.Text = "Recording Movement"); //SetInfo(txtMess, "Recording Movement"); while (tmpInt > 0) { tmpInt = bubble.detectionTrain + (secondsToTrainStart - time.secondsSinceStart()); if (secondsToLast != tmpInt) { actCount.SynchronisedInvoke(() => actCount.Text = Convert.ToString(tmpInt)); //SetInfo(actCount, Convert.ToString(tmpInt)); } secondsToLast = tmpInt; } //calculate average motion sensitivity setting //only calculate average based on non zero values CameraRig.getCam(CameraRig.TrainCam).detectionOn = false; CameraRig.getCam(CameraRig.TrainCam).calibrating = false; tmpDbl = 0; tmpInt = 0; foreach (double val in bubble.training) { if (val > 0) { tmpDbl += val; tmpInt++; } } tmpVal = 0; if (tmpDbl > 0) { tmpVal = tmpDbl / (double)tmpInt; } config.getProfile(bubble.profileInUse).movementVal = tmpVal; txtMov.SynchronisedInvoke(() => txtMov.Text = Convert.ToString((int)Math.Floor(tmpVal * 100))); //SetInfo(txtMov, Convert.ToString((int)Math.Floor(tmpVal * 100))); actCount.ForeColor = Color.Blue; txtMess.ForeColor = Color.Blue; txtMov.SynchronisedInvoke(() => txtMov.Text = string.Empty); actCount.SynchronisedInvoke(() => actCount.Text = string.Empty); //SetInfo(txtMess, ""); //SetInfo(actCount, ""); FileManager.WriteFile("training"); bubble.baselineSetting = false; bubble.movementSetting = false; dw.Dispose(); } }
private void drawModeOn_CheckedChanged(object sender, EventArgs e) { bool drawMode = drawModeOn.Checked; bubble.drawMode = drawModeOn.Checked; if (drawMode) { System.Diagnostics.Debug.WriteLine(CameraRig.cameraCount()); if (config.getProfile(bubble.profileInUse).imageToframe) { cameraWindow.imageToFrame = false; panel3.AutoScroll = true; } if (!config.getProfile(bubble.profileInUse).cameraShow) { cameraWindow.showCam = true; } bubble.exposeArea = false; CameraRig.ExposeArea = false; radioButton8.Checked = false; groupBox11.Enabled = false; groupBox4.Enabled = false; showSelection.Enabled = false; CameraRig.getCam(selectedWebcam).MotionDetector.Reset(); Thread.Sleep(250); cameraWindow.Camera.Lock(); drawArgs a = new drawArgs(); a.x = CameraRig.getCam(selectedWebcam).rectX; a.y = CameraRig.getCam(selectedWebcam).rectY; a.width = CameraRig.getCam(selectedWebcam).rectWidth; a.height = CameraRig.getCam(selectedWebcam).rectHeight; drawInitialRectangle(null, a); System.Diagnostics.Debug.WriteLine(CameraRig.cameraCount()); CameraRig.getCam(selectedWebcam).MotionDetector.Reset(); //System.Diagnostics.Debug.WriteLine(CameraRig.drawCam); } else { System.Diagnostics.Debug.WriteLine(CameraRig.cameraCount()); if (config.getProfile(bubble.profileInUse).imageToframe) { cameraWindow.imageToFrame = true; panel3.AutoScroll = false; } else { cameraWindow.imageToFrame = false; panel3.AutoScroll = true; } if (!config.getProfile(bubble.profileInUse).cameraShow) { cameraWindow.showCam = false; } groupBox11.Enabled = true; groupBox4.Enabled = radioButton4.Checked; showSelection.Enabled = radioButton4.Checked; areaOffAtMotion.Enabled = radioButton4.Checked; cameraWindow.Camera.Unlock(); } if (config.getProfile(bubble.profileInUse).areaDetection) { cameraWindow.drawRectOnOpen(); } cameraWindow.selectionOn = drawMode; cameraWindow.rectDrawn = true; }