Exemple #1
0
        /// <summary>
        /// Realiza identificação dos pontos na imagem.
        /// </summary>
        private void btnIdentificarPontos_Click(object sender, EventArgs e)
        {
            Cursor.Current = Cursors.WaitCursor;

            // desabilita botão
            this.btnProximo.Enabled = false;

            // bitmap a ser processado
            Bitmap drawBitmap = (Bitmap)this.selectedBitmap.Clone();

            // dados do bitmap
            byte[, ,] bmpData;
            BitmapTools.GetBitmapData(drawBitmap, out bmpData);

            // saturação
            BitmapTools.Saturation(ref bmpData, 4.5);

            //Bitmap teste1 = (Bitmap)this.selectedBitmap.Clone();
            //BitmapTools.SetBitmapData(teste1, ref bmpData);
            //teste1.Save("c:\\temp\\testeSat.jpg");

            // limiarização
            BitmapTools.Thresholding(ref bmpData, PointType.Green, 0, 255);

            //Bitmap teste2 = (Bitmap)this.selectedBitmap.Clone();
            //BitmapTools.SetBitmapData(teste2, ref bmpData);
            //teste2.Save("c:\\temp\\testeThreshold.jpg");

            // redução de ruído
            BitmapTools.BlackAndWhiteNoiseReduction(ref bmpData, 127);

            // template matching
            this.pointsList = BitmapTools.FindImagePoints(ref bmpData, this.fatorCorrelacao);

            if (this.pointsList.Count != 6 && this.pointsList.Count != 12)
            {
                MessageBox.Show(this, this.resourceMgr.GetString("MSG0012"), this.Text,
                                MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            else
            {
                // habilita botão
                this.btnProximo.Enabled = true;

                // reordena pontos considerando a ordem de scan
                if (this.pointsList[0].X > this.pointsList[1].X)
                {
                    PointCorrelation p = this.pointsList[0];
                    this.pointsList[0] = this.pointsList[1];
                    this.pointsList[1] = p;
                }

                if (this.pointsList[2].X > this.pointsList[3].X)
                {
                    PointCorrelation p = this.pointsList[2];
                    this.pointsList[2] = this.pointsList[3];
                    this.pointsList[3] = p;
                }

                if (this.pointsList[4].X > this.pointsList[5].X)
                {
                    PointCorrelation p = this.pointsList[4];
                    this.pointsList[4] = pointsList[5];
                    this.pointsList[5] = p;
                }

                if (this.pointsList.Count == 12)
                {
                    // reordena pontos considerando a ordem de scan
                    if (this.pointsList[6].X > this.pointsList[7].X)
                    {
                        PointCorrelation p = this.pointsList[6];
                        this.pointsList[6] = this.pointsList[7];
                        this.pointsList[7] = p;
                    }

                    if (this.pointsList[8].X > this.pointsList[9].X)
                    {
                        PointCorrelation p = this.pointsList[8];
                        this.pointsList[8] = this.pointsList[9];
                        this.pointsList[9] = p;
                    }

                    if (this.pointsList[10].X > this.pointsList[11].X)
                    {
                        PointCorrelation p = this.pointsList[10];
                        this.pointsList[10] = pointsList[11];
                        this.pointsList[11] = p;
                    }
                }
            }

            // desenha pontos
            DesenharPontos(drawBitmap);

            // atualiza PictureBox
            this.pctImagem.Image = drawBitmap;

            Cursor.Current = Cursors.Default;
        }
Exemple #2
0
        /// <summary>
        /// Realiza identificação dos pontos na imagem.
        /// </summary>
        private void btnIdentificarPontos_Click(object sender, EventArgs e)
        {
            Cursor.Current = Cursors.WaitCursor;

            // desabilita botão
            this.btnProximo.Enabled = false;

            // bitmap a ser processado
            Bitmap drawBitmap = (Bitmap)this.selectedBitmap.Clone();

            // dados do bitmap
            byte[, ,] bmpData;
            BitmapTools.GetBitmapData(drawBitmap, out bmpData);

            // saturação
            BitmapTools.Saturation(ref bmpData, 4.5);

            //Bitmap teste1 = (Bitmap)this.selectedBitmap.Clone();
            //BitmapTools.SetBitmapData(teste1, ref bmpData);
            //teste1.Save("c:\\temp\\ImagensTeste\\testeSat.jpg");

            // limiarização
            BitmapTools.Thresholding(ref bmpData, PointType.Blue, 0, 255);

            //Bitmap teste2 = (Bitmap)this.selectedBitmap.Clone();
            //BitmapTools.SetBitmapData(teste2, ref bmpData);
            //teste2.Save("c:\\temp\\ImagensTeste\\testeThreshold.jpg");

            // redução de ruído
            BitmapTools.BlackAndWhiteNoiseReduction(ref bmpData, 127);

            //Bitmap teste3 = (Bitmap)this.selectedBitmap.Clone();
            //BitmapTools.SetBitmapData(teste3, ref bmpData);
            //teste3.Save("c:\\temp\\ImagensTeste\\testeNoiseReduction.jpg");

            // template matching
            this.pointsList = BitmapTools.FindImagePoints(ref bmpData, this.fatorCorrelacao);

            if (this.pointsList.Count != 16)
            {
                MessageBox.Show(this, this.resourceMgr.GetString("MSG0012"), this.Text,
                                MessageBoxButtons.OK, MessageBoxIcon.Error);

                //StreamWriter sw = new StreamWriter(@"c:\\temp\\pontos.txt");
                //foreach (PointCorrelation pt in this.pointsList)
                //{
                //    sw.WriteLine("{0},{1}", pt.X, pt.Y);
                //}
                //sw.Close();
            }
            else
            {
                // troca pontos 15 e 16 (se necessário)
                if (this.pointsList[14].X < this.pointsList[15].X)
                {
                    PointCorrelation p = this.pointsList[15];
                    this.pointsList[15] = this.pointsList[14];
                    this.pointsList[14] = p;
                }

                // troca pontos 2 e 3 (se necessário)
                if (this.pointsList[1].X < this.pointsList[2].X)
                {
                    PointCorrelation p = this.pointsList[1];
                    this.pointsList[1] = this.pointsList[2];
                    this.pointsList[2] = p;
                }

                // habilita botão
                this.btnProximo.Enabled = true;
            }

            // desenha pontos
            DesenharPontos(drawBitmap);

            //drawBitmap.Save("c:\\temp\\ImagensTeste\\testeDrawPoints.jpg");

            // atualiza PictureBox
            this.pctImagem.Image = drawBitmap;

            Cursor.Current = Cursors.Default;
        }