We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Is we can extract text from color images? in java(ocr)?

i want to extract text from color images but its not occuring can aspose apis help me to have method to read color images? like this image can be extracted?

Hi Moon,

Thank you for your inquiry and for providing the sample image.

We have investigated the mentioned issue while using the sample image provided by you. We have used the latest version of Aspose.OCR for Java 2.7.0. While testing it was found that the images provided by you has very low DPI value i.e. 72. Please note that the current implementation of the Aspose.OCR APIs perform well with images having resolution of at least 300 DPI and the accuracy rate tends to decrease by decreasing the resolution. Your provided image has resolution of 72 DPI therefore it will not be possible to get 100% accuracy if you wish to scan the complete image. On the other hand, if you intend to get some specific contents from a portion of the image, you can use the custom recognition blocks to get better accuracy.

Please note, the above mentioned solution is useful in scenario when you have documents following the similar structure, that is; the contents to be scanned are always on the same location for each image.

Consider the following code snippet that we used to extract information from image provided by you using custom recognition blocks.

String imagePath = "C:\\omr_files\\b.jpg";
OcrEngine ocrEngine = new OcrEngine();
ocrEngine.setImage(ImageStream.fromFile(imagePath));
ocrEngine.getConfig().setDoSpellingCorrection(true);
ocrEngine.getConfig().setRemoveNonText(true);
ocrEngine.getConfig().addRecognitionBlock(RecognitionBlock.createTextBlock(182, 218, 160, 66));
if (ocrEngine.process())
{
System.out.println(ocrEngine.getText());
}

Following is the Output

A FR n 4ZO

SINDH

Hope the above information helps. In case of any issues, need further clearance please be sure to let us know, we will be glad to assist you.

i used your defined code but using this image but no output came. run successful but no out put just blank out put there.

package ocr2;
//import com.aspose.ocr.OCRConfig;
import com.aspose.ocr.OcrEngine;
import com.aspose.ocr.ImageStream;
import com.aspose.ocr.RecognitionBlock;
/
*
* @author mun
*/
public class Ocr2 {

/
* @param args the command line arguments
*/
public static void main(String[] args) {
// TODO code application logic here
String imagepath=“C:\Users\mun\Desktop\aspose-ocr-2.7.0-java\lib\output.jpg”;
OcrEngine ocrEngine = new OcrEngine();
ocrEngine.setImage(ImageStream.fromFile(imagepath));

ocrEngine.getConfig().setDoSpellingCorrection(true);
ocrEngine.getConfig().setRemoveNonText(true);

ocrEngine.getConfig().addRecognitionBlock(RecognitionBlock.createTextBlock(182, 218, 160, 66));

if (ocrEngine.process())
{
System.out.println(ocrEngine.getText());
}

}
}

and the block u provided …there came runtime error.

