/// <summary> /// A method which will loop trough each char and calculate the offset between /// all the characters /// </summary> /// <returns>An array filled with the differene</returns> private int[] calculateDifference() { // An array which will be filled with the difference between each char int[] difference = new int[5]; // A reference to the previous License char LicenseCharacter previous = chars[0]; // Loop through for (int i = 1; i < chars.Count; i++) { // Calculate the differene between each difference[i - 1] = chars[i].middle - previous.middle; previous = chars[i]; } return(difference); }
/// <summary> /// A method which creates the best possible match for a license plate /// </summary> /// <param name="pos1">The position of the first stripe</param> /// <param name="pos2">The posisiton of the second stripe</param> /// <param name="partsNum">The kenType array</param> /// <param name="matcher">The BlobMatcher</param> private void createBestMatch(int pos1, int pos2, kenType[] partsNum, BlobMatcher_Int16 matcher) { // ************************************************************** // ** Creates the best match based on: ** // ** - If there should be a number, but char found: ** // ** - Find a number in the results and change it ** // ** - If there should be a number and number found ** // ** - If the next match is a character then we can ** // ** up the confidence a lot ** // ** - If the then following match is a number we ** // ** can up it a little ** // ** ** // ** - This also aplies for chars ** // ************************************************************** // A pointer which points to the partsNum place where we are at int partNumPlace = 0; const double maxError = 0.20; // Go through all the chars for (int i = 0; i < chars.Count; i++) { // Check if we need to up the pointer if (i == pos1 || i == pos2) { partNumPlace += 1; } // If there should be a number found if (partsNum[partNumPlace] == kenType.NUMBER && chars[i].error < maxError) { // If it isn't a number if (!Char.IsNumber(chars[i].character[0])) { // Loop through the results and find a number foreach (PatternMatchResult patrn in chars[i].PatternResults) { // if this is a number if (Char.IsNumber(matcher.PatternName(patrn.id)[0])) { // Change the chars value to this number chars[i] = new LicenseCharacter(matcher.PatternName(patrn.id), -0.04, 41); break; } } // End for loop } // End number expected but not found else if (chars[i].error > 0.11) // If there should be a number and a number was found { // Check if the next match is a char if (!Char.IsNumber(matcher.PatternName(chars[i].PatternResults[1].id)[0])) { // If so we can up the confidence chars[i] = new LicenseCharacter(chars[i].character, -0.02, 41); } // If the then following match is a char else if (!Char.IsNumber(matcher.PatternName(chars[i].PatternResults[2].id)[0])) { // Then we up the confidence a little chars[i] = new LicenseCharacter(chars[i].character, -0.01, chars[i].confidence + 0.1); } } } // Check if we should expect a char and the error value isn't to high else if (partsNum[partNumPlace] == kenType.CHAR && chars[i].error < maxError) { // Char expected but number found if (Char.IsNumber(chars[i].character[0])) { // Loop through the matches foreach (PatternMatchResult patrn in chars[i].PatternResults) { if (!Char.IsNumber(matcher.PatternName(patrn.id)[0])) { // If a char was found change the chars[i] value to it chars[i] = new LicenseCharacter(matcher.PatternName(patrn.id), -0.04, 41); break; } } // End for loop } // If we already have a char else if (chars[i].error > 0.11) { // Check if the second match is a number if (Char.IsNumber(matcher.PatternName(chars[i].PatternResults[1].id)[0])) { // If so we can up the confidence a lot chars[i] = new LicenseCharacter(chars[i].character, -0.02, 41); } // Check if the then following match is a number else if (Char.IsNumber(matcher.PatternName(chars[i].PatternResults[2].id)[0])) { // If so then we can up the confidence a little chars[i] = new LicenseCharacter(chars[i].character, -0.01, chars[i].confidence + 0.1); } } // End char expected and char found } // End char expected } // End loop // Done }
/// <summary> /// A method which creates the best possible match for a license plate /// </summary> /// <param name="pos1">The position of the first stripe</param> /// <param name="pos2">The posisiton of the second stripe</param> /// <param name="partsNum">The kenType array</param> /// <param name="matcher">The BlobMatcher</param> private void createBestMatch(int pos1, int pos2, kenType[] partsNum, BlobMatcher_Int16 matcher) { // ************************************************************** // ** Creates the best match based on: ** // ** - If there should be a number, but char found: ** // ** - Find a number in the results and change it ** // ** - If there should be a number and number found ** // ** - If the next match is a character then we can ** // ** up the confidence a lot ** // ** - If the then following match is a number we ** // ** can up it a little ** // ** ** // ** - This also aplies for chars ** // ************************************************************** // A pointer which points to the partsNum place where we are at int partNumPlace = 0; const double maxError = 0.20; // Go through all the chars for (int i = 0; i < chars.Count; i++) { // Check if we need to up the pointer if (i == pos1 || i == pos2) partNumPlace += 1; // If there should be a number found if (partsNum[partNumPlace] == kenType.NUMBER && chars[i].error < maxError) { // If it isn't a number if (!Char.IsNumber(chars[i].character[0])) { // Loop through the results and find a number foreach (PatternMatchResult patrn in chars[i].PatternResults) { // if this is a number if (Char.IsNumber(matcher.PatternName(patrn.id)[0])) { // Change the chars value to this number chars[i] = new LicenseCharacter(matcher.PatternName(patrn.id), -0.04, 41); break; } } // End for loop } // End number expected but not found else if (chars[i].error > 0.11) // If there should be a number and a number was found { // Check if the next match is a char if (!Char.IsNumber(matcher.PatternName(chars[i].PatternResults[1].id)[0])) { // If so we can up the confidence chars[i] = new LicenseCharacter(chars[i].character, -0.02, 41); } // If the then following match is a char else if (!Char.IsNumber(matcher.PatternName(chars[i].PatternResults[2].id)[0])) { // Then we up the confidence a little chars[i] = new LicenseCharacter(chars[i].character, -0.01, chars[i].confidence + 0.1); } } } // Check if we should expect a char and the error value isn't to high else if (partsNum[partNumPlace] == kenType.CHAR && chars[i].error < maxError) { // Char expected but number found if (Char.IsNumber(chars[i].character[0])) { // Loop through the matches foreach (PatternMatchResult patrn in chars[i].PatternResults) { if (!Char.IsNumber(matcher.PatternName(patrn.id)[0])) { // If a char was found change the chars[i] value to it chars[i] = new LicenseCharacter(matcher.PatternName(patrn.id), -0.04, 41); break; } } // End for loop } // If we already have a char else if (chars[i].error > 0.11) { // Check if the second match is a number if (Char.IsNumber(matcher.PatternName(chars[i].PatternResults[1].id)[0])) { // If so we can up the confidence a lot chars[i] = new LicenseCharacter(chars[i].character, -0.02, 41); } // Check if the then following match is a number else if (Char.IsNumber(matcher.PatternName(chars[i].PatternResults[2].id)[0])) { // If so then we can up the confidence a little chars[i] = new LicenseCharacter(chars[i].character, -0.01, chars[i].confidence + 0.1); } } // End char expected and char found } // End char expected } // End loop // Done }