4

我已经尝试了很多方法,但我无法成功。我还没有发现任何源代码示例为Android(约rekognition)如何使用Android Studio在亚马逊重新识别AWS中识别出自动识别区域?

有一个在JAVA源代码的开发者指南中,但我不能执行,即使我试过TT

我试图通过发送到人脸从外部存储器中(模拟器) 图像文件,我不知道我做错了什么(我不是在编码好) 这里是我的代码

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()); 
} 

,这里是我的错误

02-04 09:30:07.268 29405-29405/? E/InputStream:: [email protected] 
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 

什么是空对象引用? 我试图改变文件路径,但他说没有这样的文件...当我改变到这个路径,上面有错误。 顺便说一句,我已经问过用户的权限来访问Android中的模拟器的文件夹

请帮我 PS。对不起我的英文不好

谢谢你提前。

回答

2

现在我确定有问题 我已经通过马努很多事情 谢谢

我是泰国,我不得不更努力地尝试寻找解决方案,因为那里缺乏以特定语言提供的信息,但这里是我的解决方案。

我的解决方案是:

0.There是设置为Rekognition端点 - > http://docs.aws.amazon.com/general/latest/gr/rande.html#rekognition_region

1.On一个“空对象引用的问题:”我发现,我要创建一个首先创建新对象,如“图像图像=新图像()”; < - “新”命令,在该类

2.After上述错误创建一个对象实例,有更多的错误(在NetworkOnMainThreadException错误),所以我尝试了一切,直到我发现这个页面 - > https://docs.aws.amazon.com/cognito/latest/developerguide/getting-credentials.html网页说,...

enter image description here

因此,我抬头有关的AsyncTask的详细信息之后,我创建了一个的AsyncTask类,然后将我的所有代码有关初始化的请求,对AsyncTask类的响应。 ตอนรันตอนท้ายๆน้ำตาจิไหลmy code worked ... TT and by the the the the 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

我希望这些帮助:)

+0

这将是有益的如果你可以发布你的解决方案,我是在相同的情况下。 –

+0

我编辑了我的帖子以获取更多信息,我希望这些可以帮助您。 –