Skip to main content

Wriring Image Into Text File

4 replies [Last post]
Nithya_3157
Offline
Joined: 2013-03-26
Points: 0

Hi.

I am currently doing an OCR. As for that, I will need to require to recognize the input image file into text file. Right now the code below works fine except for the output part.

I left the code with initial output format where it will be written into another image file. But, what I require here is that the output must be in TEXT file. I hope someone can suggest/show me the way to make it work.

Here is the code:

package assignment10;

import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import java.io.*;
import java.util.Arrays;

import javax.imageio.ImageIO;


public class A10Driver {

  /**
   * @param args
   * @throws IOException
   */
  public static void main(String[] args) throws IOException {
    String name = "Translation_Standard_Galactic_Alphabet.png";
    double factor  = 0.3;

    System.out.println(Arrays.toString(args));

//    if(args.length < 1){
//      System.out.println("Usage: java -jar Filename.jpg");
//      System.out.println("Exiting ...");
//      System.exit(0);
//    }
//
//
//    String name = args[0];
//    double factor = Double.parseDouble(args[1]);

    String[] arr = name.split("\\.");
    String format = arr[1];


    BufferedImage image  = ImageIO.read(new File(name));
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    BoundaryFilterOp bOp = new BoundaryFilterOp(factor);
    BufferedImage bImg   = bOp.filter(image, null);
    //    IPUtil.displayMatrix(IPUtil.readImageAsMatrix(image));
    File file = new File("boundaryFilter-"+name);
    ImageIO.write(bImg, format, file);
    baos.flush();
byte[] imageInByte = baos.toByteArray();
baos.close();

  }

}

I am hoping for kind replies. Thanks in advance!

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
daniel147
Offline
Joined: 2013-11-26
Points: 0

This OCR SDK provides users fast and accurate image recognition function, which converts scanned images into searchable text formats, such as PDF, PDF/A, Word and any other document formats. Here is a tutorial for converting scanned image to PDF document.

Abigail111
Offline
Joined: 2013-08-26
Points: 0

Hi,for image matters ,i usually use this Imaging SDK to process images,including require to recognize the input image file into text file.You can have a look.
http://www.rasteredge.com/how-to/csharp-imaging/process-online/

arronlee
Offline
Joined: 2013-05-08
Points: 0

Yes, I agree with dinesh.r .
The output part should be as follows:

//Pass the byte array to the string then write the string into a file
String imgAsTxt = new String(imageInByte);
//write the imgAsTxt into a FileOutputStream

BTW, you can refer to some free trials of professional tools dealing with images using fast and highly accurate Optical Character Recognition (OCR) Plugin technology.

I hope it helps.

Best regards,
Arron

dinesh.r
Offline
Joined: 2013-05-02
Points: 0

Hi,

After converting it to a byte array pass the value to the String then save the string using File Output Stream as below.

//Pass the byte array to the string then write the string into a file
String imgAsTxt = new String(imageInByte);
//write the imgAsTxt into a FileOutputStream

Thanks,
Dinesh.R