Exemple #1
0
        public void GetPlate(int index, float sum1, float max)
        {
            bool input = false;
            int  k1 = 0, k2 = 0;

            for (int w = 1; w < Horizont[index].p.Length - 1; w++)
            {
                if (Horizont[index].p[w] > sum1)
                {
                    if (!input)
                    {
                        k1    = w;
                        input = true;
                    }
                }
                if (Horizont[index].p[w + 1] < sum1 && input)
                {
                    input = false;
                    k2    = w;
                    if (k2 - k1 < 50)
                    {
                        continue;
                    }
                    //List<int> Maxumums = SearchMaximums(Horizont[index].p, sum1, max, Horizont[index].sobel1, true);
                    //if (Maxumums.Count < 4)
                    //    continue;
                    Plate plate = new Plate();
                    plate.x1 = k1;
                    plate.x2 = k2;
                    plate.y1 = Horizont[index].k1;
                    plate.y2 = Horizont[index].k2;

                    plate.original = Original.Copy(new System.Drawing.Rectangle(plate.x1, plate.y1, plate.x2 - plate.x1, plate.y2 - plate.y1));
                    float sum = 0;
                    for (int hg = plate.y1; hg < plate.y2; hg++)
                    {
                        sum += u[hg];
                    }
                    double alpha = 0.15 * (plate.y2 - plate.y1) + 0.25 / 0.5 + 0.4 / sum + 0.4 * Math.Abs((Math.Abs(k1 - k2) / Math.Abs(plate.y1 - plate.y2)) - 5);
                    if (!Ugol(plate))
                    {
                        Plate.Add(plate);
                    }
                }
            }
        }
Exemple #2
0
        public bool Ugol(Plate plate)
        {
            LineSegment2D[]     lines = null;
            Image <Gray, byte>  gray  = plate.original.Convert <Gray, byte>();
            Image <Gray, float> sobel = gray.Sobel(0, 1, 3);

            CvInvoke.cvConvert(sobel, gray);
            try
            {
                lines = gray.HoughLinesBinary(1, Math.PI / 45, 50, sobel.Width / 3, 0)[0];
            }
            catch {  }
            if (lines == null || lines.Length == 0)
            {
                return(true);
            }

            double        angle = 0;
            LineSegment2D avr   = new LineSegment2D();

            foreach (LineSegment2D seg in lines)
            {
                avr.P1 = new System.Drawing.Point(avr.P1.X + seg.P1.X, avr.P1.Y + seg.P1.Y);
                avr.P2 = new System.Drawing.Point(avr.P2.X + seg.P2.X, avr.P2.Y + seg.P2.Y);
            }
            avr.P1 = new System.Drawing.Point(avr.P1.X / lines.Length, avr.P1.Y / lines.Length);
            avr.P2 = new System.Drawing.Point(avr.P2.X / lines.Length, avr.P2.Y / lines.Length);
            LineSegment2D horizontal = new LineSegment2D(avr.P1, new System.Drawing.Point(avr.P2.X, avr.P1.Y));

            double c = horizontal.P2.X - horizontal.P1.X;
            double a = Math.Abs(horizontal.P2.Y - avr.P2.Y);
            double b = Math.Sqrt(c * c + a * a);

            angle        = (a / b * (180 / Math.PI)) * (horizontal.P2.Y > avr.P2.Y ? 1 : -1);
            plate.Alpha  = angle;
            plate.rotate = plate.original.Rotate(angle, new Bgr(255, 255, 255));

            return(false);
        }