Пример #1
0
        private void button_addFile_Click(object sender, EventArgs e)
        {
            string[] s = new string[4]
            {
                CamCalibration.GetROIPoints()[0].X + "/" + CamCalibration.GetROIPoints()[0].Y,
                     CamCalibration.GetROIPoints()[1].X + "/" + CamCalibration.GetROIPoints()[1].Y,
                     CamCalibration.GetROIPoints()[2].X + "/" + CamCalibration.GetROIPoints()[2].Y,
                     CamCalibration.GetROIPoints()[3].X + "/" + CamCalibration.GetROIPoints()[3].Y
            };

            if (fileExists)
            {
                DialogResult result = MessageBox.Show("Save over file?", "Saving file...", MessageBoxButtons.YesNo, MessageBoxIcon.Warning);
                if (result == DialogResult.Yes)
                {
                    camCalibration.SaveFile(s);
                    MessageBox.Show("File Saved!", "Saving file...", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
            }
            else
            {
                camCalibration.SaveFile(s);
                MessageBox.Show("File saved!", "Saving file...", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
        }
Пример #2
0
        /// <summary>
        /// Detection function.
        /// Applies camera correction and then starts <see cref="Renderer(Mat)"/> function.
        /// </summary>
        /// <param name="cam_test"></param>
        /// <param name="srcWindow"></param>
        /// <param name="dstWindow"></param>
        public void SpectrumTrack(VideoCapture cam_test, Window srcWindow, Window dstWindow)
        {
            src = cam_test.RetrieveMat(); // Real image of the camera
            Cv2.Resize(src, src, new Size(CamCalibration.GetFrameArray()[0], CamCalibration.GetFrameArray()[1]), 1, 1, InterpolationFlags.Cubic);

            Mat lambda = Cv2.GetPerspectiveTransform(CamCalibration.GetROIPoints(), CamCalibration.GetDf32());

            Cv2.WarpPerspective(src, src, lambda, new Size(CamCalibration.GetMaxWidth(), CamCalibration.GetMaxHeight()));

            dstPreview = Renderer(src);

            // Show processed images in the right windows
            if (!realView)
            {
                Cv2.ImShow(srcWindow.Name, src);
                src.Dispose();
            }
            if (!blobView)
            {
                Cv2.ImShow(dstWindow.Name, dstPreview);
                dstPreview.Dispose();
            }
            Cv2.WaitKey(1);
        }
Пример #3
0
        private void timer1_Tick(object sender, EventArgs e)
        {
            if (previousPoint != camCalibration.GetCurrentPoint())
            {
                previousPoint = camCalibration.GetCurrentPoint();
                switch (camCalibration.GetCurrentPoint())
                {
                case 1:
                    label_point1.BackColor = Color.Aqua;
                    label_point2.BackColor = Color.AliceBlue;
                    label_point3.BackColor = Color.AliceBlue;
                    label_point4.BackColor = Color.AliceBlue;
                    break;

                case 2:
                    label_point1.BackColor = Color.AliceBlue;
                    label_point2.BackColor = Color.Aqua;
                    label_point3.BackColor = Color.AliceBlue;
                    label_point4.BackColor = Color.AliceBlue;
                    break;

                case 3:
                    label_point1.BackColor = Color.AliceBlue;
                    label_point2.BackColor = Color.AliceBlue;
                    label_point3.BackColor = Color.Aqua;
                    label_point4.BackColor = Color.AliceBlue;
                    break;

                case 4:
                    label_point1.BackColor = Color.AliceBlue;
                    label_point2.BackColor = Color.AliceBlue;
                    label_point3.BackColor = Color.AliceBlue;
                    label_point4.BackColor = Color.Aqua;
                    break;
                }
            }

            textBox_point1X.Text = CamCalibration.GetROIPoints()[0].X.ToString();
            textBox_point1Y.Text = CamCalibration.GetROIPoints()[0].Y.ToString();

            textBox_point2X.Text = CamCalibration.GetROIPoints()[1].X.ToString();
            textBox_point2Y.Text = CamCalibration.GetROIPoints()[1].Y.ToString();

            textBox_point3X.Text = CamCalibration.GetROIPoints()[2].X.ToString();
            textBox_point3Y.Text = CamCalibration.GetROIPoints()[2].Y.ToString();

            textBox_point4X.Text = CamCalibration.GetROIPoints()[3].X.ToString();
            textBox_point4Y.Text = CamCalibration.GetROIPoints()[3].Y.ToString();

            if (CamCalibration.GetROIPoints()[0].X >= CamCalibration.GetROIPoints()[1].X)
            {
                textBox_point2X.BackColor = Color.IndianRed;
                x1_x2 = false;
            }
            else
            {
                textBox_point2X.BackColor = Color.White;
                x1_x2 = true;
            }
            if (CamCalibration.GetROIPoints()[0].X >= CamCalibration.GetROIPoints()[2].X)
            {
                textBox_point3X.BackColor = Color.IndianRed;
                x1_x3 = false;
            }
            else
            {
                textBox_point3X.BackColor = Color.White;
                x1_x3 = true;
            }
            if (CamCalibration.GetROIPoints()[0].Y >= CamCalibration.GetROIPoints()[2].Y)
            {
                textBox_point3Y.BackColor = Color.IndianRed;
                y1_y3 = false;
            }
            else
            {
                textBox_point3Y.BackColor = Color.White;
                y1_y3 = true;
            }
            if (CamCalibration.GetROIPoints()[0].Y >= CamCalibration.GetROIPoints()[3].Y)
            {
                textBox_point4Y.BackColor = Color.IndianRed;
                y1_y4 = false;
            }
            else
            {
                textBox_point4Y.BackColor = Color.White;
                y1_y4 = true;
            }
            if (CamCalibration.GetROIPoints()[1].X <= CamCalibration.GetROIPoints()[3].X)
            {
                textBox_point4X.BackColor = Color.IndianRed;
                x2_x4 = false;
            }
            else
            {
                textBox_point4X.BackColor = Color.White;
                x2_x4 = true;
            }
            if (CamCalibration.GetROIPoints()[1].Y >= CamCalibration.GetROIPoints()[2].Y)
            {
                textBox_point3Y.BackColor = Color.IndianRed;
                y2_y3 = false;
            }
            else
            {
                textBox_point3Y.BackColor = Color.White;
                y2_y3 = true;
            }
            if (CamCalibration.GetROIPoints()[1].Y >= CamCalibration.GetROIPoints()[3].Y)
            {
                textBox_point4Y.BackColor = Color.IndianRed;
                y2_y4 = false;
            }
            else
            {
                textBox_point4Y.BackColor = Color.White;
                y2_y4 = true;
            }
            if (CamCalibration.GetROIPoints()[2].X <= CamCalibration.GetROIPoints()[3].X)
            {
                textBox_point4X.BackColor = Color.IndianRed;
                x3_x4 = false;
            }
            else
            {
                textBox_point4X.BackColor = Color.White;
                x3_x4 = true;
            }

            if (x1_x2 && x1_x3 && y1_y3 && y1_y4 && x2_x4 && y2_y3 && y2_y4 && x3_x4)
            {
                pointsReady = true;
            }
            else
            {
                pointsReady = false;
            }

            if (textBox_fileName.Text != "")
            {
                CamCalibration.SetPath(textBox_fileName.Text);
                if (!File.Exists(CamCalibration.GetPath()))
                {
                    textBox_fileName.BackColor = Color.LightGreen;
                    fileSet    = true;
                    fileExists = false;
                }
                else if (File.Exists(CamCalibration.GetPath()))
                {
                    textBox_fileName.BackColor = Color.Yellow;
                    fileSet    = true;
                    fileExists = true;
                }
                else
                {
                    fileSet = false;
                    textBox_fileName.BackColor = Color.IndianRed;
                }
            }
            else
            {
                fileSet = false;
                textBox_fileName.BackColor = Color.IndianRed;
            }

            if (pointsReady && fileSet)
            {
                button_addFile.Enabled = true;
            }
            else
            {
                button_addFile.Enabled = false;
            }
        }