Skip to content

Instantly share code, notes, and snippets.

View truongsinh's full-sized avatar
:octocat:
Blessed

TruongSinh Tran-Nguyen truongsinh

:octocat:
Blessed
View GitHub Profile
@truongsinh
truongsinh / tflite.dart
Created September 19, 2019 00:33
feed and invoke
// ...
final inputTensor = localInterpreter.getInputTensors().single;
// shape 1, 300, 300, 3; 1 image * 300 width * 300 height * 3 colors
inputTensor.data = imgData;
localInterpreter.invoke();
// https://www.tensorflow.org/lite/models/object_detection/overview
@truongsinh
truongsinh / image_processing.dart
Created September 19, 2019 00:29
PreProcessedImageData
class PreProcessedImageData {
final Size originalSize;
final Uint8List preProccessedImageBytes;
PreProcessedImageData._(this.originalSize, this.preProccessedImageBytes);
factory PreProcessedImageData(CameraImage camImg) {
final rawRgbImage = convertCameraImageToImageColor(camImg);
final rgbImage = // camera plugin on Android sucks
@truongsinh
truongsinh / image_processing.dart
Created September 19, 2019 00:23
convertBGRA8888toImageColor
// ...
imglib.Image convertBGRA8888toImageColor(CameraImage image) {
final result = imglib.Image.fromBytes(
image.width,
image.height,
image.planes[0].bytes,
format: imglib.Format.bgra,
);
return result;
}
@truongsinh
truongsinh / image_processing.dart
Created September 19, 2019 00:23
convertBGRA8888toImageColor
// ...
imglib.Image convertBGRA8888toImageColor(CameraImage image) {
final result = imglib.Image.fromBytes(
image.width,
image.height,
image.planes[0].bytes,
format: imglib.Format.bgra,
);
return result;
}
@truongsinh
truongsinh / tflite.dart
Created September 19, 2019 00:22
tflInterpreter
// ...
Future<tfl.Interpreter> tflInterpreter(
String modelFile, {
int numThreads = 1,
}) async {
final rawModel = await rootBundle.load('assets/$modelFile');
Directory appDocDir = await getTemporaryDirectory();
String appDocPath = appDocDir.path;
final localFile = File('$appDocPath/$modelFile');
@truongsinh
truongsinh / image_processing.dart
Created September 19, 2019 00:19
convertYUV420toImageColor
// ...
imglib.Image convertYUV420toImageColor(CameraImage image) {
final int width = image.width;
final int height = image.height;
final int uvRowStride = image.planes[1].bytesPerRow;
final int uvPixelStride = image.planes[1].bytesPerPixel;
const alpha255 = (0xFF << 24);
// imgLib -> Image package from https://pub.dartlang.org/packages/image
@truongsinh
truongsinh / tflite.dart
Last active September 19, 2019 00:18
load label
// ...
final labels = (await rootBundle.loadString('assets/$labels')).split("\n").sublist(1);
// ...
@truongsinh
truongsinh / Info.plist
Created September 19, 2019 00:05
ios/Runner/Info.plist
<key>NSCameraUsageDescription</key>
<string>Camera is used to do live preview</string>
# ...
dependencies:
camera: 0.5.2+2
path_provider: 1.3.0
image: 2.1.4
tflite_native:
git:
url: https://github.com/truongsinh/tflite_native.git
ref: d2458d1
# ...
# The following section is specific to Flutter.
flutter:
# The following line ensures that the Material Icons font is
# included with your application, so that you can use the icons in
# the material Icons class.
uses-material-design: true