Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public String getText(Path imgPath) throws Exception {
- String text = "Fuck off";
- System.setProperty("aws.accessKeyId", "AKIAZTV6LSMNHTQV6WFK");
- System.setProperty("aws.secretKey", "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");
- AmazonRekognition rk = AmazonRekognitionClientBuilder.standard().withRegion(Regions.US_EAST_1).build();
- byte[] bytes = Files.readAllBytes(new File("chloe advil.jpg").toPath());
- ByteBuffer byteBuffer = ByteBuffer.wrap(bytes);
- Image img = new Image().withBytes(byteBuffer);
- DetectTextRequest req = new DetectTextRequest();
- req.withImage(img);
- DetectTextResult res = rk.detectText(req);
- for ( TextDetection d : res.getTextDetections() ) {
- text = d.getDetectedText();
- if (text.contains("DIN") && text.length() == 11) {
- text = text.replace("DIN", "");
- print("Found DIN and Number");
- print(text);
- break;
- } else if (Pattern.matches("[a-zA-Z]+", text) == false && text.length() > 2 && text.length() == 8) {
- print("Found Number");
- print(text);
- break;
- }
- //float width = d.getGeometry().getBoundingBox().getWidth();
- }
- print(res.toString());
- return text;
- }
- public static void print(String text) {
- System.out.println(text);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement