コード例 #1
0
        private Image <Gray, byte> DetectionImage(Image <Bgr, byte> sourceImg, bool debugMode = false)
        {
            Image <Hsv, byte> img = sourceImg.Convert <Hsv, byte>();

            Image <Gray, byte> blue   = ImageTools.FilterColor(img, new Hsv(90, 90, 50), new Hsv(120, 255, 255));
            Image <Gray, byte> green  = ImageTools.FilterColor(img, new Hsv(35, 70, 35), new Hsv(90, 255, 255));
            Image <Gray, byte> yellow = ImageTools.FilterColor(img, new Hsv(10, 70, 127), new Hsv(35, 255, 255));
            Image <Gray, byte> red    = ImageTools.FilterColor(
                img,
                new KeyValuePair <Hsv, Hsv>[] {
                new KeyValuePair <Hsv, Hsv>(new Hsv(0, 85, 80), new Hsv(12, 255, 255)),
                new KeyValuePair <Hsv, Hsv>(new Hsv(150, 85, 80), new Hsv(179, 255, 255))
            }
                );

            DetectionData ddb = ImageTools.DetectSquares(blue, debugMode ? "Blue Debug Window" : "");
            DetectionData ddr = ImageTools.DetectSquares(red, debugMode ? "Red Debug Window" : "");
            DetectionData ddg = ImageTools.DetectSquares(green, debugMode ? "Green Debug Window" : "");
            DetectionData ddy = ImageTools.DetectSquares(yellow, debugMode ? "Yellow Debug Window" : "");

            ddb.RemoveNoises();
            ddr.RemoveNoises();
            ddg.RemoveNoises();
            ddy.RemoveNoises();
            ddb.AddColor(ddr);
            ddb.AddColor(ddg);
            ddb.AddColor(ddy);

            return(ddb.DrawDetection().Convert <Gray, byte>());
        }
コード例 #2
0
        private void UpdateImages(string path)
        {
            if (String.IsNullOrWhiteSpace(path))
            {
                sourceImg = new Image <Bgr, byte>(100, 100);
            }
            else
            {
                sourceImg = new Image <Bgr, byte>(imageFilePath);
            }
            var hsvImg = sourceImg.Convert <Hsv, byte>();

            blueImg     = ImageTools.FilterColor(hsvImg, UserSettings.instance.blueMin, UserSettings.instance.blueMax);
            redImg      = ImageTools.FilterColor(hsvImg, UserSettings.instance.RedRange);
            greenImg    = ImageTools.FilterColor(hsvImg, UserSettings.instance.greenMin, UserSettings.instance.greenMax);
            yellowImg   = ImageTools.FilterColor(hsvImg, UserSettings.instance.yellowMin, UserSettings.instance.yellowMax);
            composedImg = ImageTools.CombineMaps(new List <KeyValuePair <Image <Gray, byte>, Bgr> >
            {
                new KeyValuePair <Image <Gray, byte>, Bgr>(blueImg, ImageTools.Colors.Blue),
                new KeyValuePair <Image <Gray, byte>, Bgr>(redImg, ImageTools.Colors.Red),
                new KeyValuePair <Image <Gray, byte>, Bgr>(greenImg, ImageTools.Colors.Green),
                new KeyValuePair <Image <Gray, byte>, Bgr>(yellowImg, ImageTools.Colors.Yellow),
            });

            if (operation == OperationType.Detection)
            {
                DetectionData ddb = ImageTools.DetectSquares(blueImg);
                DetectionData ddr = ImageTools.DetectSquares(redImg);
                DetectionData ddg = ImageTools.DetectSquares(greenImg);
                DetectionData ddy = ImageTools.DetectSquares(yellowImg);

                ddb.RemoveNoises();
                ddr.RemoveNoises();
                ddg.RemoveNoises();
                ddy.RemoveNoises();

                DetectionData common = new DetectionData(ddb);
                common.AddColor(ddr);
                common.AddColor(ddg);
                common.AddColor(ddy);

                composedImg = common.DrawDetection().Convert <Bgr, byte>();
                blueImg     = ddb.DrawDetection();
                redImg      = ddr.DrawDetection();
                greenImg    = ddg.DrawDetection();
                yellowImg   = ddy.DrawDetection();

                this.board = common.CreateBoard();
            }
        }
