Пример #1
0
    public void UpdateValues()
    {
        if (MainRecognitionBehaviour == null)
        {
            MainRecognitionBehaviour = gameObject.AddComponent <MainRecognition>();
        }

        MainRecognitionBehaviour.UpdateValues(EachFrame, RecognizePlateCode, ApplyPlateCodeSlantCorrection, ExtractPlateString, ContrastValue, GammaCorrectionValue
                                              , BynarizationThreshold, MedianGroupPixel, DimensionOfPlateCharX_Min_Max, DimensionOfPlateCharY_Min_Max
                                              , MinLenghtOfPlateRow, NumberOfPlatesToTrack, SlantThreshold);
    }
Пример #2
0
    // Filtrimi i rreshtave, disa grup kodesh mund te jene te shkaktuar nga zhurmat e ambjentit ose stema te jashtme
    // Bahkojm dy rreshtat qe jane shume afer nj-tj (targe me dy rreshta) dhe shuajm rreshtat jasht standarteve
    private void FilterCodeNoises()
    {
        // Filtrojm nqs kemi 2 ose me shume rreshta, zgjedhim me te pershtatshimn
        if (PotentialPlateRows.Count > 1)
        {
            List <Vector2> CentersOfRows = new List <Vector2>();

            for (int i = 0; i < PotentialPlateRows.Count; i++)
            {
                // Nisim procesin te llogaritjeve te rreshtit
                PotentialPlateRows[i].CalculateRowsPropeties();
                // Shpetojm qendren te rreshtit
                CentersOfRows.Add(PotentialPlateRows[i].GetCenterOfRows());
            }
            // Per cdo vlere te qendres se rreshtit bejm disa llogaritje
            for (int i = 0; i < CentersOfRows.Count - 1; i++)
            {
                // Duhet te zgjedhim rreshtat qe jane me afer nj-tj dhe qe plotesoj disa kushte
                float distance = Mathf.Infinity;

                for (int j = i + 1; j < CentersOfRows.Count; j++)
                {
                    // nqs rreshtat ne fjale jane te n dryshme nga nj-tj (pasi kemi nje ndryshim indeksi me posht)
                    if (i != j)
                    {
                        // Marrim distancen ndermjet rreshtave
                        float distanceOfCenterRows = Vector2.Distance(CentersOfRows[i], CentersOfRows[j]);
                        // Distancen ne X
                        float xDis = Vector2.Distance(new Vector2(CentersOfRows[i].x, 0f), new Vector2(CentersOfRows[j].x, 0f));
                        // Distancen ne Y
                        float yDis = Vector2.Distance(new Vector2(0f, CentersOfRows[i].y), new Vector2(0f, CentersOfRows[j].y));
                        // Rreshti me disatnce me te vogle dhe me distance brenda kufijve mesatare * 2
                        if (distanceOfCenterRows < distance &&
                            xDis <= PotentialPlateRows[i].GetAverangeXDistance() * 2f &&
                            yDis <= PotentialPlateRows[i].GetAverangeYDistance() * 2f)
                        {
                            // Duhet ta shtojm ne fund kete rresht apo ne fillimi ?
                            if (CentersOfRows[j].y < CentersOfRows[i].y)
                            {
                                // Shtojm ne fund rreshtin e llogaritur
                                PotentialPlateRows[i].InsertRows(PotentialPlateRows[i].GetSize(), PotentialPlateRows[j].GetMaxList(),
                                                                 PotentialPlateRows[i].GetSize(), PotentialPlateRows[j].GetMinList(),
                                                                 PotentialPlateRows[i].GetSize(), PotentialPlateRows[j].GetRowContours());
                            }
                            else
                            {
                                // Shtojm ne fillim rreshtin e llogaritur
                                PotentialPlateRows[i].InsertRows(0, PotentialPlateRows[j].GetMaxList(),
                                                                 0, PotentialPlateRows[j].GetMinList(),
                                                                 0, PotentialPlateRows[j].GetRowContours());
                            }
                            // Shpetojm distancen
                            distance = distanceOfCenterRows;
                            // Fshijm rreshtin qe sapo kemi bashkuar dhe qendren e tij
                            PotentialPlateRows.RemoveAt(j);
                            CentersOfRows.RemoveAt(j);
                            // Zbresim indeksin qe te mos kalojm "CentersOfRows.Count" dhe te mos humbasim vlera
                            j--;
                        }
                    }
                }
            }
        }
        // Per cdo rresht te mbetur
        for (int i = 0; i < PotentialPlateRows.Count; i++)
        {
            // Kodet qe permban ai rresht jane te mjaftueshme per tu konsideruar Grup germash ?
            if (PotentialPlateRows[i].GetSize() < MainRecognition.GetMinCodeLenghtOfPlateRow())
            {
                // Fshirja te rreshtit jasht standartit
                PotentialPlateRows.RemoveAt(i);
                i--;
            }
        }

        if (PotentialPlateRows.Count >= MainRecognition.GetNumberOfPlatesToTrack() && PotentialPlateRows.Count != 1)
        {
            // Rreshtojm rreshtat sipas atyj qe ka grup kodesh me te madh
            // Bubble Sort pasi nk jane shume elementet
            for (int i = 0; i < PotentialPlateRows.Count - 1; i++)
            {
                for (int j = i + 1; j < PotentialPlateRows.Count; j++)
                {
                    if (PotentialPlateRows[i].GetSize() < PotentialPlateRows[j].GetSize())
                    {
                        Rows tempRow = PotentialPlateRows[i];
                        PotentialPlateRows[i] = PotentialPlateRows[j];
                        PotentialPlateRows[j] = tempRow;
                    }
                }
            }
            // Sa targa duhen te trackohen njekohesisht ?
            // fshijm rreshtat qe kane pak elemente te bazuar sipas trackimit paralel
            for (int i = MainRecognition.GetNumberOfPlatesToTrack(); i < PotentialPlateRows.Count; i++)
            {
                PotentialPlateRows.RemoveAt(i);
                i--;
            }
        }
    }