You can read all the details at: Recognize Text by Performing OCR on Image from URL with Java
Last active
December 23, 2021 06:56
-
-
Save aspose-com-gists/e74d058177ae660b2e875ee69d6c4ab7 to your computer and use it in GitHub Desktop.
Recognize Text by Performing OCR on Image from URL with Java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Create api instance | |
AsposeOCR api = new AsposeOCR(); | |
String uri = "https://www.castlegateit.co.uk/wp-content/uploads/2016/09/justified_text.png"; | |
BufferedImage image = null; | |
try{ | |
java.net.URL url =new java.net.URL(uri); | |
// read the url | |
image = ImageIO.read(url); | |
}catch(IOException e){ | |
e.printStackTrace(); | |
} | |
// set recognition options | |
RecognitionSettings settings = new RecognitionSettings(); | |
double angle = 0; | |
// Get skew angle | |
try { | |
angle = api.CalcSkewImage(image); | |
System.out.println("Skew text is:" + angle + " degrees."); | |
} catch (IOException e1) { | |
e1.printStackTrace(); | |
} | |
settings.setSkew(angle); | |
ArrayList<Rectangle> rectangles = new ArrayList<Rectangle>(); | |
rectangles.add(new Rectangle(90,186,775,95)); | |
settings.setRecognitionAreas(rectangles); | |
// get result object | |
RecognitionResult result = null; | |
try { | |
result = api.RecognizePageFromUri(uri, settings); | |
} catch (IOException e) { | |
e.printStackTrace(); | |
} | |
// print result | |
System.out.println("Result: \n" + result.recognitionText+"\n\n"); | |
System.out.println("RecognitionAreasText: \n"); | |
for(String text: result.recognitionAreasText) { | |
System.out.println(text); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Create api instance | |
AsposeOCR api = new AsposeOCR(); | |
// Specify image URI | |
String uri = "https://www.castlegateit.co.uk/wp-content/uploads/2016/09/justified_text.png"; | |
// Set recognition options | |
RecognitionSettings settings = new RecognitionSettings(); | |
settings.setAutoSkew(false); | |
ArrayList<Rectangle> rectangles = new ArrayList<Rectangle>(); | |
rectangles.add(new Rectangle(90,186,775,95)); | |
settings.setRecognitionAreas(rectangles); | |
// Get result object | |
RecognitionResult result = null; | |
try { | |
result = api.RecognizePageFromUri(uri, settings); | |
} catch (IOException e) { | |
e.printStackTrace(); | |
} | |
// Print result | |
System.out.println("Result: \n" + result.recognitionText+"\n\n"); | |
System.out.println("RecognitionAreasText: \n"); | |
for(String text: result.recognitionAreasText) { | |
System.out.println(text); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment