Here's my code:
imageAnalysis.setAnalyzer(ThreadManager.getInstance().cameraExecutor, new ImageAnalysis.Analyzer() {
@SuppressLint("UnsafeOptInUsageError")
@Override
public void analyze(@NonNull ImageProxy image) {
int rotationDegrees = image.getImageInfo().getRotationDegrees();
// insert your code here.
Log.d(TAG, "starting");
Bitmap bmp = Bitmap.createBitmap(270,480, Bitmap.Config.ARGB_8888);
conv.yuvToRgb(image.getImage(), bmp);
ByteBuffer buffer = ByteBuffer.allocate(3*270*480*4);
int pixelVals[] = new int[480*270*3];
bmp.getPixels(pixelVals, 0, bmp.getWidth(), 0, 0, bmp.getWidth(), bmp.getHeight());
int itr = 0;
for(int i=0;i<480;++i)
{
for(int j=0;j<270;++j)
{
int x = pixelVals[itr++];
float red = ((x >> 16) & 0xFF) / 256.f;
float green = ((x >> 8) & 0xFF) / 256.f;
float blue = (x & 0xFF) / 256.f;
buffer.putFloat(red);
buffer.putFloat(green);
buffer.putFloat(blue);
}
}
float[][] output = new float[1][1];
tflite.run(buffer, output);
float out = output[0][0];
ContextCompat.getMainExecutor(MainActivity.this).execute(new Runnable() {
@Override
public void run() {
scoretv.setText(out+"");
Log.d(TAG, "updating");
}
});
image.close();
}
});
The problem is that tflite.run() always return the same output, no matter what the input is. I've tested my .tflite model using python script on my pc and it works correctly.
I'm not sure if buffer holds correctly converted image when run() is called, but using debugger I verified that it at least looks like correct image data, and certainly should not give the same result every time. (Buffer data changes, so output should change too)
Also, this model should output floats closer to 1.0 when object is detected, and closer to 0.0 when it isn't. If image was corruped during conversion, model should output low value (confirmed by tests on my pc).
Model always outputs 0.7001277
EDIT: This is edited version, original question is now outdated. Sorry for that, I probably should had waited a little more time before asking a question.