Exception in thread “main” class com.aspose.ocr.OcrException: class com.aspose.ocr.OcrException: Error occurred during recognition. —> class com.aspose.ocr.internal.h: Recognition block right edge exceeds image border.
Parameter name: recognition block
com.aspose.ocr.internal.bnl.a(Unknown Source)
com.aspose.ocr.internal.bnl.a(Unknown Source)
com.aspose.ocr.OcrEngine.a(Unknown Source)
com.aspose.ocr.OcrEngine.process(Unknown Source)
ocr3.Ocr3.main(Ocr3.java:53)
— End of inner exception stack trace —
com.aspose.ocr.OcrEngine.a(Unknown Source)
com.aspose.ocr.OcrEngine.process(Unknown Source)
ocr3.Ocr3.main(Ocr3.java:53) —> class com.aspose.ocr.OcrException: Error occurred during recognition. —> class com.aspose.ocr.internal.h: Recognition block right edge exceeds image border.
Parameter name: recognition block
com.aspose.ocr.internal.bnl.a(Unknown Source)
com.aspose.ocr.internal.bnl.a(Unknown Source)
com.aspose.ocr.OcrEngine.a(Unknown Source)
com.aspose.ocr.OcrEngine.process(Unknown Source)
ocr3.Ocr3.main(Ocr3.java:53)
— End of inner exception stack trace —
com.aspose.ocr.OcrEngine.a(Unknown Source)
com.aspose.ocr.OcrEngine.process(Unknown Source)
ocr3.Ocr3.main(Ocr3.java:53)
— End of inner exception stack trace —
com.aspose.ocr.OcrEngine.process(Unknown Source)
ocr3.Ocr3.main(Ocr3.java:53)
at com.aspose.ocr.OcrEngine.process(Unknown Source)
at ocr3.Ocr3.main(Ocr3.java:53)
Caused by: class com.aspose.ocr.OcrException: Error occurred during recognition. —> class com.aspose.ocr.internal.h: Recognition block right edge exceeds image border.
Parameter name: recognition block
com.aspose.ocr.internal.bnl.a(Unknown Source)
com.aspose.ocr.internal.bnl.a(Unknown Source)
com.aspose.ocr.OcrEngine.a(Unknown Source)
com.aspose.ocr.OcrEngine.process(Unknown Source)
ocr3.Ocr3.main(Ocr3.java:53)
— End of inner exception stack trace —
com.aspose.ocr.OcrEngine.a(Unknown Source)
com.aspose.ocr.OcrEngine.process(Unknown Source)
ocr3.Ocr3.main(Ocr3.java:53)
at com.aspose.ocr.OcrEngine.a(Unknown Source)
… 2 more
Caused by: class com.aspose.ocr.internal.h: Recognition block right edge exceeds image border.
Parameter name: recognition block
com.aspose.ocr.internal.bnl.a(Unknown Source)
com.aspose.ocr.internal.bnl.a(Unknown Source)
com.aspose.ocr.OcrEngine.a(Unknown Source)
com.aspose.ocr.OcrEngine.process(Unknown Source)
ocr3.Ocr3.main(Ocr3.java:53)
at com.aspose.ocr.internal.bnl.a(Unknown Source)
at com.aspose.ocr.internal.bnl.a(Unknown Source)
… 3 more
Java Result: 1
BUILD SUCCESSFUL (total time: 5 seconds)


mun mughal:
i used your defined code but using this image but no output came. run successful but no out put just blank out put there.
package ocr2;
//import com.aspose.ocr.OCRConfig;
import com.aspose.ocr.OcrEngine;
import com.aspose.ocr.ImageStream;
import com.aspose.ocr.RecognitionBlock;
/**
*
* @author mun
*/
public class Ocr2 {

/**
* @param args the command line arguments
*/
public static void main(String[] args) {
// TODO code application logic here
String imagepath="C:\\Users\\mun\\Desktop\\aspose-ocr-2.7.0-java\\lib\\output.jpg";
OcrEngine ocrEngine = new OcrEngine();
ocrEngine.setImage(ImageStream.fromFile(imagepath));

ocrEngine.getConfig().setDoSpellingCorrection(true);
ocrEngine.getConfig().setRemoveNonText(true);

ocrEngine.getConfig().addRecognitionBlock(RecognitionBlock.createTextBlock(182, 218, 160, 66));

if (ocrEngine.process())
{
System.out.println(ocrEngine.getText());
}

}
}


Hi Moon,

We have tried to reproduce the issue end our end by using the code sample provided by you. We are unable to reproduce it. Note that you have to change the block size and the location coordinates according to the image you are using. Further, the DPI value of the image provided by you is very low i.e. 72. Please note that the current implementation of the Aspose.OCR APIs perform well with images having resolution of at least 300 DPI and the accuracy rate tends to decrease by decreasing the resolution. So it is recommended that you should use images with at least 300 DPI.

mun mughal:
and the block u provided ..there came runtime error.
Exception in thread "main" class com.aspose.ocr.OcrException: class com.aspose.ocr.OcrException: Error occurred during recognition. ---> class com.aspose.ocr.internal.h: Recognition block right edge exceeds image border.
Parameter name: recognition block
com.aspose.ocr.internal.bnl.a(Unknown Source)
com.aspose.ocr.internal.bnl.a(Unknown Source)
com.aspose.ocr.OcrEngine.a(Unknown Source)
com.aspose.ocr.OcrEngine.process(Unknown Source)
ocr3.Ocr3.main(Ocr3.java:53)
--- End of inner exception stack trace ---
com.aspose.ocr.OcrEngine.a(Unknown Source)
com.aspose.ocr.OcrEngine.process(Unknown Source)
ocr3.Ocr3.main(Ocr3.java:53) ---> class com.aspose.ocr.OcrException: Error occurred during recognition. ---> class com.aspose.ocr.internal.h: Recognition block right edge exceeds image border.
Parameter name: recognition block
com.aspose.ocr.internal.bnl.a(Unknown Source)
com.aspose.ocr.internal.bnl.a(Unknown Source)
com.aspose.ocr.OcrEngine.a(Unknown Source)
com.aspose.ocr.OcrEngine.process(Unknown Source)
ocr3.Ocr3.main(Ocr3.java:53)
--- End of inner exception stack trace ---
com.aspose.ocr.OcrEngine.a(Unknown Source)
com.aspose.ocr.OcrEngine.process(Unknown Source)
ocr3.Ocr3.main(Ocr3.java:53)
--- End of inner exception stack trace ---
com.aspose.ocr.OcrEngine.process(Unknown Source)
ocr3.Ocr3.main(Ocr3.java:53)
at com.aspose.ocr.OcrEngine.process(Unknown Source)
at ocr3.Ocr3.main(Ocr3.java:53)
Caused by: class com.aspose.ocr.OcrException: Error occurred during recognition. ---> class com.aspose.ocr.internal.h: Recognition block right edge exceeds image border.
Parameter name: recognition block
com.aspose.ocr.internal.bnl.a(Unknown Source)
com.aspose.ocr.internal.bnl.a(Unknown Source)
com.aspose.ocr.OcrEngine.a(Unknown Source)
com.aspose.ocr.OcrEngine.process(Unknown Source)
ocr3.Ocr3.main(Ocr3.java:53)
--- End of inner exception stack trace ---
com.aspose.ocr.OcrEngine.a(Unknown Source)
com.aspose.ocr.OcrEngine.process(Unknown Source)
ocr3.Ocr3.main(Ocr3.java:53)
at com.aspose.ocr.OcrEngine.a(Unknown Source)
... 2 more
Caused by: class com.aspose.ocr.internal.h: Recognition block right edge exceeds image border.
Parameter name: recognition block
com.aspose.ocr.internal.bnl.a(Unknown Source)
com.aspose.ocr.internal.bnl.a(Unknown Source)
com.aspose.ocr.OcrEngine.a(Unknown Source)
com.aspose.ocr.OcrEngine.process(Unknown Source)
ocr3.Ocr3.main(Ocr3.java:53)
at com.aspose.ocr.internal.bnl.a(Unknown Source)
at com.aspose.ocr.internal.bnl.a(Unknown Source)
... 3 more
Java Result: 1
BUILD SUCCESSFUL (total time: 5 seconds)



Hi Moon,

Please note that this exception occurs when you provided some invalid block size or some invalid location coordinates that are outside the image boundary. Please, try again with some valid values of block size and the location coordinates. For more information on how to extract text from part of an image and getting values to define recognition block, follow the link given below:

Extracting Text from Part of an Image

how can i know the dpi of image?

Hi Moon,

You can find the DPI of an image as:

  • Right Click the image.
  • Select Properties menu item at the end.
  • Go to Details tab.

Here you can find the height & width, resolution, bit depth etc information of the image. Another way is to install any 3rd part software such as "IrfanView" to check the DPI (resolution) value of the image.

is this possible to send text as a message using your apis? im doing this on java platform.

Hi Moon,

Thank you for your inquiry.

Please, note that using Aspose.OCR it is not possible to send text as message. The functionality of Aspose.OCR is to recognize the characters only not to send any type of message. In case, if you want to send email message, you have to look into Aspose.Email APIs.