Обнаружение объектов Android: как вернуть null, если ИИ ничего не обнаружил после захвата?
Поэтому я создал приложение, которое может определить, обнаруживаю я банан или нет. Каждый раз, когда я захватываю объект, не являющийся бананом, он все равно возвращает результат, что это банан. Я не использовал живое обнаружение камеры. Просто камера, и после ее захвата откроется новый интент, показывающий результат.
Вот код:
try {
Android model = Android.newInstance(getApplicationContext());
// Creates inputs for reference.
//TensorImage image = TensorImage.fromBitmap(image2);
ImageProcessor imageProcessor =
new ImageProcessor.Builder()
.add(new ResizeOp(224, 224, ResizeOp.ResizeMethod.BILINEAR))
.build();
TensorImage tensorImage = new TensorImage(DataType.UINT8);
tensorImage.load(image2);
tensorImage = imageProcessor.process(tensorImage);
// Runs model inference and gets result.
Android.Outputs outputs = model.process(tensorImage);
Android.DetectionResult detectionResult = outputs.getDetectionResultList().get(0);
score = detectionResult.getScoreAsFloat();
location = detectionResult.getLocationAsRectF();
category = detectionResult.getCategoryAsString();
// Releases model resources if no longer used.
model.close();
} catch (IOException e) {
// TODO Handle the exception
}
tv.setText(category);