This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ... | |
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ... | |
imglib.Image convertBGRA8888toImageColor(CameraImage image) { | |
final result = imglib.Image.fromBytes( | |
image.width, | |
image.height, | |
image.planes[0].bytes, | |
format: imglib.Format.bgra, | |
); | |
return result; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ... | |
imglib.Image convertBGRA8888toImageColor(CameraImage image) { | |
final result = imglib.Image.fromBytes( | |
image.width, | |
image.height, | |
image.planes[0].bytes, | |
format: imglib.Format.bgra, | |
); | |
return result; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ... | |
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'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ... | |
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ... | |
final labels = (await rootBundle.loadString('assets/$labels')).split("\n").sublist(1); | |
// ... |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<key>NSCameraUsageDescription</key> | |
<string>Camera is used to do live preview</string> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# ... | |
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# ... | |
# 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 |