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);
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());
}
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; }
}
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; }
}
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; }
}
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; }
}
Overview: Saaspose.OCR
Saaspose.OCR is a platform independent REST API used for optical character recognition and document scanning. It allows developers to scan documents, extract text and recognize characters from the documents in the cloud. It supports OCR feature for whole image, partial image or a specific rectangular area of an image file. It can be used with languages like .NET, Java, PHP, Ruby, Rails, Python, jQuery & many others. It can also be integrated with other cloud services to process documents.
More about Saaspose.BarCode
- Homepage of Saaspose.OCR
- More Technical Tips by Saaspose.OCR
- 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
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
No comments:
Post a Comment