我已經嘗試了很多方法,但我無法成功。我還沒有發現任何源代碼示例爲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。對不起我的英文不好
謝謝你提前。
這將是有益的如果你可以發佈你的解決方案,我是在相同的情況下。 –
我編輯了我的帖子以獲取更多信息,我希望這些可以幫助您。 –