How to use Request class of com.galenframework.ocr.google.pojo.request package

Best Galen code snippet using com.galenframework.ocr.google.pojo.request.Request

Source:GoogleVisionOcrService.java Github

copy

Full Screen

...29import com.galenframework.config.GalenConfig;30import com.galenframework.config.GalenProperty;31import com.galenframework.ocr.google.pojo.GoogleModel;32import com.galenframework.ocr.google.pojo.request.Feature;33import com.galenframework.ocr.google.pojo.request.GoogleRequest;34import com.galenframework.ocr.google.pojo.request.Image;35import com.galenframework.ocr.google.pojo.request.Request;36import com.galenframework.page.Rect;37import com.galenframework.validation.ValidationErrorException;38import org.apache.commons.io.IOUtils;39import org.apache.http.HttpResponse;40import org.apache.http.client.HttpClient;41import org.apache.http.client.methods.HttpPost;42import org.apache.http.entity.StringEntity;43import org.apache.http.impl.client.HttpClients;44/**45 * Implementation of the OcrService.46 * Cache the model, so if the same image is used, will send a single OCR request to the service.47 * @author guy arieli, Ivan Shubin48 *49 */50public class GoogleVisionOcrService implements OcrService {51 private final static String BASE_URL = "https://vision.googleapis.com/v1/images:annotate?key=";52 final static HttpClient httpClient = HttpClients.createDefault();53 final static ObjectMapper objectMapper = new ObjectMapper();54 @Override55 public OcrResult findOcrText(BufferedImage image, Rect rect) throws ValidationErrorException {56 if (rect.getRight() > image.getWidth() && rect.getBottom() > rect.getHeight()) {57 throw new ValidationErrorException("Could not extract element image. Looks like it is located outside of screenshot area");58 }59 try {60 BufferedImage croppedImage = image.getSubimage(rect.getLeft(), rect.getTop(), rect.getWidth(), rect.getHeight());61 GoogleModel model = getGoogleModel(croppedImage);62 if (model.responses != null && !model.responses.isEmpty()) {63 String resultedText = model.responses.get(0).fullTextAnnotation.text;64 if (resultedText == null) {65 resultedText = "";66 }67 return new OcrResult(new String(resultedText.getBytes(Charset.forName("utf-8"))), rect);68 } else {69 throw new NullPointerException("Got empty result");70 }71 } catch (Exception e) {72 throw new ValidationErrorException("Google vision API error: " + e.getMessage(), e);73 }74 }75 public static GoogleModel getGoogleModel(BufferedImage img) throws Exception {76 String key = GalenConfig.getConfig().readProperty(GalenProperty.GALEN_OCR_GOOGLE_VISION_KEY);77 if (key == null) {78 throw new RuntimeException("Missing property " + GalenProperty.GALEN_OCR_GOOGLE_VISION_KEY + ". See https://cloud.google.com/vision/docs/auth for more info");79 }80 GoogleRequest grequest = new GoogleRequest();81 List<Request> requests = new ArrayList<>();82 Request request = new Request();83 requests.add(request);84 Image image = new Image();85 image.setContent(imgToBase64String(img, "PNG"));86 request.setImage(image);87 grequest.setRequests(requests);88 List<Feature> features = new ArrayList<>();89 Feature feature = new Feature();90 feature.setType("TEXT_DETECTION");91 feature.setMaxResults(1);92 request.setFeatures(features);93 features.add(feature);94 return postOcrImage(key, grequest);95 }96 private static GoogleModel postOcrImage(String key, GoogleRequest grequest) throws IOException {97 String url = BASE_URL + key;98 HttpResponse response = post(url, grequest);99 int status = response.getStatusLine().getStatusCode();100 String responseText = IOUtils.toString(response.getEntity().getContent());101 if (status < 400) {102 System.out.println("\n" + responseText);103 return objectMapper.readValue(responseText, GoogleModel.class);104 } else {105 String message;106 try {107 JsonNode tree = objectMapper.readTree(responseText);108 message = tree.get("error").get("message").asText();109 } catch (Exception ex) {110 message = responseText;...

Full Screen

Full Screen

Source:Request.java Github

copy

Full Screen

...16package com.galenframework.ocr.google.pojo.request;17import java.util.List;18import com.google.gson.annotations.Expose;19import com.google.gson.annotations.SerializedName;20public class Request {21 @SerializedName("image")22 @Expose23 private Image image;24 @SerializedName("features")25 @Expose26 private List<Feature> features = null;27 public Image getImage() {28 return image;29 }30 public void setImage(Image image) {31 this.image = image;32 }33 public List<Feature> getFeatures() {34 return features;...

Full Screen

Full Screen

Source:GoogleRequest.java Github

copy

Full Screen

...16package com.galenframework.ocr.google.pojo.request;17import java.util.List;18import com.google.gson.annotations.Expose;19import com.google.gson.annotations.SerializedName;20public class GoogleRequest {21 @SerializedName("requests")22 @Expose23 private List<Request> requests = null;24 public List<Request> getRequests() {25 return requests;26 }27 public void setRequests(List<Request> requests) {28 this.requests = requests;29 }30}...

Full Screen

Full Screen

Request

Using AI Code Generation

copy

Full Screen

1package com.galenframework.ocr.google.pojo.request;2import java.util.List;3import com.google.gson.annotations.Expose;4import com.google.gson.annotations.SerializedName;5public class Request {6@SerializedName("image")7private Image image;8@SerializedName("features")9private List<Feature> features = null;10public Image getImage() {11return image;12}13public void setImage(Image image) {14this.image = image;15}16public List<Feature> getFeatures() {17return features;18}19public void setFeatures(List<Feature> features) {20this.features = features;21}22}23package com.galenframework.ocr.google.pojo.request;24import java.util.List;25import com.google.gson.annotations.Expose;26import com.google.gson.annotations.SerializedName;27public class Request {28@SerializedName("image")29private Image image;30@SerializedName("features")31private List<Feature> features = null;32public Image getImage() {33return image;34}35public void setImage(Image image) {36this.image = image;37}38public List<Feature> getFeatures() {39return features;40}41public void setFeatures(List<Feature> features) {42this.features = features;43}44}45package com.galenframework.ocr.google.pojo.request;46import java.util.List;47import com.google.gson.annotations.Expose;48import com.google.gson.annotations.SerializedName;49public class Request {50@SerializedName("image")51private Image image;52@SerializedName("features")53private List<Feature> features = null;54public Image getImage() {55return image;56}57public void setImage(Image image) {58this.image = image;59}60public List<Feature> getFeatures() {61return features;62}63public void setFeatures(List<Feature> features) {64this.features = features;65}66}67package com.galenframework.ocr.google.pojo.request;68import java.util.List;69import com.google.gson.annotations.Expose;70import com.google.gson.annotations.SerializedName;71public class Request {72@SerializedName("image")73private Image image;74@SerializedName("features")75private List<Feature> features = null;76public Image getImage() {77return image;

Full Screen

Full Screen

Request

Using AI Code Generation

copy

Full Screen

1package com.galenframework.ocr.google.pojo.request;2import java.util.List;3public class Request {4 private List<AnnotateImageRequest> requests;5 public List<AnnotateImageRequest> getRequests() {6 return requests;7 }8 public void setRequests(List<AnnotateImageRequest> requests) {9 this.requests = requests;10 }11}12package com.galenframework.ocr.google.pojo.request;13import java.util.List;14public class AnnotateImageRequest {15 private Image image;16 private List<Feature> features;17 public Image getImage() {18 return image;19 }20 public void setImage(Image image) {21 this.image = image;22 }23 public List<Feature> getFeatures() {24 return features;25 }26 public void setFeatures(List<Feature> features) {27 this.features = features;28 }29}30package com.galenframework.ocr.google.pojo.request;31public class Image {32 private String content;33 public String getContent() {34 return content;35 }36 public void setContent(String content) {37 this.content = content;38 }39}40package com.galenframework.ocr.google.pojo.request;41public class Feature {42 private String type;43 private int maxResults;44 public String getType() {45 return type;46 }47 public void setType(String type) {48 this.type = type;49 }50 public int getMaxResults() {51 return maxResults;52 }53 public void setMaxResults(int maxResults) {54 this.maxResults = maxResults;55 }56}57package com.galenframework.ocr.google.pojo.response;58import java.util.List;59public class Response {60 private List<AnnotateImageResponse> responses;61 public List<AnnotateImageResponse> getResponses() {62 return responses;63 }64 public void setResponses(List<AnnotateImageResponse> responses) {65 this.responses = responses;66 }

Full Screen

Full Screen

Request

Using AI Code Generation

copy

Full Screen

1package com.galenframework.ocr.google.pojo.request;2import java.util.ArrayList;3import java.util.List;4import com.fasterxml.jackson.annotation.JsonIgnoreProperties;5import com.fasterxml.jackson.annotation.JsonProperty;6@JsonIgnoreProperties(ignoreUnknown = true)7public class Request {8@JsonProperty("image")9private Image image;10@JsonProperty("features")11private List<Feature> features = new ArrayList<Feature>();12@JsonProperty("imageContext")13private ImageContext imageContext;14public Image getImage() {15return image;16}17public void setImage(Image image) {18this.image = image;19}20public List<Feature> getFeatures() {21return features;22}23public void setFeatures(List<Feature> features) {24this.features = features;25}26public ImageContext getImageContext() {27return imageContext;28}29public void setImageContext(ImageContext imageContext) {30this.imageContext = imageContext;31}32}33package com.galenframework.ocr.google.pojo.request;34import com.fasterxml.jackson.annotation.JsonIgnoreProperties;35import com.fasterxml.jackson.annotation.JsonProperty;36@JsonIgnoreProperties(ignoreUnknown = true)37public class Feature {38@JsonProperty("type")39private String type;40@JsonProperty("maxResults")41private Integer maxResults;42@JsonProperty("model")43private String model;44public String getType() {45return type;46}47public void setType(String type) {48this.type = type;49}50public Integer getMaxResults() {51return maxResults;52}53public void setMaxResults(Integer maxResults) {54this.maxResults = maxResults;55}56public String getModel() {57return model;58}59public void setModel(String model) {60this.model = model;61}62}63package com.galenframework.ocr.google.pojo.request;64import com.fasterxml.jackson.annotation.JsonIgnoreProperties;65import com.fasterxml.jackson.annotation.JsonProperty;66@JsonIgnoreProperties(ignoreUnknown = true)67public class ImageContext {68@JsonProperty("languageHints")69private List<String> languageHints = new ArrayList<String>();70public List<String> getLanguageHints() {71return languageHints;72}73public void setLanguageHints(List<String> languageHints) {74this.languageHints = languageHints;75}76}77package com.galenframework.ocr.google.pojo.request;78import com.fasterxml.jackson.annotation.JsonIgnoreProperties;79import com.fasterxml.jackson.annotation.JsonProperty;

Full Screen

Full Screen

Request

Using AI Code Generation

copy

Full Screen

1import com.galenframework.ocr.google.pojo.request.Request;2import com.galenframework.ocr.google.pojo.response.Response;3import com.galenframework.ocr.google.GoogleOcrClient;4public class Sample {5 public static void main(String[] args) throws Exception {6 Request request = new Request();7 request.setBase64Image("base64 encoded image string");8 request.setLanguage("en");9 request.setOcrType("text");10 GoogleOcrClient client = new GoogleOcrClient();11 Response response = client.process(request);12 System.out.println(response);13 }14}15import com.galenframework.ocr.google.GoogleOcrClient;16public class Sample {17 public static void main(String[] args) throws Exception {18 GoogleOcrClient client = new GoogleOcrClient();19 String response = client.process("base64 encoded image string", "en", "text");20 System.out.println(response);21 }22}23import com.galenframework.ocr.google.GoogleOcrClient;24public class Sample {25 public static void main(String[] args) throws Exception {26 GoogleOcrClient client = new GoogleOcrClient();27 String response = client.process("base64 encoded image string");28 System.out.println(response);29 }30}31import com.galenframework.ocr.google.GoogleOcrClient;32public class Sample {33 public static void main(String[] args) throws Exception {34 GoogleOcrClient client = new GoogleOcrClient();35 String response = client.process("base64 encoded image string", "en");36 System.out.println(response);37 }38}39import com.galenframework.ocr.google.GoogleOcrClient;40public class Sample {41 public static void main(String[] args) throws Exception {

Full Screen

Full Screen

Request

Using AI Code Generation

copy

Full Screen

1Request request = new Request();2request.setRequests(requests);3GoogleOcr googleOcr = new GoogleOcr();4String response = googleOcr.getOcrResponse(request);5Response responseObj = new Gson().fromJson(response, Response.class);6List<Responses> responses = responseObj.getResponses();7for (Responses resp : responses) {8 List<TextAnnotations> textAnnotations = resp.getTextAnnotations();9 for (TextAnnotations textAnnotation : textAnnotations) {10 System.out.println("Text: " + textAnnotation.getDescription());11 System.out.println("Bounding Poly: " + textAnnotation.getBoundingPoly());12 System.out.println("Confidence: " + textAnnotation.getConfidence());13 }14}

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run Galen automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Most used methods in Request

Test Your Web Or Mobile Apps On 3000+ Browsers

Signup for free

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful