//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET: //ORIGINAL LINE: public static void main(String[] args) throws java.io.IOException public static void Main(string[] args) { // User input parameters //******************************************************************************************************************************************* string imagePath = "C:/Users/Mihailo/Desktop/OCR/tekst.png"; //path to the image with letters (document) for recognition string textPath = "C:/Users/Mihailo/Desktop/OCR/tekst.txt"; // path to the .txt file where the recognized text will be stored string networkPath = "C:/Users/Mihailo/Desktop/OCR/network.nnet"; // locatoin of the trained network int fontSize = 12; // fontSize, predicted by height of the letters, minimum font size is 12 pt int scanQuality = 300; // scan quality, minimum quality is 300 dpi //******************************************************************************************************************************************* BufferedImage image = ImageIO.read(new File(imagePath)); ImageFilterChain chain = new ImageFilterChain(); chain.addFilter(new GrayscaleFilter()); chain.addFilter(new OtsuBinarizeFilter()); BufferedImage binarizedImage = chain.processImage(image); // Information about letters and text Letter letterInfo = new Letter(scanQuality, binarizedImage); // letterInfo.recognizeDots(); // call this method only if you want to recognize dots and other litle characters, TODO Text textInfo = new Text(binarizedImage, letterInfo); OCRTextRecognition recognition = new OCRTextRecognition(letterInfo, textInfo); recognition.NetworkPath = networkPath; recognition.recognize(); //if you want to save recognized text // recognition.setRecognizedTextPath(textPath); // recognition.saveText(); Console.WriteLine(recognition.RecognizedText); }
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET: //ORIGINAL LINE: public static void main(String[] args) throws java.io.IOException public static void Main(string[] args) { // User input parameteres //******************************************************************************************************************************* string imagePath = "C:/Users/Mihailo/Desktop/OCR/slova.png"; //path to the image with letters * string folderPath = "C:/Users/Mihailo/Desktop/OCR/ImagesDir/"; // loaction folder for storing segmented letters * string textPath = "C:/Users/Mihailo/Desktop/OCR/slova.txt"; // path to the .txt file with text on the image * string networkPath = "C:/Users/Mihailo/Desktop/OCR/network.nnet"; // location where the network will be stored * int fontSize = 12; // fontSize, predicted by height of the letters, minimum font size is 12 pt * int scanQuality = 300; // scan quality, minimum quality is 300 dpi * //******************************************************************************************************************************* BufferedImage image = ImageIO.read(new File(imagePath)); ImageFilterChain chain = new ImageFilterChain(); chain.addFilter(new GrayscaleFilter()); chain.addFilter(new OtsuBinarizeFilter()); BufferedImage binarizedImage = chain.processImage(image); Letter letterInfo = new Letter(scanQuality, binarizedImage); // letterInfo.recognizeDots(); // call this method only if you want to recognize dots and other litle characters, TODO Text texTInfo = new Text(binarizedImage, letterInfo); OCRTraining ocrTraining = new OCRTraining(letterInfo, texTInfo); ocrTraining.FolderPath = folderPath; ocrTraining.TrainingTextPath = textPath; ocrTraining.prepareTrainingSet(); List <string> characterLabels = ocrTraining.CharacterLabels; IDictionary <string, FractionRgbData> map = ImageRecognitionHelper.getFractionRgbDataForDirectory(new File(folderPath), new Dimension(20, 20)); DataSet dataSet = ImageRecognitionHelper.createBlackAndWhiteTrainingSet(characterLabels, map); dataSet.FilePath = "C:/Users/Mihailo/Desktop/OCR/DataSet1.tset"; dataSet.save(); List <int?> hiddenLayers = new List <int?>(); hiddenLayers.Add(12); NeuralNetwork nnet = ImageRecognitionHelper.createNewNeuralNetwork("someNetworkName", new Dimension(20, 20), ColorMode.BLACK_AND_WHITE, characterLabels, hiddenLayers, TransferFunctionType.SIGMOID); BackPropagation bp = (BackPropagation)nnet.LearningRule; bp.LearningRate = 0.3; bp.MaxError = 0.1; // MultiLayerPerceptron mlp = new MultiLayerPerceptron(12,13); // mlp.setOutputNeurons(null); Console.WriteLine("Start learning..."); nnet.learn(dataSet); Console.WriteLine("NNet learned"); nnet.save(networkPath); }