コード例 #3
0
        private DetectionData PrepareDetectionDataExample()
        {
            var dd = new DetectionData(new Size(450, 450));

            dd.AddColor(new List <Rectangle> {
                new Rectangle(120, 10, 100, 100), new Rectangle(230, 10, 100, 100), new Rectangle(340, 230, 100, 100), new Rectangle(230, 340, 100, 100), new Rectangle(340, 340, 100, 100)
            });
            dd.AddColor(new List <Rectangle> {
                new Rectangle(10, 120, 100, 100), new Rectangle(10, 230, 100, 100)
            });
            dd.AddColor(new List <Rectangle> {
                new Rectangle(340, 10, 100, 100), new Rectangle(340, 120, 100, 100), new Rectangle(120, 230, 100, 100), new Rectangle(230, 230, 100, 100)
            });
            dd.AddColor(new List <Rectangle> {
                new Rectangle(120, 120, 100, 100), new Rectangle(230, 120, 100, 100)
            });
            return(dd);
        }
コード例 #4
0
 private void button1_Click(object sender, EventArgs e)
 {
     try
     {
         if (textBox2.Text.Trim().Length <= 0)
         {
             MessageBox.Show("请填写设备地址");
             return;
         }
         DetectionData theDetectionData = new DetectionData();
         theDetectionData.DeviceAddress      = textBox2.Text;
         theDetectionData.DeviceLine         = textBox18.Text;
         theDetectionData.detectionDataArray = new List <DetectionDataArray>();
         DetectionDataArray theDetectionDataArray = new DetectionDataArray();
         theDetectionDataArray.DetectionName   = textBox6.Text;
         theDetectionDataArray.DetectionNumber = textBox17.Text;
         theDetectionDataArray.DetectionRouteA = textBox3.Text;
         theDetectionDataArray.DetectionRouteB = textBox4.Text;
         theDetectionDataArray.DetectionRouteC = textBox5.Text;
         theDetectionData.detectionDataArray.Add(theDetectionDataArray);
         DetectionDataArray towDetectionDataArray = new DetectionDataArray();
         towDetectionDataArray.DetectionName   = textBox7.Text;
         towDetectionDataArray.DetectionNumber = textBox16.Text;
         towDetectionDataArray.DetectionRouteA = textBox10.Text;
         towDetectionDataArray.DetectionRouteB = textBox9.Text;
         towDetectionDataArray.DetectionRouteC = textBox8.Text;
         theDetectionData.detectionDataArray.Add(towDetectionDataArray);
         DetectionDataArray threeDetectionDataArray = new DetectionDataArray();
         threeDetectionDataArray.DetectionName   = textBox11.Text;
         threeDetectionDataArray.DetectionNumber = textBox15.Text;
         threeDetectionDataArray.DetectionRouteA = textBox14.Text;
         threeDetectionDataArray.DetectionRouteB = textBox13.Text;
         threeDetectionDataArray.DetectionRouteC = textBox12.Text;
         theDetectionData.detectionDataArray.Add(threeDetectionDataArray);
         if (theDetectionData != null && theDetectionData.detectionDataArray != null)
         {
             theAddDevice.Invoke(theDetectionData, textBox2.Text);
         }
     }
     catch (Exception msg)
     {
         HandleTool.LogWrite(msg);
     }
 }
コード例 #5
0
        /// <summary>
        /// Включение детекции движения с предустановленной заполенной маской детекции
        /// </summary>
        public static async Task <string> SetDetectionFromBody([FromBody] DetectionData data)
        {
            _logger.Info("[SetDetectionFromBody] Method started");
            try
            {
                using var xmlData = Converters.ToStringContent(data, "MotionDetection");
                var response = await WebClient.Client.PutAsync("System/Video/inputs/channels/1/motionDetection", xmlData).Result.Content.ReadAsStringAsync();

                var jsonResponse = Converters.XmlToJson(response);
                var responseData = JsonConvert.DeserializeObject <CamResponses>(jsonResponse);

                _logger.Info("[SetDetectionFromBody] Method has complete");
                return($"{responseData.responseStatus.StatusString,-10} Request url {responseData.responseStatus.RequestUrl}");
            }
            catch (Exception e)
            {
                _logger.Error($"[SetDetectionFromBody] Method failed. \nError message: {e.Message}");
                return(e.Message);
            }
        }
