camera.java
final File file = new File(getExternalFilesDir(null) ,"/CCA_" + new SimpleDateFormat("yyyy-MM-dd_HHmmss", Locale.getDefault()).format(new Date()) + ".jpg");
ImageReader.OnImageAvailableListener readerListener = new ImageReader.OnImageAvailableListener() {
@Override
public void onImageAvailable(ImageReader imageReader) {
Image image;
image = reader.acquireLatestImage();
ByteBuffer buffer = image.getPlanes()[0].getBuffer();
byte[] bytes = new byte[buffer.capacity()];
buffer.get(bytes);
OutputStream outputStream = null;
try {
outputStream = new FileOutputStream(file);
outputStream.write(bytes);
imgTaken = file.getPath();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} finally {
if (outputStream != null) {
try {
outputStream.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
};
using this function to save the image taken.
scenarioFire.java
Bitmap bmpPhoto = BitmapFactory.decodeFile(imageFilePath);
List<ImageDetection.Recognition> predictions = imageDetection.recognizeImage(bmpPhoto,0);
final List<String> lstPredictions = new ArrayList<>();
for(ImageDetection.Recognition recognition : predictions){
lstPredictions.add(recognition.getName() + "- Confidence: " + recognition.getConfidence());
Log.e("Prediction: " , recognition.getName() + "- Confidence: " + recognition.getConfidence());
imageContains += recognition.getName() + "- Confidence: " + recognition.getConfidence() + "\n";
}
in this file i am trying to decode the jpeg into bitmap so it can be passed onto the tensorflow function to recognize the image, but the image cannot be decoded.
i have tried every solution on most forums and nothing seems to work.
keeps returning null. i have tried to see if it was the size affecting it or the location but those seem to be okay. dont know how to proceed