// Gjen katrorin mbajtes te nje konturi private ProcessedContour FindBoundBoxOfAContour(List <Contour> CodeContour) { // Do permbaje te gjitha informacionet ProcessedContour results = new ProcessedContour(); // Per cdo kontur for (int cont = 0; cont < CodeContour.Count; cont++) { // Merren pikat X & Y te konturit List <int> xVal = CodeContour[cont].GetXValue(); List <int> yVal = CodeContour[cont].GetYValue(); // Vendosen vlerat mnimale dhe maksimale qe do mbishkruhen Vector2 maxXY = new Vector2(-1, -1), minXY = new Vector2(ImageWidth + 1, ImageHeight + 1); // Per cdo vlere te X, gjem maksimumin dhe minimumin for (int i = 0; i < xVal.Count; i++) { if (xVal[i] >= maxXY.x) { maxXY.x = xVal[i]; } if (yVal[i] >= maxXY.y) { maxXY.y = yVal[i]; } if (xVal[i] <= minXY.x) { minXY.x = xVal[i]; } if (yVal[i] <= minXY.y) { minXY.y = yVal[i]; } } // Llogarisim distancen , gjeresin e lartesin int distanceMinMaxX = (int)Vector2.Distance(new Vector2(minXY.x, 0f), new Vector2(maxXY.x, 0f)); int distanceMinMaxY = (int)Vector2.Distance(new Vector2(0f, minXY.y), new Vector2(0f, maxXY.y)); // Filtrim ne varesi te distances (gjeresi dhe lartesi), vleres x y, germa eshte me e gjate se e gjere if (distanceMinMaxX > DimensionOfPlateCharX_Min_Max.x && distanceMinMaxY > DimensionOfPlateCharY_Min_Max.x && distanceMinMaxX < DimensionOfPlateCharX_Min_Max.y && distanceMinMaxY < DimensionOfPlateCharY_Min_Max.y && distanceMinMaxY > distanceMinMaxX && (int)minXY.y > 0 && (int)minXY.x > 0 && (int)maxXY.y > 0 && (int)maxXY.x > 0) { results.MaxPoints.Add(maxXY); results.MinPoints.Add(minXY); results.SavedCont.Add(CodeContour[cont]); } } // Kthejem rezultatet return(results); }
// Lokalizon Kodet me te mundshme per te qene nje Targe // Grupon kodet e ngjashme dhe me vone filtrohen public void LocalizePlateString() { // Gjene pikat Max, Min qe perbejn konturin qe do permbaje nje kod ProcessedContour GetContourResultsProcess = FindBoundBoxOfAContour(ContourPath); // Shpetohen localisht keto konture List <Vector2> MaxPoints = GetContourResultsProcess.MaxPoints; List <Vector2> MinPoints = GetContourResultsProcess.MinPoints; // Dhe Kodet List <Contour> CodeContour = GetContourResultsProcess.SavedCont; List <PossiblePlateChar> PossiblePlateGroups = new List <PossiblePlateChar>(); List <int> DrawsIndexes = new List <int>(); List <int> NumberOfSimilarity = new List <int>(); // Per cdo kontur for (int i = 0; i < MaxPoints.Count; i++) { // Nqs ky kontur nk eshte procesuar if (!DrawsIndexes.Contains(i)) { DrawsIndexes.Add(i); NumberOfSimilarity.Add(1); // Shtohet konturi se kodi nje kode qe nk ngjason me asnje tjeter PossiblePlateGroups.Add(new PossiblePlateChar(i, MaxPoints[i], MinPoints[i], CodeContour[i])); } // Per cdo konture for (int j = 0; j < MaxPoints.Count; j++) { // Llogarisim gjeresin te konturave qe do krahasohen float yDistanceCurrent = Vector2.Distance(new Vector2(0f, MinPoints[i].y), new Vector2(0f, MaxPoints[i].y)); float yDistanceTesting = Vector2.Distance(new Vector2(0f, MinPoints[j].y), new Vector2(0f, MaxPoints[j].y)); // Llogarisim Ratio float ratio = yDistanceCurrent / yDistanceTesting; // Raposti i ngjashmerise duhet te jete brenda vlerave if (ratio > .8f && ratio < 1.2f && i != j) { // Nqs konturi qe po krahasohet nk eshte procesuar ose pjese te nje grupi if (!DrawsIndexes.Contains(j)) { DrawsIndexes.Add(j); NumberOfSimilarity.Add(1); // Shtohet ky kontur tek grupi i ngajshmerive PossiblePlateGroups.Add(new PossiblePlateChar(j, MaxPoints[j], MinPoints[j], CodeContour[j])); // Shtohen elementet te ngjshme te nje indexi NumberOfSimilarity[DrawsIndexes.IndexOf(i)]++; PossiblePlateGroups[DrawsIndexes.IndexOf(i)].AddPattern(j, MaxPoints[j], MinPoints[j], CodeContour[j]); } } } } // Nqs kemi konture te ngjashme if (NumberOfSimilarity.Count > 0) { // Gjem ate me vleren maximale int MaxIndex = NumberOfSimilarity.IndexOf(NumberOfSimilarity.Max()); // Shpetojm grupin e kodeve me m shume ngjashmeri PossiblePlate = PossiblePlateGroups[MaxIndex]; // Filtrojm kodet PossiblePlate.ProcessTheSimilarCode(); } }
// Rregullon prespektive dhe rrotullimin te nje grup konturesh public void SlantCorrection(float SlantThreshold) { // Nqs kemi nje potencial targe if (PossiblePlate != null) { // Vlerat qe do permbajn indekset te 1 corrected, 0 blancked List <Vector3> CorrectedValues = new List <Vector3>(); List <Vector2> BlanckedValues = new List <Vector2>(); // Marrim rreshtat te kesaj targe (mudn te jene dhe 2) List <Rows> PlateRows = PossiblePlate.GetPlateRows(); // Per cdo rresht for (int i = 0; i < PlateRows.Count; i++) { // Marrim kendin e prespektives float slantAngle = PlateRows[i].GetSlantAngle(); // Nqs kalon nje Thresholde if (Mathf.Abs(slantAngle) > SlantThreshold) { // Marrim kendin ne radioan slantAngle *= (Mathf.PI / 180f); // Qendren e rrotullimit Vector2 centerOfSlantCorrection = PlateRows[i].GetCenterOfRotation(); // Listen te kotureve qe permbejn kete rresht List <Vector2> MaxPoints = PlateRows[i].GetMaxList(); List <Vector2> MinPoints = PlateRows[i].GetMinList(); List <Contour> RotatedContour = new List <Contour>(); // Per cdo kontur for (int j = 0; j < MaxPoints.Count; j++) { // Shtojm konturin e procesuar RotatedContour.Add(new Contour()); for (int x = (int)MinPoints[j].x; x <= MaxPoints[j].x; x++) { for (int y = (int)MinPoints[j].y; y <= MaxPoints[j].y; y++) { // Llogarisim koordinatat e rrotulluara Vector2 rotatedPoint = RotatePoint((float)x, (float)y, centerOfSlantCorrection, slantAngle); // Shpetojm pikat qe do ndryshohen dhe pikat e ndryshuara CorrectedValues.Add(new Vector3(rotatedPoint.x, rotatedPoint.y, ImageMatrix[x, y])); BlanckedValues.Add(new Vector3(x, y)); // Rrotullojm dhe konturet me vlere -1 if (ImageMatrix[x, y] == -1) { RotatedContour[RotatedContour.Count - 1].AddPoint((int)rotatedPoint.x, (int)rotatedPoint.y); } } } } // Gjene pikat Max, Min qe perbejn konturin qe do permbaje nje kod ProcessedContour reprocessBoundBoxAfterRotation = FindBoundBoxOfAContour(RotatedContour); // Mbivendosim rreshtat PlateRows[i].SetRows(reprocessBoundBoxAfterRotation.MaxPoints, reprocessBoundBoxAfterRotation.MinPoints, reprocessBoundBoxAfterRotation.SavedCont); } } #region DRAWING_FUNCTIONS try { // Mbishkruajm grafikisht imazhin for (int i = 0; i < BlanckedValues.Count; i++) { ImageMatrix[(int)BlanckedValues[i].x, (int)BlanckedValues[i].y] = 0; } for (int i = 0; i < CorrectedValues.Count; i++) { ImageMatrix[(int)CorrectedValues[i].x, (int)CorrectedValues[i].y] = CorrectedValues[i].z; } } catch { Debug.Log("Error Correcting Slant"); } #endregion } }