Tesseract_indic_alpha

June 8, 2008 at 6:56 pm (Uncategorized)

Released an alpha version at http://debayanin.googlepages.com/hackingtesseract. It works, but wait a little longer for a far more ready-to-use copy.

Advertisements

1 Comment

  1. RKVS Raman said,

    Hi ,

    Great Code!!

    I took the liberty of attempting matra clipping in Java. Bit clumsy for a days work, but has started to work. Thought you might want to use it sometime. Here it is.

    ———————————————————————

    /*
    * To change this template, choose Tools | Templates
    * and open the template in the editor.
    */

    import java.awt.image.BufferedImage;
    import java.io.File;
    import javax.imageio.ImageIO;
    import net.sourceforge.jiu.codecs.CodecMode;
    import net.sourceforge.jiu.codecs.ImageCodec;
    import net.sourceforge.jiu.codecs.ImageLoader;
    import net.sourceforge.jiu.codecs.PNGCodec;
    import net.sourceforge.jiu.codecs.jpeg.JPEGCodec;
    import net.sourceforge.jiu.color.reduction.RGBToGrayConversion;
    import net.sourceforge.jiu.data.MemoryGray8Image;
    import net.sourceforge.jiu.data.PixelImage;
    import net.sourceforge.jiu.gui.awt.BufferedRGB24Image;
    import org.omg.IOP.Codec;

    /**
    *
    * @author raman
    */
    public class Main {

    /**
    * @param args the command line arguments
    */
    static BlackRow blackrows[];
    static PrintedLine lines[];
    static int no_of_lines;
    public static void main(String[] args) throws Exception {

    if(args.length < 1)
    {
    System.out.println(“Usage: java in.cdacbangalore.ilcg.ocrwork.Main fileName”);
    System.exit(0);

    }

    BufferedImage bImage = ImageIO.read (new File(args[0]));
    BufferedRGB24Image image = new BufferedRGB24Image(bImage);
    RGBToGrayConversion toGrayConversion = new RGBToGrayConversion();
    toGrayConversion.setInputImage(image);
    toGrayConversion.process();
    MemoryGray8Image newImage = (MemoryGray8Image)toGrayConversion.getOutputImage();

    //System.out.println(newImage);

    //PixelImage image = codec.getImage();
    ImageCodec myCodec = new PNGCodec();
    myCodec.setFile(“/home/raman/result.png”, CodecMode.SAVE);
    myCodec.setImage(newImage);
    myCodec.process();

    System.out.println(“X ” + newImage.getWidth() + ” Y ” + newImage.getHeight());
    blackrows = new BlackRow[newImage.getHeight()];

    /* One Approach for(int y = 0 ; y < newImage.getHeight() ; y++)
    {
    int i = 0;
    for(int x =0 ; x 100)
    {
    for(int x =0 ; x < newImage.getWidth() ; x++)
    if(y+2 < newImage.getHeight() && !newImage.isBlack(x, y+1) && !newImage.isBlack(x, y-1))
    newImage.putWhite(x,y);
    if(y+1 < newImage.getHeight())
    for(int x =0 ; x < newImage.getWidth() ; x++)
    if(y+2 < newImage.getHeight() && !newImage.isBlack(x, y+2) && !newImage.isBlack(x, y))
    newImage.putWhite(x,y+1);

    i = 0;

    for(int x =0 ; x < newImage.getWidth() ; x++)
    {
    if(newImage.isBlack(x,y))
    i++;
    }

    }
    System.out.println(i);
    }*/

    /* Second Approach */

    for(int y = 0 ; y < newImage.getHeight() ; y++)
    blackrows[y] = new BlackRow(newImage, y);

    lines = new PrintedLine[15];
    int i = 0;
    no_of_lines = -1;

    while(i 4) || no_of_lines == -1)
    {
    System.out.println(“K is ” +k + ” ” + (k-i));
    no_of_lines++;
    lines[no_of_lines] = new PrintedLine(newImage);
    lines[no_of_lines].addLine(blackrows[k], k);
    i = k+1;
    continue;
    }
    if(k == -1)
    break;
    lines[no_of_lines].addLine(blackrows[i],i);
    i++;

    }

    for(i = 0 ; i <= no_of_lines; i++)
    {
    System.out.println(“Printing line number ” + (i+1));
    //lines[i].print();
    lines[i].printNoOfStems();
    //lines[i].printNoOfStems();
    // lines[i].printNoOfStems();

    }

    MemoryGray8Image myImage = new MemoryGray8Image(newImage.getWidth(), newImage.getHeight());
    for(i = 0 ; i < newImage.getHeight();i++)
    {
    for(int j = 0 ; j < newImage.getWidth() ; j++)
    {
    if(blackrows[i].isBlack[j])
    myImage.putBlack(j, i);
    else
    myImage.putWhite(j, i);

    }

    }

    //ImageCodec myCodec = new PNGCodec();
    myCodec.setFile(“/home/raman/result1.png”, CodecMode.SAVE);
    myCodec.setImage(newImage);
    myCodec.process();

    // TODO code application logic here
    }

    public static int findnextBlackRow(int rowNum,MemoryGray8Image image)
    {
    for(int i = rowNum ; i 0)
    return i;
    return -1;
    }

    public static int getBlackCount(MemoryGray8Image image, int row)
    {
    int count = 0;
    for(int i = 0 ; i < image.getWidth() ;i++)
    if(image.isBlack(i, row))
    count++;
    return count;

    }

    }

    —————————–

    /*
    * To change this template, choose Tools | Templates
    * and open the template in the editor.
    */

    import net.sourceforge.jiu.data.MemoryGray8Image;

    /**
    *
    * @author raman
    */
    public class BlackRow {

    boolean isBlack[];
    int width;
    int no_of_blacks;
    int rowNum;

    public BlackRow(MemoryGray8Image image, int row)
    {
    width = image.getWidth();
    isBlack = new boolean[width];
    no_of_blacks = 0;
    rowNum = row;
    for(int i = 0 ; i < width ; i++)
    {
    if(image.isBlack(i, rowNum))
    {
    isBlack[i] = true;
    no_of_blacks++;
    }
    else
    isBlack[i] = false;

    }

    }

    }

    ———————————

    /*
    * To change this template, choose Tools | Templates
    * and open the template in the editor.
    */

    import net.sourceforge.jiu.data.MemoryGray8Image;

    /**
    *
    * @author raman
    */
    public class PrintedLine {

    //int rowNum;
    MemoryGray8Image image;
    BlackRow rows[];
    int rownums[];
    int no_of_rows;

    public PrintedLine(MemoryGray8Image im)
    {
    image = im;

    rows = new BlackRow[80];
    rownums = new int[80];
    no_of_rows = -1;

    }

    public void addLine(BlackRow br, int row_no)
    {
    no_of_rows++;
    rows[no_of_rows] = br;
    rownums[no_of_rows] = row_no;
    }

    public void print()
    {
    for(int i = 0 ; i <= no_of_rows; i++)
    System.out.println(rows[i].no_of_blacks);
    }

    public int calculateMaxCount()
    {
    int max = 0;
    int r = -1;
    for(int i =0 ; i max)
    {
    max = Main.getBlackCount(image, rownums[i]);
    r = i;
    }

    return r;

    }
    public void printNoOfStems()
    {
    int row = calculateMaxCount();
    int w =image.getWidth();
    System.out.println(“Width ” + w + ” Height ” + no_of_rows);

    //int totalStems = 0;
    for(int i =0; i < w; i++)
    {
    if(!image.isBlack(i, rownums[row+1] ) && !image.isBlack(i, rownums[row-1]))
    {
    image.putWhite(i, rownums[row]);
    image.putWhite(i, rownums[row-1]);
    //image.putWhite(i, rownums[row+2]);
    }

    }

    /* for(int i = 0; i <w ; i++)
    {
    int count = 0;
    for(int j = 0 ; j 0 && count < 2)
    {
    //for( int j =0 ; j <= no_of_rows ; j++ )
    image.putWhite(i, row);
    image.putWhite(i, row+1);
    //image.putWhite(i+1, row);
    //image.putWhite(i-1, row);
    //image.putWhite(i+1, row+1);
    //image.putWhite(i-1, row+1);
    totalStems++;
    }
    }
    System.out.println(“Total Stems = ” +totalStems);*/

    }

    }
    ———————-

    Cheers
    -Raman

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: