0

i have a project to find a text embedded image angle of rotation and i am using Tess4j so how can i get correct orientation angle of image is there any option in Tess4j that can rotate an image in correct orientation...

if i give an image as an input so output should be the correct oriented image...first image is as input and 2n one is out put so how can i do it .... plzz help me input image desire output image

rj27
  • 89
  • 1
  • 9

4 Answers4

1

Tess4J supports both determining the skew angle of an image and rotating it. Check out its API documentation page for more info.

nguyenq
  • 8,212
  • 1
  • 16
  • 16
1

for image orientation and page segmantation

public class TestOrientation {
    public static void D() throws Exception {

        TessAPI api=LoadLibs.getTessAPIInstance();
        TessBaseAPI handle=TessAPI1.TessBaseAPICreate();

        File tiff = new File("C:/Users/atul/Desktop/test1.tif");
        String datapath = "C:/Tesseract/tessdata";
        String language = "eng";
        int expResult = TessPageSegMode.PSM_AUTO_OSD;
        IntBuffer orientation = IntBuffer.allocate(1);
        IntBuffer direction = IntBuffer.allocate(1);
        IntBuffer order = IntBuffer.allocate(1);
        FloatBuffer deskew_angle = FloatBuffer.allocate(1);

        BufferedImage image = ImageIO.read(new FileInputStream(tiff)); // require jai-imageio lib to read TIFF
        ByteBuffer buf = ImageIOHelper.convertImageData(image);
        int bpp = image.getColorModel().getPixelSize();
        int bytespp = bpp / 8;
        int bytespl = (int) Math.ceil(image.getWidth() * bpp / 8.0);
        api.TessBaseAPIInit3(handle, datapath, language);
        api.TessBaseAPISetPageSegMode(handle, TessPageSegMode.PSM_AUTO_OSD);
        int actualResult = api.TessBaseAPIGetPageSegMode(handle);

        api.TessBaseAPISetImage(handle, buf, image.getWidth(), image.getHeight(), bytespp, bytespl);
        int success = api.TessBaseAPIRecognize(handle, null);
        if (success == 0) {
            TessPageIterator pi = api.TessBaseAPIAnalyseLayout(handle);
            api.TessPageIteratorOrientation(pi, orientation, direction, order, deskew_angle);
            System.out.println("Orientation:" + orientation.get()+
                "\nWritingDirection:"+Utils.getConstantName(direction.get(), TessWritingDirection.class)+
                " \nTextlineOrder:" + Utils.getConstantName(order.get(), TessTextlineOrder.class)+
                "\nDeskew angle: %.4f\n"+deskew_angle.get());
        }
    }

    public static void main(String[] args) {
        try {
            D();
        } catch (Exception e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }
}
nemoinho
  • 604
  • 4
  • 15
rj27
  • 89
  • 1
  • 9
1
BufferedImage image = ImageIO.read(new File("C:\\myimg-tilt.jpg"));
ImageDeskew id = new ImageDeskew(image);
image = ImageHelper.rotateImage(image, -id.getSkewAngle());
  • Hi and welcome to stackoverflow, and thank you for answering. While this code might answer the question, can you consider adding some explanation for what the problem was you solved, and how you solved it? This will help future readers to understand your answer better and learn from it. – Plutian Feb 10 '20 at 08:06
0

You can use OpenCV for this operation. Firstly you need to calculate skew angle of image. Then, you can rotate your image with angle that you've found.

You can check out this link. It's really helpful. But you need to implement it to Java.

http://felix.abecassis.me/2011/09/opencv-detect-skew-angle/

bodoroman
  • 278
  • 2
  • 16