Beispiel #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);
            }
        }
Beispiel #2
0
        private void ResSelection(int selectedIndex)
        {
            switch (selectedIndex)
            {
            case 0:
                CamCalibration.SetFrameSize(640, 480);
                CamCalibration.SetResolution(640, 480);
                break;

            case 1:
                CamCalibration.SetFrameSize(800, 450);
                CamCalibration.SetResolution(800, 450);
                break;

            case 2:
                CamCalibration.SetFrameSize(640, 480);
                CamCalibration.SetResolution(1440, 1080);
                break;

            case 3:
                CamCalibration.SetFrameSize(800, 480);
                CamCalibration.SetResolution(1920, 1080);
                break;
            }
        }
Beispiel #3
0
 public Form4()
 {
     InitializeComponent();
     colourCalibration = new ColourCalibration();
     colourWindow      = new Window("Color Calibration Window");
     Cv2.SetMouseCallback(colourWindow.Name, colourCalibration.ColourPicker);
     cam = new VideoCapture(FormMain.GetCamera());
     cam.Set(CaptureProperty.FrameWidth, CamCalibration.GetResolution()[0]);
     cam.Set(CaptureProperty.FrameHeight, CamCalibration.GetResolution()[1]);
     FormBorderStyle = FormBorderStyle.FixedSingle;
     current_smin    = -1;
     current_smax    = -1;
     current_vmin    = -1;
     current_vmax    = -1;
     colourWindow.Move(400, 0);
 }
Beispiel #4
0
        public void ColourLoop(VideoCapture cam_test, Window colourWindow)
        {
            src = cam_test.RetrieveMat();
            Cv2.Resize(src, src, new Size(CamCalibration.GetFrameArray()[0], CamCalibration.GetFrameArray()[1]), 1, 1, InterpolationFlags.Cubic);

            if (colourPicked)
            {
                HSV = new Mat();
                RGB = new Mat(src, new Rect(colourPoint.X, colourPoint.Y, 1, 1));

                Cv2.CvtColor(RGB, HSV, ColorConversionCodes.BGR2HSV);
                hsv          = HSV.At <Vec3b>(0, 0);
                newColor_hsv = new Scalar(hsv[0], hsv[1], hsv[2]);
                Hue          = hsv[0];

                rgb          = RGB.At <Vec3b>(0, 0);
                newColor_rgb = new Scalar(rgb[0], rgb[1], rgb[2]);

                colourPicked = false;
                AddNewColour = true;

                HSV.Dispose();
                RGB.Dispose();
            }

            if (blobView)
            {
                Cv2.Blur(src, src, new Size(3, 3));
                Cv2.CvtColor(src, src, ColorConversionCodes.BGR2HSV);
                Cv2.InRange(src, new Scalar(hsv[0] - 10, elementSm, elementVm), new Scalar(hsv[0] + 10, elementSM, elementVM), src);
            }

            Cv2.ImShow(colourWindow.Name, src);

            Cv2.WaitKey(1);

            src.Dispose();
        }
Beispiel #5
0
 public Form3()
 {
     InitializeComponent();
     main = new Main();
     cam  = new VideoCapture(FormMain.GetCamera());
     cam.Set(CaptureProperty.FrameWidth, CamCalibration.GetResolution()[0]);
     cam.Set(CaptureProperty.FrameHeight, CamCalibration.GetResolution()[1]);
     Main.FillColorList(Main.colorCalibrationPath);
     srcWindow       = new Window("Main Window");
     dstWindow       = new Window("Blob Window");
     FormBorderStyle = FormBorderStyle.FixedSingle;
     srcWindow.Move(300, 0);
     Main.MorphValue             = 7;
     label_morphValue.Text       = "MORPH VALUE: " + Main.MorphValue;
     trackBar_morph.Value        = 7;
     labelCurrentIP.Text         = "IP: " + Main.IP_udp;
     labelCurrentPort.Text       = "PORT: " + Main.Port_udp;
     areaResult_min.Text         = Main.MinBlobArea.ToString();
     areaResult_max.Text         = Main.MaxBlobArea.ToString();
     label_calCam.Text           = Main.CameraFileName;
     label_calColor.Text         = Main.ColorFileName;
     checkBox_blobsLabel.Checked = true;
     Main.BlobLabel = true;
 }
Beispiel #6
0
 public Form2()
 {
     InitializeComponent();
     calNumber++;
     camCalibration = new CamCalibration();
     camCalibration.ResetPoints();
     cam_test = new VideoCapture(FormMain.GetCamera());
     cam_test.Set(CaptureProperty.FrameWidth, CamCalibration.GetResolution()[0]);
     cam_test.Set(CaptureProperty.FrameHeight, CamCalibration.GetResolution()[1]);
     calWindow = new Window("Calibration Window " + calNumber);
     Cv2.SetMouseCallback(calWindow.Name, camCalibration.Click); // Need to be outside of the loop
     FormBorderStyle = FormBorderStyle.FixedSingle;
     calWindow.Move(450, 0);
     pointsReady              = false;
     previousPoint            = 0;
     label_point1.MouseEnter += OnMouseEnterPoint1;
     label_point1.MouseLeave += OnMouseLeavePoint1;
     label_point2.MouseEnter += OnMouseEnterPoint2;
     label_point2.MouseLeave += OnMouseLeavePoint2;
     label_point3.MouseEnter += OnMouseEnterPoint3;
     label_point3.MouseLeave += OnMouseLeavePoint3;
     label_point4.MouseEnter += OnMouseEnterPoint4;
     label_point4.MouseLeave += OnMouseLeavePoint4;
 }
Beispiel #7
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);
        }
Beispiel #8
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;
            }
        }
Beispiel #9
0
        private void timer1_Tick(object sender, EventArgs e)
        {
            cameras = DsDevice.GetDevicesOfCat(FilterCategory.VideoInputDevice);
            if (lastCamera_count != cameras.Length)
            {
                lastCamera_count = cameras.Length;
                listBox_Cameras.Items.Clear();
                for (int i = 0; i < cameras.Length; i++)
                {
                    listBox_Cameras.Items.Add(cameras[i].Name);
                }
                listBox_Cameras.SelectedIndex = 0;
            }

            camera = listBox_Cameras.SelectedIndex;

            if (listBox_CamCal.SelectedIndex >= 0)
            {
                button_deleteCamCal.Enabled = true;
            }
            else
            {
                button_deleteCamCal.Enabled = false;
            }

            if (listBox_ColorCal.SelectedIndex >= 0)
            {
                button_deleteColorCal.Enabled = true;
            }
            else
            {
                button_deleteColorCal.Enabled = false;
            }

            if (listBox_Cameras.SelectedIndex >= 0 && listBox_Resolution.SelectedIndex >= 0 && listBox_ColorCal.SelectedIndex >= 0 && listBox_CamCal.SelectedIndex >= 0)
            {
                Main.ColorCalibrationPath(listBox_ColorCal.SelectedItem.ToString());
                Main.ColorFileName = listBox_ColorCal.SelectedItem.ToString();

                if (!onCamCalibration)
                {
                    Main.CameraFileName = listBox_CamCal.SelectedItem.ToString();
                    CamCalibration.SetPath(listBox_CamCal.SelectedItem.ToString());
                    List <string> camList = new List <string>();
                    using (StreamReader sr = File.OpenText(CamCalibration.GetPath()))
                    {
                        string s = "";
                        while ((s = sr.ReadLine()) != null)
                        {
                            camList.Add(s);
                        }
                    }
                    string[] camArray = camList.ToArray();
                    int      counter  = 0;
                    foreach (string s in camArray)
                    {
                        string[] xAndY = s.Split('/');
                        CamCalibration.SetPoints(new OpenCvSharp.Point(int.Parse(xAndY[0]), int.Parse(xAndY[1])), counter);
                        counter++;
                    }
                }
                button3.Enabled = true;
            }
            else
            {
                button3.Enabled = false;
            }

            if (checkBox1.Checked)
            {
                Main.SetOrientation(false);
            }
            else
            {
                Main.SetOrientation(true);
            }

            if (wrongInput_IP)
            {
                if (wrongInput_IPCounter <= 0)
                {
                    textBoxIP.BackColor  = Color.White;
                    wrongInput_IP        = false;
                    wrongInput_IPCounter = 6;
                }
                else
                {
                    wrongInput_IPCounter--;
                }
            }

            if (ip_done)
            {
                if (ip_doneCounter <= 0)
                {
                    ip_done = false;
                    labelCurrentIP.BackColor = Color.Transparent;
                }
                else
                {
                    ip_doneCounter--;
                }
            }

            if (wrongInput_Port)
            {
                if (wrongInput_PortCounter <= 0)
                {
                    textBoxPORT.BackColor  = Color.White;
                    wrongInput_Port        = false;
                    wrongInput_PortCounter = 6;
                }
                else
                {
                    wrongInput_PortCounter--;
                }
            }

            if (port_done)
            {
                if (port_doneCounter <= 0)
                {
                    labelCurrentPort.BackColor = Color.Transparent;
                    port_done        = false;
                    port_doneCounter = 6;
                }
                else
                {
                    port_doneCounter--;
                }
            }

            if (wrongInput_minArea)
            {
                if (wrongInput_minAreaCounter <= 0)
                {
                    textBox_minimumArea.BackColor = Color.White;
                    wrongInput_minArea            = false;
                    wrongInput_minAreaCounter     = 6;
                }
                else
                {
                    wrongInput_minAreaCounter--;
                }
            }

            if (minArea_done)
            {
                if (minArea_doneCounter <= 0)
                {
                    minAreaResult.BackColor = Color.Transparent;
                    minArea_done            = false;
                    minArea_doneCounter     = 6;
                }
                else
                {
                    minArea_doneCounter--;
                }
            }

            if (wrongInput_maxArea)
            {
                if (wrongInput_maxAreaCounter <= 0)
                {
                    textBox_maximumArea.BackColor = Color.White;
                    wrongInput_maxArea            = false;
                    wrongInput_maxAreaCounter     = 6;
                }
                else
                {
                    wrongInput_maxAreaCounter--;
                }
            }

            if (maxArea_done)
            {
                if (maxArea_doneCounter <= 0)
                {
                    maxAreaResult.BackColor = Color.Transparent;
                    maxArea_done            = false;
                    maxArea_doneCounter     = 6;
                }
                else
                {
                    maxArea_doneCounter--;
                }
            }

            if (listBox_Cameras.SelectedIndex >= 0)
            {
                label_CameraBool.BackColor = Color.LightGreen;
            }
            else
            {
                label_CameraBool.BackColor = Color.IndianRed;
            }

            if (listBox_Resolution.SelectedIndex >= 0)
            {
                label_ResolutionBool.BackColor = Color.LightGreen;
            }
            else
            {
                label_ResolutionBool.BackColor = Color.IndianRed;
            }

            if (listBox_CamCal.SelectedIndex >= 0)
            {
                label_CamCalBool.BackColor = Color.LightGreen;
            }
            else
            {
                label_CamCalBool.BackColor = Color.IndianRed;
            }

            if (listBox_ColorCal.SelectedIndex >= 0)
            {
                label_ColorCalBool.BackColor = Color.LightGreen;
            }
            else
            {
                label_ColorCalBool.BackColor = Color.IndianRed;
            }
        }