Hello there, I've come across to perform some orientation based task on my input image/pdf. I found source code in flexicapture sdk "Image processing" and the procedure of different image processing operation. I'm trying to perform orientation based operation, below is my source code to perform task.

public void preprocessDocumentForImageProcessing ( IEngine engine,List<String> filePaths)
{
    try {
        //load image processing tools 
        IImageProcessingTools imageProcessor = engine.CreateImageProcessingTools() ; 
        try {

            IImageFile imageFile = null ;

            //iterate through all files and open them and process them
            for (String filePath : filePaths) {

                // Open an image file using the OpenImageFile for image
                // processing
                imageFile = imageProcessor.OpenImageFile(filePath);

                int totalPageCountInaImageDocument = imageFile
                        .getPagesCount();

                //image page object for each page in a image file
                IImage _page = null ; 
                ILanguage language = engine.getPredefinedLanguages().FindLanguage("English");

                for (int iteratorForPageInImageFile = 0; iteratorForPageInImageFile < totalPageCountInaImageDocument; iteratorForPageInImageFile++) {
                    //open page of a image file
                    _page = imageFile.OpenImagePage(iteratorForPageInImageFile);

                    //perform image processing operations

                    /* Orientation detection and correction Start */
                    // get rotation type
                    RotationTypeEnum rotationTypeEnum = imageProcessor
                            .DetectOrientationByText(_page, language);

                    // rotate image according to rotation type
                    _page = imageProcessor.RotateImageByRotationType(_page,rotationTypeEnum);

                ***********I got stuck at here***************************** 
                    /* Orientation detection and correction Start */

                }

                // Open a page of the image file using the OpenImagePage of
                // the ImageFile object

            }

        }finally {
            imageProcessor.Release();
            logger.info("Image processor released");
        }

    }catch (Throwable e){
        logger.error("Exception occured in loading image processing tools and performing operation ",e);
    }

}

in the above source code, i got some confusion at the line "**I got stuck at here****" when i applied RotateImageByRotationType method, this method return me a page which is the result page denoted by "_page" in above code Queries : 1. does after performing RotateImageByRotationType method, the original page in imagefile gets change or stayed same as before?
2. if its stay same then How do i update my original page in Imagefile with result page?

Pls reply fast !!!

asked 01 May '14, 14:23

nits's gravatar image

nits
115


When you call ImageProcessingTools::DetectOrientationByText method you get current page rotation as a result. After it you can rotate the image using ImageProcessingTools:: RotateImageByRotationType method. It’s necessary to specify needed rotation correctly. For example, if the result of ImageProcessingTools::DetectOrientationByText is RotationTypeEnum. RT_Clockwise then you should pass RotationTypeEnum.RT_Counterclockwise as a rotation type parameter to ImageProcessingTools:: RotateImageByRotationType method.

C# code might look like the following:

// get rotation type
RotationTypeEnum rotationTypeEnum = imageProcessor.DetectOrientationByText(_page, language);

// rotate image according to rotation type
if (rotationTypeEnum == RotationTypeEnum.RT_Clockwise)
{
  _page = imageProcessor.RotateImageByRotationType(_page,RotationTypeEnum.RT_Counterclockwise);
} else
if (rotationTypeEnum == RotationTypeEnum.RT_Counterclockwise)
{
  _page = imageProcessor.RotateImageByRotationType(_page,RotationTypeEnum.RT_Clockwise);
} else
if (rotationTypeEnum == RotationTypeEnum.RT_Upsidedown)
{
  _page = imageProcessor.RotateImageByRotationType(_page,RotationTypeEnum.RT_Upsidedown);
}

If you want to save the rotated image, you could use Image::WriteToFile method.

link

answered 06 May '14, 12:29

SDK_support's gravatar image

SDK_support ♦♦
2763

Dear, Thank you for you recommendation. As par as above solution, it seems it does not rotate original image rather it give u rotated one as _page in above code, OK. But as par as your tutorial's say's, we can use the resultant image further with flexicapture processor.

for example, [as par as tutorial] Preprocess the image using methods of the ImageProcessingTools object. **i perform rotation of page in image of pdf, i got result as _page of a image of a pdf: Repeat for every page of image of pdf. Then how i ensure that i have the result pdf to load in flexicapture as step 2

Create an instance of FlexiCapture processor using the CreateFlexiCaptureProcessor method of the Engine object. . How i perform the step 2 ? Since i got a _page of image of pdf, how i use it further ?

Please share code snippet.

link

answered 06 May '14, 13:14

nits's gravatar image

nits
115

Thank you team, I got the way to perform my required task. i would like to make you in notice that, the above code written by you :

// get rotation type
               RotationTypeEnum rotationTypeEnum = imageProcessor.DetectOrientationByText(_page, language);

// rotate image according to rotation type
if (rotationTypeEnum == RotationTypeEnum.RT_Clockwise)
{
                                _page = imageProcessor.RotateImageByRotationType(_page,RotationTypeEnum.RT_Counterclockwise);
} else
if (rotationTypeEnum == RotationTypeEnum.RT_Counterclockwise)
{
                               _page = imageProcessor.RotateImageByRotationType(_page,RotationTypeEnum.RT_Clockwise);
} else
if (rotationTypeEnum == RotationTypeEnum.RT_Upsidedown)
{
                               _page = imageProcessor.RotateImageByRotationType(_page,RotationTypeEnum.RT_Upsidedown);
}

Having some issues, i have a pdf which is rotated clockwise, when i get RotationTypeEnum rotationTypeEnum the value i got is counterclockwise instead clockwise ( don't know why? i would like to know) and vice versa

so i've just changed the code like below

// get rotation type
               RotationTypeEnum rotationTypeEnum = imageProcessor.DetectOrientationByText(_page, language);

// rotate image according to rotation type
if (rotationTypeEnum == RotationTypeEnum.RT_Clockwise)
{
                                _page = imageProcessor.RotateImageByRotationType(_page,RotationTypeEnum.RT_Clockwise);
} else
if (rotationTypeEnum == RotationTypeEnum.RT_Counterclockwise)
{
                               _page = imageProcessor.RotateImageByRotationType(_page,RotationTypeEnum.RT_Counterclockwise);
} else
if (rotationTypeEnum == RotationTypeEnum.RT_Upsidedown)
{
                               _page = imageProcessor.RotateImageByRotationType(_page,RotationTypeEnum.RT_Upsidedown);
}

As par as my understanding, rotationTypeEnum gives you what rotation u need to perform in order to fix the image rather the opposite one. Thank you for your suggestions

link

answered 06 May '14, 17:05

nits's gravatar image

nits
115

edited 06 May '14, 17:06

Your answer
toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported

Tags:

×20

Asked: 01 May '14, 14:23

Seen: 2,050 times

Last updated: 06 May '14, 17:06

© 2016 ABBYY. All rights Reserved. www.ABBYY.com | Privacy Policy | Legal