コード例 #1
0
        public String getPlate()
        {
            DTOBinaryObject patternObject = new DTOBinaryObject();
            DTOBinaryObject resizedObject = new DTOBinaryObject();
            List<Double> distances = new List<Double>();
            evaluateImages();

            String plate = String.Empty;
            double minimum = 1.0, distance = 1.0;
            Char character = ' ';
            var ordered = PlateObjects.OrderBy(x => x.Key);

            foreach (var varPlate in ordered)
            {
                DTOBinaryObject objeto = varPlate.Value;
                minimum = 1.0;

                foreach (int key in PatternObjects.Keys)
                {
                    patternObject = PatternObjects[key];
                    resizedObject = Scalar(objeto, patternObject.Height, patternObject.Width);
                    resizedObject.setCenterOfMass();

                    distance = tanimotoDistance(resizedObject, patternObject);

                    if (distance < minimum)
                    {
                        minimum = distance;
                        character = key < 10 ? key.ToString()[0] : Char.ToUpper((char)key);
                    }
                }

                distances.Add(minimum);
                plate += character;
            }

            while (distances.Count > 7)
            {
                int indexMax = !distances.Any() ? -1 : distances.
                    Select((value, index) => new { Value = value, Index = index })
                    .Aggregate((a, b) => (a.Value > b.Value) ? a : b).Index;

                distances.Remove(distances.Max());

                plate = plate.Remove(indexMax, 1);
            }

            if (Char.IsNumber(plate[2]))
            {
                plate = plate.Insert(2, "-");
                plate = plate.Insert(5, "-");
            }
            else
            {
                plate = plate.Insert(3, "-");
                plate = plate.Insert(6, "-");
            }

            return plate;
        }
コード例 #2
0
        public DTOBinaryObject Scalar(DTOBinaryObject binaryObject, int newHeight, int netWidth)
        {
            DTOBinaryObject newBinaryObject = new DTOBinaryObject();

            int tempX, tempY, it, itTemp;
            float esc_x = 0;
            float esc_y = 0;

            esc_y = (float)newHeight / (float)binaryObject.Height;
            esc_x = (float)netWidth / (float)binaryObject.Width;

            newBinaryObject.Label = binaryObject.Label;
            newBinaryObject.Height = newHeight;
            newBinaryObject.Width = netWidth;
            newBinaryObject.Pixels = new int[newHeight * netWidth];

            for (int iteratorHeight = 0; iteratorHeight < newHeight; iteratorHeight++)
            {
                for (int interatorWidth = 0; interatorWidth < netWidth; interatorWidth++)
                {
                    tempX = (int)(interatorWidth / esc_x);
                    tempY = (int)(iteratorHeight / esc_y);
                    it = iteratorHeight * netWidth + interatorWidth;
                    itTemp = tempY * binaryObject.Width + tempX;
                    newBinaryObject.Pixels[it] = binaryObject.Pixels[itTemp];
                }
            }

            newBinaryObject.setCenterOfMass();

            return newBinaryObject;
        }