tflite_flutter_helper
tflite_flutter_helper copied to clipboard
[FEATURE] ImageConversion: support for converting float32 TensorBuffer to Image
@bazinac We will need more flexibility here, along with your changes. Thanks a lot for your contribution. I will make changes on top of these and merge them.
Can we also add support for converting Image to float32 TensorBuffer for those who need it for their model? I did this successfully.
static void convertImageToTensorBuffer(Image image, TensorBuffer buffer) {
int w = image.width;
int h = image.height;
List
buffer.loadList(rgbValues, shape: shape);
} else if (buffer.getDataType() == TfLiteType.float32) {
Float32List rgbValues = new Float32List(w * h * 3);
for (int i = 0, j = 0; i < intValues.length; i++) {
if (intValues[i] == null) {
print(i);
}
rgbValues[j++] = (((intValues[i]) & 0xFF) / 255.0).toDouble();
rgbValues[j++] = (((intValues[i] >> 8) & 0xFF) / 255.0).toDouble();
rgbValues[j++] = (((intValues[i] >> 16) & 0xFF) / 255.0).toDouble();
}
buffer.loadList(rgbValues, shape: shape);
} else {
throw UnsupportedError(
"The TensorBuffer of type ${buffer.getBuffer()} to Image is not supported yet.",
);
}
}`