//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); }
// creates hsl map from given image files - params should be files List<File> - or even better image files //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET: //ORIGINAL LINE: public static java.util.Map<String, FractionHSLData> getFractionHSLDataForDirectory(java.io.File imgDir, org.neuroph.imgrec.image.Dimension samplingResolution) throws java.io.IOException public static IDictionary <string, FractionHSLData> getFractionHSLDataForDirectory(File imgDir, Dimension samplingResolution) { if (!imgDir.Directory) { throw new System.ArgumentException("The given file must be a directory. Argument is: " + imgDir); } IDictionary <string, FractionHSLData> map = new Dictionary <string, FractionHSLData>(); ImageFilesIterator imagesIterator = new ImageFilesIterator(imgDir); try { while (imagesIterator.hasNext()) { File imgFile = imagesIterator.next(); BufferedImage img = ImageIO.read(imgFile); BufferedImage image = ImageUtilities.resizeImage(img, samplingResolution.Width, samplingResolution.Height); string filenameOfCurrentImage = imgFile.Name; //String filenameOfCurrentImage = imagesIterator.getFilenameOfCurrentImage(); StringTokenizer st = new StringTokenizer(filenameOfCurrentImage, "."); map[st.nextToken()] = new FractionHSLData(image); } } catch (Exception e) { Console.WriteLine(e.ToString()); Console.Write(e.StackTrace); } return(map); }
public Picture(string str) { this.isOriginUpperLeft = true; this.filename = str; try { File file = new File(str); if (file.isFile()) { this.image = ImageIO.read(file); } else { URL uRL = java.lang.Object.instancehelper_getClass(this).getResource(str); if (uRL == null) { uRL = new URL(str); } this.image = ImageIO.read(uRL); } this.width = this.image.getWidth(null); this.height = this.image.getHeight(null); } catch (IOException arg_7E_0) { goto IL_82; } return; IL_82: string arg_A7_0 = new StringBuilder().append("Could not open file: ").append(str).toString(); throw new RuntimeException(arg_A7_0); }
private void loadImageOfUser(string paramString) { string str = DatabaseDBUtil.Properties.ConnectionHost; if (this.imgcIcon == null && !string.ReferenceEquals(str, null)) { if (DatabaseDBUtil.Enterprise) { if (!str.StartsWith("http://", StringComparison.Ordinal) && !str.StartsWith("https://", StringComparison.Ordinal)) { str = "http://" + str; } string str1 = str + "/ces/pictures/showAvatar?userId=" + DatabaseDBUtil.Properties.UserId; try { BufferedImage bufferedImage1 = ImageIO.read((new URL(str1)).openStream()); BufferedImage bufferedImage2 = ImageUtils.resizeImage(bufferedImage1, 1, 12, 12); this.imgcIcon = new ImageIcon(bufferedImage2); } catch (Exception) { this.imgcIcon = new ImageIcon(); } } else { this.imgcIcon = new ImageIcon(); } } if (this.imgcIcon != null) { ((JideButton)this.o_trailingButton).Icon = this.imgcIcon; } }
public Picture(File f) { this.isOriginUpperLeft = true; IOException ex; try { this.image = ImageIO.read(f); } catch (IOException arg_20_0) { ex = ByteCodeHelper.MapException <IOException>(arg_20_0, ByteCodeHelper.MapFlags.NoRemapping); goto IL_2A; } if (this.image == null) { string arg_82_0 = new StringBuilder().append("Invalid image file: ").append(f).toString(); throw new RuntimeException(arg_82_0); } this.width = this.image.getWidth(null); this.height = this.image.getHeight(null); this.filename = f.getName(); return; IL_2A: IOException this2 = ex; Throwable.instancehelper_printStackTrace(this2); string arg_55_0 = new StringBuilder().append("Could not open file: ").append(f).toString(); throw new RuntimeException(arg_55_0); }
public JXMapViewer() { if (!InstanceFieldsInitialized) { InitializeInstanceFields(); InstanceFieldsInitialized = true; } PanMouseInputListener panMouseInputListener = new PanMouseInputListener(this, null); RecenterOnClickEnabled = false; addMouseListener(panMouseInputListener); addMouseMotionListener(panMouseInputListener); addMouseWheelListener(new ZoomMouseWheelListener(this, null)); addKeyListener(new PanKeyListener(this, null)); try { URL uRL = this.GetType().getResource("mapviewer/resources/loading.png"); LoadingImage = ImageIO.read(uRL); } catch (Exception) { Console.WriteLine("could not load 'loading.png'"); BufferedImage bufferedImage = new BufferedImage(16, 16, 2); Graphics2D graphics2D = bufferedImage.createGraphics(); graphics2D.Color = Color.black; graphics2D.fillRect(0, 0, 16, 16); graphics2D.dispose(); LoadingImage = bufferedImage; } BackgroundPainter = new AbstractPainterAnonymousInnerClass(this); }
private bool parseImage() { _image = ImageIO.read(_is); _width = _image.getWidth(); _height = _image.getHeight(); TempStream ts = new TempStream(); WriteStream os = new WriteStream(ts); try { ImageIO.write(_image, "jpeg", os); } finally { os.close(); } /* * os = Vfs.openWrite("file:/tmp/caucho/qa/test.jpg"); * try { * ImageIO.write(_image, "jpeg", os); * } finally { * os.close(); * } * * os = Vfs.openWrite("file:/tmp/caucho/qa/test.png"); * try { * ImageIO.write(_image, "png", os); * } finally { * os.close(); * } */ return(parseImageJpeg(ts.openRead())); }
public BufferedImage composeImageForSector(Sector sector, int canvasWidth, int canvasHeight, double aspectRatio, int levelNumber, String mimeType, bool abortOnError, BufferedImage image, int timeout) { if (sector == null) { String message = Logging.getMessage("nullValue.SectorIsNull"); Logging.logger().severe(message); throw new ArgumentException(message); } Level requestedLevel; if ((levelNumber >= 0) && (levelNumber < this.getLevels().getNumLevels())) { requestedLevel = this.getLevels().getLevel(levelNumber); } else { requestedLevel = this.getLevels().getLastLevel(); } ComposeImageTile tile = new ComposeImageTile(sector, mimeType, requestedLevel, canvasWidth, canvasHeight); try { if (image == null) { image = new BufferedImage(canvasWidth, canvasHeight, BufferedImage.TYPE_INT_RGB); } downloadImage(tile, mimeType, timeout); Thread.sleep(1); // generates ThreadInterruptedException if thread has been interupted BufferedImage tileImage = ImageIO.read(tile.getFile()); Thread.sleep(1); // generates ThreadInterruptedException if thread has been interupted ImageUtil.mergeImage(sector, tile.getSector(), aspectRatio, tileImage, image); Thread.sleep(1); // generates ThreadInterruptedException if thread has been interupted this.firePropertyChange(AVKey.PROGRESS, 0d, 1d); } catch (InterruptedIOException e) { throw e; } catch (Exception e) { if (abortOnError) { throw e; } String message = Logging.getMessage("generic.ExceptionWhileRequestingImage", tile.getPath()); Logging.logger().log(java.util.logging.Level.WARNING, message, e); } return(image); }
public QuercusImage(Env env, string filename) { try { _bufferedImage = ImageIO.read(filename.openRead()); _graphics = (Graphics2D)_bufferedImage.getGraphics(); } catch (IOException e) { throw new QuercusException(e); } }
public QuercusImage(InputStream inputStream) { try { _bufferedImage = ImageIO.read(inputStream); _graphics = (Graphics2D)_bufferedImage.getGraphics(); } catch (IOException e) { throw new QuercusException(e); } }
/// <summary> /// Loads image from the file. /// </summary> /// <param name="file"> image file </param> /// <returns> loaded image </returns> public static BufferedImage loadImage(File file) { try { return(ImageIO.read(file)); } catch (IOException ex) { throw new Exception("IOException whle trying to load image file" + file.Name, ex); } }
public void SetIcon(File icon) { try { this.image = ImageIO.read(icon); iconChanged = true; // logger.info("set icon from file: " + _icon.getWidth()); } catch (IOException ex) { logger.catching(ex); } }
/// <summary> /// This method loads the input Image and returns the cleaned version /// </summary> /// <param name="file"> - input file that will be loaded as image </param> /// <returns> - return cleaned loaded image as BufferedImage </returns> public static BufferedImage loadAndCleanImage(File file) { try { BufferedImage image = ImageIO.read(file); return(blackAndLightGrayCleaning(image)); } catch (IOException ex) { //JAVA TO C# CONVERTER WARNING: The .NET Type.FullName property will not always yield results identical to the Java Class.getName method: Logger.getLogger(typeof(ImageUtilities).FullName).log(Level.SEVERE, null, ex); return(null); } }
protected internal virtual bool compareScreenshots(File expected, File result, File compare) { bool equals = false; try { System.Drawing.Bitmap expectedImg = ImageIO.read(expected); System.Drawing.Bitmap resultImg; try { resultImg = ImageIO.read(result); } catch (Exception) { // java.lang.RuntimeException: New BMP version not implemented yet. resultImg = readBmp(result); } int width = System.Math.Min(expectedImg.Width, resultImg.Width); int height = System.Math.Min(expectedImg.Height, resultImg.Height); System.Drawing.Bitmap compareImg = new System.Drawing.Bitmap(width, height, System.Drawing.Bitmap.TYPE_INT_RGB); equals = true; for (int y = 0; y < height; y++) { for (int x = 0; x < width; x++) { int expectedColor = expectedImg.getRGB(x, y); int resultColor = resultImg.getRGB(x, y); if (areColorsEqual(expectedColor, resultColor)) { compareImg.setRGB(x, y, 0x000000); } else { compareImg.setRGB(x, y, 0xFF0000); equals = false; } } } ImageIO.write(compareImg, "bmp", compare); } catch (IOException e) { error(string.Format("comparing screenshots {0}", e)); } return(equals); }
protected internal virtual DiagramNode getDiagramBoundsFromImage(Stream imageStream, int offsetTop, int offsetBottom) { BufferedImage image; try { image = ImageIO.read(imageStream); } catch (IOException e) { throw new ProcessEngineException("Error while reading process diagram image.", e); } DiagramNode diagramBoundsImage = getDiagramBoundsFromImage(image, offsetTop, offsetBottom); return(diagramBoundsImage); }
public static string uploadLocalImage(string paramString, Type paramClass, long?paramLong) { File file1 = new File("data/images/" + paramClass.Name.ToLower()); if (!file1.exists()) { file1.mkdirs(); } File file2 = new File(paramString); string str1 = file2.Name.substring(0, file2.Name.LastIndexOf(".")); string str2 = getLocalPathOfImage(str1, paramClass, paramLong); File file3 = new File(str2); ImageUtils.saveImage(ImageIO.read(file2), file3.AbsolutePath, 1); return(str1); }
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: //ORIGINAL LINE: public static java.awt.image.BufferedImage resizeImage(String paramString, int paramInt1, int paramInt2) throws java.io.IOException public static BufferedImage resizeImage(string paramString, int paramInt1, int paramInt2) { BufferedImage bufferedImage = null; if (paramString.ToLower().EndsWith(".png", StringComparison.Ordinal)) { bufferedImage = resizeImage(ImageIO.read(new File(paramString)), 1, paramInt1, paramInt2); } else if (paramString.ToLower().EndsWith(".gif", StringComparison.Ordinal)) { bufferedImage = resizeImage(ImageIO.read(new File(paramString)), 3, paramInt1, paramInt2); } else { bufferedImage = resizeImage(ImageIO.read(new File(paramString)), 0, paramInt1, paramInt2); } return(bufferedImage); }
public Benchmark(int resolution, bool showOutput, bool showBenchmarkOutput, bool saveOutput, int threads) { UI.set(this); this.resolution = resolution; this.showOutput = showOutput; this.showBenchmarkOutput = showBenchmarkOutput; this.saveOutput = saveOutput; this.threads = threads; errorThreshold = 6; // fetch reference image from resources (jar file or classpath) if (saveOutput) { return; } URL imageURL = getResource(string.Format("/resources/golden_{0}.png", resolution));//fixme: add padding zeros if (imageURL == null) { UI.printError(UI.Module.BENCH, "Unable to find reference frame!"); } UI.printInfo(UI.Module.BENCH, "Loading reference image from: {0}", imageURL); try { BufferedImage bi = ImageIO.read(imageURL); if (bi.getWidth() != resolution || bi.getHeight() != resolution) { UI.printError(UI.Module.BENCH, "Reference image has invalid resolution! Expected {0}x{1} found {2}x{3}", resolution, resolution, bi.getWidth(), bi.getHeight()); } referenceImage = new int[resolution * resolution]; for (int y = 0, i = 0; y < resolution; y++) { for (int x = 0; x < resolution; x++, i++) { referenceImage[i] = bi.getRGB(x, resolution - 1 - y); // flip } } } catch (Exception e) { UI.printError(UI.Module.BENCH, "Unable to load reference frame!"); } }
/// /// <summary> /// Inverts the image colors from negative to positive /// </summary> /// <returns> the image with inverted colors </returns> public static BufferedImage invertImage(string imageName) { // read the image file BufferedImage inputFile = null; try { inputFile = ImageIO.read(new File(imageName)); } catch (IOException e) { Console.WriteLine(e.ToString()); Console.Write(e.StackTrace); } // go through image pixels and reverse their color for (int x = 0; x < inputFile.Width; x++) { for (int y = 0; y < inputFile.Height; y++) { int rgba = inputFile.getRGB(x, y); Color col = new Color(rgba, true); col = new Color(255 - col.Red, 255 - col.Green, 255 - col.Blue); inputFile.setRGB(x, y, col.RGB); } } //write the image to a file blackandwhite.png try { File outputFile = new File("blackandwhite.png"); ImageIO.write(inputFile, "png", outputFile); } catch (IOException e) { Console.WriteLine(e.ToString()); Console.Write(e.StackTrace); } return(inputFile); }
private System.Drawing.Bitmap readImage(int offset, int Length) { int currentPosition = tell(); seek(pImgData + offset); sbyte[] buffer = readBytes(Length); seek(currentPosition); System.IO.Stream imageInputStream = new System.IO.MemoryStream(buffer); System.Drawing.Bitmap System.Drawing.Bitmap = null; try { System.Drawing.Bitmap = ImageIO.read(imageInputStream); imageInputStream.Close(); // Add an alpha color channel if not available if (!System.Drawing.Bitmap.ColorModel.hasAlpha()) { System.Drawing.Bitmap System.Drawing.BitmapWithAlpha = new System.Drawing.Bitmap(System.Drawing.Bitmap.Width, System.Drawing.Bitmap.Height, System.Drawing.Bitmap.TYPE_INT_ARGB); Graphics2D g = System.Drawing.BitmapWithAlpha.createGraphics(); g.drawImage(System.Drawing.Bitmap, 0, 0, null); g.dispose(); System.Drawing.Bitmap = System.Drawing.BitmapWithAlpha; } if (dumpImages) { ImageIO.write(System.Drawing.Bitmap, "png", new File(string.Format("tmp/Image0x{0:X}.png", offset))); } } catch (IOException e) { Console.WriteLine(string.Format("Error reading image from RCO at 0x{0:X}, Length=0x{1:X}", offset, Length), e); } return(System.Drawing.Bitmap); }
public virtual void run() { try { // load image with text to recognize if (image == null) { image = ImageIO.read(new File(textImageFile)); } //binarize the input image image = BinaryOps.binary(textImageFile); //dataset creation /// <summary> /// CharacterExtractor ce1 = new CharacterExtractor(); File /// inputImage1 = new File(datasetImageFile); File outputDirectory1 = /// new File (datasetOutputFile); ce1.slice(inputImage1, /// outputDirectory1, 60, 60); /// </summary> // crop the white rectange from the image File cropFile = crop(image); // extract individual characters from text image CharacterExtractor ce = new CharacterExtractor(); //make the output file File outputDirectory = new File(charOutputFile); //slice the cropped file to individual character with the width and height of 60px ce.slice(cropFile, outputDirectory, 60, 60); //make a list of character images and add the images form char files List <BufferedImage> lista = new List <BufferedImage>(); for (int i = 0; i <= 7; i++) { File f = new File("data/char_" + i + ".png"); BufferedImage bi = ImageIO.read(f); lista.Add(bi); } // load neural network from file if (nnet == null) { NeuralNetwork nnet = NeuralNetwork.createFromFile(neuralNetworkFile); } // get ocr plugin from neural network nnet.addPlugin(new OcrPlugin(new Dimension(10, 10), ColorMode.BLACK_AND_WHITE)); OcrPlugin ocrPlugin = (OcrPlugin)nnet.getPlugin(typeof(OcrPlugin)); // and recognize current character - ( have to use ImageJ2SE here to wrap BufferedImage) for (int i = 0; i < lista.Count; i++) { recognizedCharacters += ocrPlugin.recognizeCharacter(new ImageJ2SE(lista[i])) + " "; Console.Write(ocrPlugin.recognizeCharacter(new ImageJ2SE(lista[i])) + " "); } recognizedCharacters.Trim(); } catch (IOException e) { //Let us know what happened Console.WriteLine("Error reading dir: " + e.Message); } }
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET: //ORIGINAL LINE: private ImageJ2SE(java.io.File imageFile) throws java.io.IOException private ImageJ2SE(File imageFile) { bufferedImage = ImageIO.read(imageFile); }
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: //ORIGINAL LINE: public static java.awt.image.BufferedImage resizeImage(String paramString, int paramInt1, int paramInt2, int paramInt3) throws java.io.IOException public static BufferedImage resizeImage(string paramString, int paramInt1, int paramInt2, int paramInt3) { return(resizeImage(ImageIO.read(new File(paramString)), paramInt1, paramInt2, paramInt3)); }
public static string makeGraphicHTML(string paramString1, string paramString2) { string str = "http://www.costdatabase.eu/rsmeans/as/graphics/" + paramString1 + ".PNG"; int i = 0; int j = 0; char c1 = 'Ȯ'; char c2 = 'Ǵ'; char c3 = (char)(c1 / '\x0002' - '2'); try { BufferedImage bufferedImage = ImageIO.read(new URL(str)); Dimension dimension = new Dimension(c1, c2); i = bufferedImage.getWidth(null); j = bufferedImage.getHeight(null); float f = i / j; if ((char)i > c1 || (char)j > c2) { if (dimension.width / dimension.height > f) { dimension.width = (int)Math.Ceiling((dimension.height * f)); } else { dimension.height = (int)Math.Ceiling((dimension.width / f)); } i = dimension.width; j = dimension.height; } } catch (Exception) { i = 0; j = 0; } StringBuilder stringBuffer = new StringBuilder(); if (i == 0 || (char)i > c3) { stringBuffer.Append("<html>"); if (i != 0) { stringBuffer.Append("<div>"); stringBuffer.Append("<a href=\"http://www.costdatabase.eu/rsmeans/as/graphics/" + paramString1 + ".PDF\"><img src=\"" + str + "\" width=\"" + i + "\" height=\"" + j + "\" border=\"0\"></a>"); stringBuffer.Append("</div>"); } if (!StringUtils.isNullOrBlank(paramString2)) { stringBuffer.Append("<div width=\"400px\">"); stringBuffer.Append("<font color=\"black\" face=\"Arial\" size=\"2\">"); stringBuffer.Append("<br/>"); stringBuffer.Append(paramString2); stringBuffer.Append("</font>"); stringBuffer.Append("</div>"); } stringBuffer.Append("</html>"); } else { stringBuffer.Append("<html>"); stringBuffer.Append("<table border=0 width=\"558\">"); stringBuffer.Append("<tr><td>"); stringBuffer.Append("<a href=\"http://www.costdatabase.eu/rsmeans/as/graphics/" + paramString1 + ".PDF\"><img src=\"" + str + "\" width=\"" + i + "\" height=\"" + j + "\" border=\"0\"></a>"); stringBuffer.Append("</td><td valign=\"top\">"); stringBuffer.Append("<font face=\"Arial\" size=\"2\">"); stringBuffer.Append(paramString2); stringBuffer.Append("</font></td></tr></table>"); stringBuffer.Append("</html>"); } return(stringBuffer.ToString()); }
public virtual void actionPerformed(System.Object event_sender, System.EventArgs event_Renamed) { if (event_sender.Equals(openMenu)) { chooser.ShowDialog(this); if (new System.IO.FileInfo(chooser.FileName) == null) { return; } try { sourceImage = ImageIO.read(new System.IO.FileInfo(chooser.FileName)); } catch (System.Exception e) { SupportClass.WriteStackTrace(e, Console.Error); } } else if (SupportClass.CommandManager.GetCommand(event_sender).Equals("Open from URL")) { try { //UPGRADE_TODO: Class 'java.net.URL' was converted to a 'System.Uri' which does not throw an exception if a URL specifies an unknown protocol. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1132'" sourceImage = ImageIO.read(new System.Uri(url.Text)); } catch (System.Exception e) { SupportClass.WriteStackTrace(e, Console.Error); } } else { return; } if (sourceImageLabel != null) { //UPGRADE_TODO: Method 'javax.swing.JFrame.getContentPane' was converted to 'System.Windows.Forms.Form' which has a different behavior. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1073_javaxswingJFramegetContentPane'" ((System.Windows.Forms.ContainerControl) this).Controls.Remove(sourceImageLabel); } System.Windows.Forms.Label temp_label; temp_label = new System.Windows.Forms.Label(); temp_label.Image = (System.Drawing.Image)sourceImage.Clone(); sourceImageLabel = temp_label; //UPGRADE_TODO: Method 'javax.swing.JFrame.getContentPane' was converted to 'System.Windows.Forms.Form' which has a different behavior. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1073_javaxswingJFramegetContentPane'" //UPGRADE_TODO: Method 'java.awt.Container.add' was converted to 'System.Windows.Forms.ContainerControl.Controls.Add' which has a different behavior. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1073_javaawtContaineradd_javaawtComponent_javalangObject'" ((System.Windows.Forms.ContainerControl) this).Controls.Add(sourceImageLabel); sourceImageLabel.Dock = System.Windows.Forms.DockStyle.Left; sourceImageLabel.BringToFront(); QRCodeDecoder decoder = new QRCodeDecoder(); if (canvas != null) { //UPGRADE_TODO: Method 'javax.swing.JFrame.getContentPane' was converted to 'System.Windows.Forms.Form' which has a different behavior. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1073_javaxswingJFramegetContentPane'" ((System.Windows.Forms.ContainerControl) this).Controls.Remove(canvas); //canvas.setImage(null); } canvas = new J2SEDebugCanvas(); QRCodeDecoder.setCanvas(canvas); //UPGRADE_TODO: Method 'javax.swing.JFrame.getContentPane' was converted to 'System.Windows.Forms.Form' which has a different behavior. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1073_javaxswingJFramegetContentPane'" //UPGRADE_TODO: Method 'java.awt.Container.add' was converted to 'System.Windows.Forms.ContainerControl.Controls.Add' which has a different behavior. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1073_javaawtContaineradd_javaawtComponent_javalangObject'" ((System.Windows.Forms.ContainerControl) this).Controls.Add(canvas); canvas.Dock = System.Windows.Forms.DockStyle.Right; canvas.BringToFront(); System.String decodedString = null; try { decodedString = new String(decoder.decode(new J2SEImage(this, sourceImage))); } catch (DecodingFailedException e) { canvas.println(e.getMessage()); canvas.println("--------"); return; } decodedString = ContentConverter.convert(decodedString); canvas.println("\nDecode result:"); canvas.println(decodedString); canvas.println("--------"); if (decodedText != null) { //UPGRADE_TODO: Method 'javax.swing.JFrame.getContentPane' was converted to 'System.Windows.Forms.Form' which has a different behavior. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1073_javaxswingJFramegetContentPane'" ((System.Windows.Forms.ContainerControl) this).Controls.Remove(decodedText); } System.Windows.Forms.TextBox temp_TextBox; temp_TextBox = new System.Windows.Forms.TextBox(); temp_TextBox.Multiline = true; temp_TextBox.WordWrap = false; temp_TextBox.ScrollBars = System.Windows.Forms.ScrollBars.Both; temp_TextBox.Text = decodedString; decodedText = temp_TextBox; decodedText.WordWrap = true; //UPGRADE_ISSUE: Method 'javax.swing.JTextArea.setRows' was not converted. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1000_javaxswingJTextAreasetRows_int'" decodedText.setRows(decodedString.Length / 20 + 1); if (decodedString.Length < 20) { //UPGRADE_ISSUE: Method 'javax.swing.JTextArea.setColumns' was not converted. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1000_javaxswingJTextAreasetColumns_int'" decodedText.setColumns(decodedString.Length); } else { //UPGRADE_ISSUE: Method 'javax.swing.JTextArea.setColumns' was not converted. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1000_javaxswingJTextAreasetColumns_int'" decodedText.setColumns(20); } //decodedText.setSize(sourceImageLabel.getSize().width,100); //UPGRADE_TODO: Method 'javax.swing.JFrame.getContentPane' was converted to 'System.Windows.Forms.Form' which has a different behavior. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1073_javaxswingJFramegetContentPane'" //UPGRADE_TODO: Method 'java.awt.Container.add' was converted to 'System.Windows.Forms.ContainerControl.Controls.Add' which has a different behavior. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1073_javaawtContaineradd_javaawtComponent_javalangObject'" ((System.Windows.Forms.ContainerControl) this).Controls.Add(decodedText); decodedText.Dock = System.Windows.Forms.DockStyle.Bottom; decodedText.SendToBack(); //UPGRADE_ISSUE: Method 'java.awt.Window.pack' was not converted. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1000_javaawtWindowpack'" pack(); }
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET: //ORIGINAL LINE: private ImageJ2SE(String filePath) throws java.io.IOException private ImageJ2SE(string filePath) { bufferedImage = ImageIO.read(new File(filePath)); }
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET: //ORIGINAL LINE: private ImageJ2SE(java.net.URL imageUrl) throws java.io.IOException private ImageJ2SE(URL imageUrl) { bufferedImage = ImageIO.read(imageUrl); }
//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); }