Пример #1
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;
            }
        }
Пример #2
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;
            }
        }