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 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<Part> Parts;
public List<Part> 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.BarCode
- Homepage of Saaspose.OCR
- More
Technical Tips by Saaspose.BarCode
- Ask technical questions/queries from Saaspose
Support Team
Contact Information
Aspose Pty Ltd, Suite 163,
79 Longueville Road
Lane Cove, NSW, 2066
Australia
Saaspose - Your File Format Experts 2.0
sales@aspose.com
Phone: 1.214.329.1520
Fax: 866.810.9465