Amazon Rekognition用于图像中的文本检测文本

时间:2018-08-30 18:46:45

标签: android apache android-studio amazon-rekognition

使用Amazon Rekognition服务获取图像中的文本时出现错误

Process: com.example.myapplication, PID: 32656
    java.lang.NoSuchFieldError: org.apache.http.conn.ssl.AllowAllHostnameVerifier.INSTANCE
        at org.apache.http.conn.ssl.SSLConnectionSocketFactory.<clinit>(SSLConnectionSocketFactory.java:146)
        at com.amazonaws.http.apache.client.impl.ApacheConnectionManagerFactory.getPreferredSocketFactory(ApacheConnectionManagerFactory.java:86)
        at com.amazonaws.http.apache.client.impl.ApacheConnectionManagerFactory.create(ApacheConnectionManagerFactory.java:63)
        at com.amazonaws.http.apache.client.impl.ApacheConnectionManagerFactory.create(ApacheConnectionManagerFactory.java:56)
        at com.amazonaws.http.apache.client.impl.ApacheHttpClientFactory.create(ApacheHttpClientFactory.java:50)
        at com.amazonaws.http.apache.client.impl.ApacheHttpClientFactory.create(ApacheHttpClientFactory.java:38)
        at com.amazonaws.http.AmazonHttpClient.<init>(AmazonHttpClient.java:317)
        at com.amazonaws.http.AmazonHttpClient.<init>(AmazonHttpClient.java:301)
        at com.amazonaws.AmazonWebServiceClient.<init>(AmazonWebServiceClient.java:194)
        at com.amazonaws.services.rekognition.AmazonRekognitionClient.<init>(AmazonRekognitionClient.java:290)
        at com.amazonaws.services.rekognition.AmazonRekognitionClientBuilder.build(AmazonRekognitionClientBuilder.java:61)
        at com.amazonaws.services.rekognition.AmazonRekognitionClientBuilder.build(AmazonRekognitionClientBuilder.java:27)
        at com.amazonaws.client.builder.AwsSyncClientBuilder.build(AwsSyncClientBuilder.java:46)
        at com.amazonaws.services.rekognition.AmazonRekognitionClientBuilder.defaultClient(AmazonRekognitionClientBuilder.java:45)
        at com.example.myapplication.MainActivity.onCreate(MainActivity.java:59)
        at android.app.Activity.performCreate(Activity.java:5343)
        at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1088)
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2340)
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2438)
        at android.app.ActivityThread.access$800(ActivityThread.java:160)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1351)
        at android.os.Handler.dispatchMessage(Handler.java:110)
        at android.os.Looper.loop(Looper.java:193)
        at android.app.ActivityThread.main(ActivityThread.java:5368)
        at java.lang.reflect.Method.invokeNative(Native Method)
        at java.lang.reflect.Method.invoke(Method.java:515)
        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:828)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:644)
        at dalvik.system.NativeStart.main(Native Method)

这是我的代码

String photo = Environment.getExternalStorageDirectory().getAbsolutePath()+"/test/testImage.png";

    ByteBuffer imageBytes;
        try  {

            InputStream inputStream = new FileInputStream(new File(photo));
            imageBytes = ByteBuffer.wrap(IOUtils.toByteArray(inputStream));
            Logger.getLogger("org.apache.http").setLevel(Level.FINEST);
            Logger.getLogger("com.amazonaws").setLevel(Level.FINEST);

            ImageView imageView = findViewById(R.id.image);
            Glide.with(this)
                    .load(photo)
                    .into(imageView);

                  AmazonRekognition rekognitionClient = AmazonRekognitionClientBuilder.defaultClient();


            DetectTextRequest  request = new DetectTextRequest ()
                    .withImage(new Image()
                            .withBytes(imageBytes));



            DetectTextResult  result = rekognitionClient.detectText(request);
            List<TextDetection> textDetections = result.getTextDetections();

            Log.i(TAG,"Detected lines and words for " + photo);
                for (TextDetection  text: textDetections) {

                    Log.i(TAG,"Detected: " + text.getDetectedText());
                    Log.i(TAG,"Confidence: " + text.getConfidence().toString());


                }
        }
        catch (Exception e)
        {
            Log.e(TAG,e.toString());
        }

我尝试使用库'org.apache.httpcomponents:httpmime:4.3.6'和'org.apache.httpcomponents:httpclient-android:4.3.6',但是对于httpclient'gradle'无法解决其依赖关系。 / p>

我写错了吗?我还可以在图像中使用文本从本地存储中获取图像吗?它是否支持阿拉伯语?

1 个答案:

答案 0 :(得分:0)

如文档中所述,当前算法只能识别

https://en.wikipedia.org/wiki/ISO_basic_Latin_alphabet

大写和小写英文字符。

文本检测:

https://docs.aws.amazon.com/rekognition/latest/dg/text-detection.html

  

一个单词是一个或多个ISO基本拉丁字母字符,不是   用空格隔开。 DetectText最多可以在一张图像中检测50个单词。

在撰写本文时,尚不支持阿拉伯语。

希望有帮助。