Ejemplo n.º 1
0
        private void DiagonalsAndRotation2(int type)
        {
            imagen.GetChannels();

            extractArgs();


            if (type == 0)
            {
                factorDiago = 0.90;
            }



            imagen.detect = new Detector();



            Image <Rgb, byte> final = imagen.UIOne.Convert <Rgb, byte>().CopyBlank();

            int    resetvalor = 11;
            int    detectType = 2; //lines
            int    step       = 2;
            double threshold  = 220;
            int    max        = 19;
            int    xorder     = Convert.ToInt16(xorderbox.Text);
            int    yorder     = Convert.ToInt16(yorderbox.Text);

            imagen.SobelRoutine(detectType, step, threshold, max, resetvalor, xorder, yorder);

            imagen.GetDiagonalsRoutine(factorDiago);
            imagen.detect.DrawDiagonals(ref final);


            imagen.detect.GetAvgDiagonalsPosNeg(true);

            this.rgbbox.Image = final.Bitmap;

            //  MessageBox.Show("1.1");

            Rgb r = new Rgb(255, 255, 255);

            final = final.InRange(r, r).Convert <Rgb, byte>().Clone();

            this.segmentBox.Image = final.Bitmap;

            //
            final = final.CopyBlank();
            //  MessageBox.Show("1.2");

            Rgb[] color = new Rgb[3];
            imagen.detect.PickColorsAvg(type, ref color);
            Image <Rgb, byte>[] arr = imagen.detect.DrawDetectedAvg(ref final, ref color, false);


            printSteps(ref final, ref arr);

            //  MessageBox.Show("1.2");

            imagen.FindRotation(lastSum);


            this.richTextBox1.Text = imagen.detect.msgBuilder.ToString();
            this.segmentBox.Image  = rgbbox.Image;


            //factores

            Image <Rgba, byte> other = imagen.imgUtil.rotated.Clone();


            ImgDB.BasicInfoRow red   = imagen.BInfo.table.FirstOrDefault(o => o.Channel == 0);
            ImgDB.BasicInfoRow green = imagen.BInfo.table.FirstOrDefault(o => o.Channel == 1);
            ImgDB.BasicInfoRow blue  = imagen.BInfo.table.FirstOrDefault(o => o.Channel == 2);
            ImgDB.BasicInfoRow alpha = imagen.BInfo.table.FirstOrDefault(o => o.Channel == 3);



            //imagen.imgUtil.rotated._EqualizeHist() ;
            Img.ChangeColor(ref imagen.imgUtil.rotated, (float)red.Factor, (float)green.Factor, (float)blue.Factor, (float)alpha.Factor);
            //imagen.UIOne = imagen.imgUtil.rotated;
            this.rgbbox.Image = imagen.imgUtil.rotated.Bitmap;
            // this.matrixBox.Matrix = imagen.imgUtil.rotated.Mat.Data;

            imagen.imgUtil.rotated.Save(imagen.path + "\\" + imagen.curentfilename.Replace(".jpg", ".out.jpg"));
            //  originalBox.Image = imagen.escaledUI.Bitmap;


            float sum = (float)(red.Avg + green.Avg + blue.Avg);

            sum /= 3;
            float rF = 1;
            float gF = 1;
            float bF = 1;
            float AF = 1;

            rF = (float)(sum / red.Avg);
            gF = (float)(sum / green.Avg);
            bF = (float)(sum / blue.Avg);


            Img.ChangeColor(ref other, rF, gF, bF, AF);


            /*
             *
             * // CvInvoke.CLAHE(other, 1, new Size(10, 10), other);
             * double radius = Img.CalculateDiagonalLenght(other.Width, other.Height);
             * radius /= 2;
             * Point p = imagen.GetMiddlePointCanvas(radius, ref other);
             * Rectangle rec = new Rectangle(p.X , p.Y , 2, 2);
             * //  Rectangle rec = new Rectangle(p.X-(p.X*1/5), p.Y+ (p.Y * 3 / 2), 150,150);
             * //  other.ROI = rec;
             * Image<Rgba,byte> pantone  = other.GetSubRect(rec);
             * //  other.ROI = rec;
             * Point ul = new Point(rec.X, rec.Y);
             * Point bl = new Point(rec.Left, rec.Bottom);
             * Point ur = new Point(rec.Right, rec.Top);
             * Point br = new Point(rec.Right, rec.Bottom);
             * other.DrawPolyline(new Point[] { ul, bl, br, ur }, true, new Rgba(255, 0, 0, 255), 2, Emgu.CV.CvEnum.LineType.FourConnected);
             * //  source.CopyTo(destiny);
             * //   other.ROI = Rectangle.Empty;
             *
             *
             */


            // this.segmentBox.Image = pantone.Bitmap;
            this.segmentBox.Image = other.Bitmap;
        }