Advertisement
Guest User

Untitled

a guest
Aug 24th, 2019
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.28 KB | None | 0 0
  1. public String getText(Path imgPath) throws Exception {
  2. String text = "Fuck off";
  3.  
  4. System.setProperty("aws.accessKeyId", "AKIAZTV6LSMNHTQV6WFK");
  5. System.setProperty("aws.secretKey", "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");
  6.  
  7. AmazonRekognition rk = AmazonRekognitionClientBuilder.standard().withRegion(Regions.US_EAST_1).build();
  8. byte[] bytes = Files.readAllBytes(new File("chloe advil.jpg").toPath());
  9. ByteBuffer byteBuffer = ByteBuffer.wrap(bytes);
  10.  
  11. Image img = new Image().withBytes(byteBuffer);
  12. DetectTextRequest req = new DetectTextRequest();
  13. req.withImage(img);
  14.  
  15. DetectTextResult res = rk.detectText(req);
  16.  
  17. for ( TextDetection d : res.getTextDetections() ) {
  18. text = d.getDetectedText();
  19. if (text.contains("DIN") && text.length() == 11) {
  20. text = text.replace("DIN", "");
  21. print("Found DIN and Number");
  22. print(text);
  23. break;
  24. } else if (Pattern.matches("[a-zA-Z]+", text) == false && text.length() > 2 && text.length() == 8) {
  25. print("Found Number");
  26. print(text);
  27. break;
  28. }
  29. //float width = d.getGeometry().getBoundingBox().getWidth();
  30. }
  31. print(res.toString());
  32. return text;
  33. }
  34.  
  35. public static void print(String text) {
  36. System.out.println(text);
  37. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement