作者:骁炉 | 来源:互联网 | 2023-02-12 21:01
我已经尝试了很多方法,但是我无法成功。我尚未找到Android的任何源代码示例(关于rekognition)
在《开发人员指南》中的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:: 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
什么是空对象引用?我尝试更改文件路径,但他说没有此类文件...,当我更改为该路径时,上面有错误。顺便说一句,我已经向用户询问了从Android中的模拟器访问文件夹的权限
请帮助我PS。对不起,我的英语不好
先感谢您。