Мне пришлось установить кнопку, которая выбирает изображение, как показано в коде с моделью, инициализированной как model = "model.tflite"
pick_image = findViewById(R.id.pick_picture);
pick_image.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
// filename in assets
model = "model.tflite";
Intent gallery = new Intent(Intent.ACTION_PICK, MediaStore.Images.Media.INTERNAL_CONTENT_URI);
startActivityForResult(gallery, GET_FROM_GALLERY);
}
});
, тогда onActivity должен выглядеть так, как показано ниже
if(requestCode == REQUEST_IMAGE && resultCode == RESULT_OK) {
try {
Uri source_uri = imageUri;
Uri dest_uri = Uri.fromFile(new File(getCacheDir(), "cropped"));
// need to crop it to square image as CNN's always required square input
Crop.of(source_uri, dest_uri).asSquare().start(MainActivity.this);
} catch (Exception e) {
e.printStackTrace();
}
}
// if cropping acitivty is finished, get the resulting cropped image uri and send it to 'Classify' activity
else if(requestCode == Crop.REQUEST_CROP && resultCode == RESULT_OK){
imageUri = Crop.getOutput(data);
Intent i = new Intent(MainActivity.this, Classify.class);
// put image data in extras to send
i.putExtra("resID_uri", imageUri);
// put filename in extras
i.putExtra("chosen", chosen);
// send other required data
startActivity(i);
}
if (requestCode == GET_FROM_GALLERY && resultCode == RESULT_OK){
// beginCrop(data.getData());
try{
Uri source =data.getData();
Uri destination = Uri.fromFile(new File(getCacheDir(), "cropped"));
Crop.of(source, destination).asSquare().start(this);
}catch (Exception e){
e.printStackTrace();
}
}else if (requestCode == Crop.REQUEST_CROP && resultCode ==RESULT_OK){
// handleCrop(resultCode, data);
Uri gon = Crop.getOutput(data);
Intent i = new Intent(MainActivity.this, Classify.class);
// put image data in extras to send
i.putExtra("resID_uri", gon);
// put filename in extras
i.putExtra("chosen", chosen);
// send other required data
startActivity(i);
}