コード例 #6
0
        private void ReadXmlSetting(string selectItemName)
        {
            textBox2.Text = this.selectItemName;
            string filePath = @"SettingTest/" + selectItemName + ".xml";

            if (File.Exists(filePath))
            {
                using (StreamReader sr = new StreamReader(Path.GetFullPath(filePath)))
                {
                    DetectionData theDetectionData = new DetectionData();
                    theDetectionData.detectionDataArray = new List <DetectionDataArray>();
                    theDetectionData = XmlUtil.Deserialize(typeof(DetectionData), sr.ReadToEnd()) as DetectionData;
                    if (theDetectionData != null && theDetectionData.detectionDataArray.Count > 0)
                    {
                        textBox18.Text = theDetectionData.DeviceLine;
                        textBox6.Text  = theDetectionData.detectionDataArray[0].DetectionName;
                        textBox17.Text = theDetectionData.detectionDataArray[0].DetectionNumber;
                        textBox3.Text  = theDetectionData.detectionDataArray[0].DetectionRouteA;
                        textBox4.Text  = theDetectionData.detectionDataArray[0].DetectionRouteB;
                        textBox5.Text  = theDetectionData.detectionDataArray[0].DetectionRouteC;

                        textBox7.Text  = theDetectionData.detectionDataArray[1].DetectionName;
                        textBox16.Text = theDetectionData.detectionDataArray[1].DetectionNumber;
                        textBox10.Text = theDetectionData.detectionDataArray[1].DetectionRouteA;
                        textBox9.Text  = theDetectionData.detectionDataArray[1].DetectionRouteB;
                        textBox8.Text  = theDetectionData.detectionDataArray[1].DetectionRouteC;

                        textBox11.Text = theDetectionData.detectionDataArray[2].DetectionName;
                        textBox15.Text = theDetectionData.detectionDataArray[2].DetectionNumber;
                        textBox14.Text = theDetectionData.detectionDataArray[2].DetectionRouteA;
                        textBox13.Text = theDetectionData.detectionDataArray[2].DetectionRouteB;
                        textBox12.Text = theDetectionData.detectionDataArray[2].DetectionRouteC;
                    }
                }
            }
        }
コード例 #7
0
        private void BoardButton_Click(object sender, RoutedEventArgs e)
        {
            string[]          args = Environment.GetCommandLineArgs();
            Image <Hsv, byte> img  = new Image <Hsv, byte>(args[1]);

            Image <Gray, byte> blue   = ImageTools.FilterColor(img, new Hsv(90, 90, 50), new Hsv(120, 255, 255));
            Image <Gray, byte> green  = ImageTools.FilterColor(img, new Hsv(35, 70, 35), new Hsv(90, 255, 255));
            Image <Gray, byte> yellow = ImageTools.FilterColor(img, new Hsv(10, 70, 127), new Hsv(35, 255, 255));
            Image <Gray, byte> red    = ImageTools.FilterColor(
                img,
                new KeyValuePair <Hsv, Hsv>[] {
                new KeyValuePair <Hsv, Hsv>(new Hsv(0, 85, 80), new Hsv(12, 255, 255)),
                new KeyValuePair <Hsv, Hsv>(new Hsv(150, 85, 80), new Hsv(179, 255, 255))
            }
                );

            DetectionData ddb = ImageTools.DetectSquares(blue);
            DetectionData ddr = ImageTools.DetectSquares(red);
            DetectionData ddg = ImageTools.DetectSquares(green);
            DetectionData ddy = ImageTools.DetectSquares(yellow);

            ddb.RemoveNoises();
            ddr.RemoveNoises();
            ddg.RemoveNoises();
            ddy.RemoveNoises();
            ddb.AddColor(ddr);
            ddb.AddColor(ddg);
            ddb.AddColor(ddy);

            var board = ddb.CreateBoard();
            var di    = ddb.DrawDetection().Bitmap;

            MessageBox.Show("Detected board: " + board.Height + "x" + board.Width);

            ImageTools.ShowInNamedWindow(img.Convert <Bgr, byte>(), "Original");
        }
コード例 #8
0
 public DataInfo(cycleDataArray thecycleDataArray, DetectionData theDetectionData)
 {
     this.thecycleDataArray = thecycleDataArray;
     this.theDetectionData  = theDetectionData;
     InitializeComponent();
 }