This technical tip allows developers to extract image text from remote image URL using Saaspose.OCR REST API in their Java applications.
Terms of Agreement:
By using this article, you agree to the following terms...
You may use
this article in your own programs (and may compile it into a program and distribute it in compiled format for languages that allow it) freely and with no charge.
You MAY NOT redistribute this article (for example to a web site) without written permission from the original author. Failure to do so is a violation of copyright laws.
You may link to this article from another website, but ONLY if it is not wrapped in a frame.
You will abide by any additional copyright restrictions which the author may have placed in the article or article's description.
This technical tip allows developers to extract image text from remote image URL using Saaspose.OCR REST API in their Java applications. Some important steps for performing this task is to build URI to extract text, sign URI, execute signed URI request and get response, Parse and deserialize the JSON to an object and Display the value and type of all the extracted text.
Sample Code for Extracting Image Text from Remote Image URL
//build URI to extract text
String strURI = "";
strURI = "http://api.saaspose.com/v1.0/ocr/recognize?url=http://s017.radikal.ru/i406/1202/7b/70183bef7a09.jpg&language=english&useDefaultDictionaries=true";
//sign URI
String signedURI = Sign(strURI);
//execute signed URI request and get response
InputStream responseStream = ProcessCommand(signedURI, "POST");
String strJSON = StreamToString(responseStream);
// Parse and deserialize the JSON to a object.
OCRResponse ocrResponse = gson.fromJson(strJSON, OCRResponse.class);
// Display the value and type of all the recognized barcodes
for (Part part : ocrResponse.getPartsInfo().getList())
{
System.out.println("Text: " + part.getText());
System.out.println("Font Name: " + part.getFontName());
System.out.println("Font Size: " + part.getFontSize());
System.out.println("Bold: " + part.getBold());
System.out.println("Italic: " + part.getItalic());
System.out.println("Underline: " + part.getUnderline());
}
//Here is the OCRResponse class
public class OCRResponse extends BaseResponse
{
private String Text;
private OCREnvelop PartsInfo;
public String getText() { return Text; }
public OCREnvelop getPartsInfo() { return PartsInfo; }
}
//Here is the OCREnvelop class
public class OCREnvelop
{
private List Parts;
public List getList() { return Parts; }
}
//Here is the Part class
public class Part
{
public Part() { }
private String FontName;
private float FontSize;
private boolean Bold;
private boolean Italic;
private boolean Underline;
private String Text;
public String getFontName() { return FontName; }
public float getFontSize() { return FontSize; }
public boolean getBold() { return Bold; }
public boolean getItalic() { return Italic; }
public boolean getUnderline() { return Underline; }
public String getText() { return Text; }
}
More about Saaspose.OCR
- Homepage of Saaspose.OCR: http://saaspose.com/api/ocr
- More Technical Tips by Saaspose.OCR: http://saaspose.com/docs/display/ocr/1.2+-+Saaspose.OCR+Examples
Your feedback will be posted below and an email sent to
the author. Please remember that the author was kind enough to
share this with you, so any criticisms must be stated politely, or they
will be deleted. (For feedback not related to this particular article, please
click here instead.)