How can I detect objects in Amazon Rekognition AWS with Android Studio?

I have tried so much, but I cannot succeed. I didn’t find any source code examples for Android (about the reenactment)

there is source code in JAVA in the Developer's Guide, but I can not implement this, although I tried TT

I'm trying to detect faces by sending an image file from external storage (from the emulator) I don’t know what I did wrong (I can’t encode) Here is my code

AmazonRekognitionClient amazonRekognitionClient;
Image getAmazonRekognitionImage;
DetectFacesRequest detectFaceRequest;
DetectFacesResult detectFaceResult;
File file = new File(Environment.getExternalStorageDirectory(),"sungyeol.jpg.jpg");

public void test_00(View view) {
 ByteBuffer imageBytes;
 try{
        InputStream inputStream = new FileInputStream(file.getAbsolutePath().toString());
        imageBytes = ByteBuffer.wrap(IOUtils.toByteArray(inputStream));
        Log.e("InputStream: ",""+inputStream);
        Log.e("imageBytes: ","");
        getAmazonRekognitionImage.withBytes(imageBytes);

        // Initialize the Amazon Cognito credentials provider
        CognitoCachingCredentialsProvider credentialsProvider = new CognitoCachingCredentialsProvider(
                getApplicationContext(),
                "us-east-2:.......", // Identity Pool ID
                Regions.US_EAST_2 // Region
        );

        //I want "ALL" attributes
        amazonRekognitionClient = new AmazonRekognitionClient(credentialsProvider);

        detectFaceRequest = new DetectFacesRequest()
                .withAttributes(Attribute.ALL.toString())
                .withImage(getAmazonRekognitionImage);

        detectFaceResult = amazonRekognitionClient.detectFaces(detectFaceRequest);
        detectFaceResult.getFaceDetails();

    }
 catch(Exception ex){
   Log.e("Error on something:","Message:"+ex.getMessage());
 }

and here are my mistakes

02-04 09:30:07.268 29405-29405/? E/InputStream:: java.io.FileInputStream@a9b23e7
02-04 09:30:07.271 29405-29405/? E/Error on something:: Message:Attempt to invoke virtual method 'com.amazonaws.services.rekognition.model.Image com.amazonaws.services.rekognition.model.Image.withBytes(java.nio.ByteBuffer)' on a null object reference

What is a reference to a null object? I'm trying to change the path to a file, but he didn’t say such a file ... and when I go to this path, there are errors above. By the way, I already asked the user for permission to access the folder from Emulator in Android

please help me PS. sorry for my bad english

Thanks in advance.

+4
1

. <3 <3 <3.

, , . .

:

0. Rekognition--> http://docs.aws.amazon.com/general/latest/gr/rande.html#rekognition_region

1. " " , , "Image image = new Image();" <- ""

2. ( NetworkOnMainThreadException), , → https://docs.aws.amazon.com/cognito/latest/developerguide/getting-credentials.html , ...

enter image description here

, AsyncTask, AsyncTask, , , AsyncTask. Code รัน ตอน ท้าย ๆ น้ำตา จิ ไหล ... TT , , sungyeol.jpg.jpg

private void testTask(){
  .... all code in the main thread particularly on the requests and responses
  from the services
 //print the response or the result
 //Log.e() makes the message in the android monitor red like an error
 Log.e("Response:", [responseparameter.toString()]);

}

//create the inherited class from the AsyncTask Class
//(you can create within your activity class)
class AsyncTaskRunner extends AsyncTask<String,String,String>{
    @Override 
    public String doInBackground(String ... input){
        testTask(); // call the testTask() method that i have created
        return null; // this override method must return String
    }

} 

//I've created a button for running the task
public void buttonTask(View view){
    AsyncTaskRunner runner = new AsyncTaskRunner();
    runner.execute();

}

AsyncTask:

https://developer.android.com/training/basics/network-ops/connecting.html#AsyncTask

http://www.compiletimeerror.com/2013/01/why-and-how-to-use-asynctask.html#.WJdkqVOLTIU

, :)

+2

Source: https://habr.com/ru/post/1668815/


All Articles