I need to extract the text from images (png,jpeg,tiff, AFP) documents using aspose? can you please advice it is possible or not? I try to use Aspose OCR but I am not able to get the text.
if possible, can you please share the sample code using java?
@sudhakar11
Cause
Yes, it is possible to extract text from images (PNG, JPEG, TIFF, AFP) using Aspose. The Aspose.OCR library is specifically designed for this purpose. If you’re experiencing difficulties in extracting text, it may be due to factors such as image quality, OCR settings, or the specific format of the image.
Solution
To extract text from images using Aspose.OCR in Java, you can follow this sample code:
Code
import com.aspose.ocr.*;
public class OcrExample {
public static void main(String[] args) {
// Create an instance of OcrEngine
OcrEngine ocrEngine = new OcrEngine();
// Load the image file
ocrEngine.setImage(ImageStream.fromFile("path/to/your/image.png"));
// Perform OCR
if (ocrEngine.process()) {
// Get the recognized text
String recognizedText = ocrEngine.getText().getText();
System.out.println("Recognized Text: " + recognizedText);
} else {
System.out.println("OCR processing failed.");
}
}
}
Make sure to replace "path/to/your/image.png"
with the actual path to your image file.
Next Steps
- Ensure that the image quality is good; low-quality images can lead to poor OCR results.
- Experiment with different image formats if you’re not getting satisfactory results.
- Check the Aspose.OCR documentation for additional settings that might improve recognition accuracy.
If you follow these steps and still encounter issues, please provide more details about the specific problems you’re facing, and I will assist you further!
I am using the aspose-ocr-22.5.jar file
We use the same code but we are getting the error for below code.
String recognizedText = ocrEngine.getText().getText();
getText() method not available? can you please tell me which jar file we need to use?
@sudhakar11
We request you please use the code snippet given in below example with the latest available version of the API and in case you face any issues, please share your sample image with us. We will test the scenario in our environment and address it accordingly.
hi @asad.ali thanks for you reply.
I try the use the code Recognition|Documentation but i am getting the below error msg.
java.lang.UnsatisfiedLinkError : no onnxruntime4j_jni in java.library.path
I try to add the onnxruntime.jar file in classpath.
currently we are using open JDK 1.8
@sudhakar11
Would you please try adding onnxruntime 1.20.0 JAR in your project? In case you are working with Maven, you can use below dependency in pom.xml:
<!-- https://mvnrepository.com/artifact/com.microsoft.onnxruntime/onnxruntime -->
<dependency>
<groupId>com.microsoft.onnxruntime</groupId>
<artifactId>onnxruntime</artifactId>
<version>1.20.0</version>
</dependency>