private string recognizeWord(WordPosition word, int rowPixel) { string wordText = ""; int tmpWidth = 3 * letterInformation.CropWidth; int tmpHeight = 3 * letterInformation.CropHeight; int trashsize = letterInformation.TrashSize; OCRExtractLetter extractionLetter = new OCRExtractLetter(tmpWidth, tmpHeight, trashsize); int letterSize = letterInformation.LetterSize; int start = word.StartPixel; int end = word.EndPixel; Color white = Color.WHITE; Color color; //====================================================================== for (int j = start; j < end; j++) { for (int k = -(letterSize / 4); k < (letterSize / 4); k++) { int i = rowPixel + k; if (i < 0 || i > image.Height) { continue; } //====================================================================== // gornja vrzija je ispravna ova ne radi kako treba // for (int k = -(letterSize / 4); k < (letterSize / 4); k++) { // int i = rowPixel + k; // if (i < 0 || i > image.getHeight()) { // continue; // } // for (int j = start; j < end; j++) { //====================================================================== color = new Color(image.getRGB(j, i)); if (color.Equals(white)) { visited[i][j] = true; } else if (visited[i][j] == false) { BufferedImage letter = extractionLetter.extraxtLetter(image, visited, i, j); //OCRUtilities.extraxtCharacterImage(image, visited, i, j, tmpWidth, tmpHeight, letterInformation.getTrashSize()); if (letter != null) { OCRCropLetter crop = new OCRCropLetter(letter, letterInformation.CropWidth, letterInformation.CropHeight); BufferedImage croped = crop.processImage(); wordText += recognizeLetter(croped); } } } } return(wordText); }
private void createImagesWithLetters() { int cropWidth = letterInformation.CropWidth; int cropHeight = letterInformation.CropHeight; int tmpWidth = 3 * cropWidth; int tmpHeight = 3 * cropHeight; int trashSize = letterInformation.TrashSize; OCRExtractLetter extractionLetter = new OCRExtractLetter(tmpWidth, tmpHeight, trashSize); int letterSize = letterInformation.LetterSize; int imageHeight = image.Height; int imageWidth = image.Width; //JAVA TO C# CONVERTER NOTE: The following call to the 'RectangularArrays' helper class reproduces the rectangular array initialization that is automatic in Java: //ORIGINAL LINE: bool[][] visited = new bool[imageHeight][imageWidth]; bool[][] visited = RectangularArrays.ReturnRectangularBoolArray(imageHeight, imageWidth); Color white = Color.WHITE; Color color; int seqNum = 0; for (int line = 0; line < textInformation.numberOfRows(); line++) { //============================================================================== for (int j = 0; j < imageWidth; j++) { for (int k = -(letterSize / 4); k < (letterSize / 4); k++) { int rowPixel = textInformation.getRowAt(line); int i = rowPixel + k; if (i < 0 || i >= imageHeight) { continue; } //============================================================================== // fornja verzija radi, ova ima gresku // for (int k = -(letterSize / 4); k < (letterSize / 4); k++) { // int rowPixel = textInformation.getRowAt(line); // int i = rowPixel + k; // if (i < 0 || i >= imageHeight) { // continue; // } // for (int j = 0; j < imageWidth; j++) { //============================================================================== color = new Color(image.getRGB(j, i)); if (color.Equals(white)) { visited[i][j] = true; } else if (visited[i][j] == false) { BufferedImage letter = extractionLetter.extraxtLetter(image, visited, i, j); // OCRUtilities.extraxtCharacterImage(image, visited, i, j, tmpWidth, tmpHeight, letterInformation.getTrashSize()); if (letter != null) { OCRCropLetter crop = new OCRCropLetter(letter, cropWidth, cropHeight); BufferedImage croped = crop.processImage(); string character = trainingText[seqNum] + ""; string name = character + "_" + seqNum; OCRUtilities.saveToFile(croped, folderPath, name, imageExtension); seqNum++; } } } } } }