title: Flutter: Change cameraPreview from bgra8888 to RGB 75x75x3 image so tflite model can predict
body: <p>I've built a mood detection algorithm that takes a 75x75x3 image and predicts on it.</p>
  <p>I've converted this to a tflite model and im using the camera preview in flutter to pass images and then predict on that image stream.</p>
  <p>Im not getting any predictions out but I presume its because the image isn't the right dimensions.</p>
  <p>Any ideas on how I can transform the data from the cameraPreview to use with my model?</p>
  <p>Code below for reference:</p>
  <pre><code>import 'package:camera/camera.dart';
  import 'package:flutter/cupertino.dart';
  import 'package:flutter/material.dart';
  import 'package:moodful/Screens/HomeScreen/home_screen.dart';
  import 'package:moodful/Screens/Login/login_screen.dart';
  import 'package:moodful/main.dart';
  import 'package:tflite/tflite.dart';
  import '../constants.dart';
  
  class CameraPage extends StatefulWidget {
    final List&lt;CameraDescription&gt;? cameras;
  
    const CameraPage({this.cameras, Key? key}) : super(key: key);
  
    @override
    _CameraPageState createState() =&gt; _CameraPageState();
  }
  
  class _CameraPageState extends State&lt;CameraPage&gt; {
    late CameraController controller;
  
    // used to increment camera switch tap
    int cameraIconTap = 0;
    CameraImage? cameraImage;
     String output= 'null';
    XFile? pictureFile;
  
    @override
    void initState() {
      super.initState();
      loadCamera();
      loadModel();
    }
  
      loadCamera(){
          controller = CameraController(
        widget.cameras![0],
        ResolutionPreset.veryHigh,
            imageFormatGroup: ImageFormatGroup.bgra8888
      );
      controller.initialize().then((_) {
            if (!mounted) {
              return;
            }
            setState(() {
              controller!.startImageStream((imageStream) {
                cameraImage = imageStream;
                runModel();
              });
            });
          });
      }
  
  
    runModel() async {
      if (cameraImage != null) {
        var predictions = await Tflite.runModelOnFrame(
            bytesList: cameraImage!.planes.map((plane) {
              return plane.bytes;
            }).toList(),
            imageHeight: cameraImage!.height,
            imageWidth: cameraImage!.width,
            imageMean: 127.5,
            imageStd: 127.5,
            rotation: 90,
            numResults: 2,
            threshold: 0.1,
            asynch: true);
        predictions!.forEach((element) {
          setState(() {
            output = element['label'];
          });
        });
      }
    }
  
  loadModel() async {
    await Tflite.loadModel(
        model: &quot;assets/model1.tflite&quot;, labels: &quot;assets/labels.txt&quot;);
  }
  
  
    @override
    void dispose() {
      controller.dispose();
      super.dispose();
    }
  
    @override
    Widget build(BuildContext context) {
      var size = MediaQuery.of(context).size;
      if (!controller.value.isInitialized) {
        return const SizedBox(
          child: Center(
            child: CircularProgressIndicator(),
          ),
        );
      }
      return Scaffold(
          appBar: AppBar(
            backgroundColor: kPrimaryColor,
            centerTitle: true,
            title: Text('AppBar'),
            leading: IconButton(
              onPressed: () {
                Navigator.push(
                  context,
                  MaterialPageRoute(
                      builder: (BuildContext context) =&gt; HomeScreen()),
                ).then((value) =&gt; setState(() {}));
                print(&quot;refresh done &quot;);
              },
              icon: Icon(Icons.home),
            ),
            actions: [
              IconButton(
                onPressed: () {
                  //increment on tap, calculate modulus, pass to widget.camera. 0 == rear camera, 1 == front camera
                  cameraIconTap++;
                  int modulusTap;
                  modulusTap = cameraIconTap % 2;
                  if (widget.cameras!.length &gt; 1) {
                    setState(() {
                      controller = CameraController(
                          widget.cameras![modulusTap], ResolutionPreset.veryHigh);
                    });
                    controller.initialize().then((_) {
                      if (!mounted) {
                        return;
                      }
                      setState(() {});
                    });
                  } else {
                    ScaffoldMessenger.of(context).showSnackBar(const SnackBar(
                      content: Text('No secondary camera found'),
                      duration: Duration(seconds: 2),
                    ));
                  }
                },
                icon: const Icon(Icons.cameraswitch),
              ),
            ],
          ),
          body: Center(
              child: Column(
            children: &lt;Widget&gt;[
              Padding(
                padding: const EdgeInsets.fromLTRB(8.0, 20.0, 8.0, 8.0),
                child: Column(
                  children: [
                    Center(
                      child: SizedBox(
                        height: //400
                        size.height / controller.value.aspectRatio,
                        width: size.width * 1.3 / controller.value.aspectRatio,
                        child: AspectRatio(
                          aspectRatio: controller.value.aspectRatio,
                          child: CameraPreview(controller),
                        ),
                      ),
                    ),
                  ],
                ),
              ),
              //),
  
              Text(output,
              style: TextStyle(
                  color: Colors.black
              )),
  
              if (pictureFile != null)
                Image.network(
                  pictureFile!.path,
                  height: 200,
                )
              //Android/iOS
              // Image.file(File(pictureFile!.path)))
            ],
          )));
    }
  }
  </code></pre>
  <p>Thanks!</p>