Initialize camera
Initializing Camera:
Inside the main method initialize the available cameras using
availableCameras
.
List<CameraDescription> cameras;Future<void> main() async {
WidgetsFlutterBinding.ensureInitialized();
cameras = await availableCameras();
runApp(MyApp());
}
camera
the package provides us support for live image streaming. Firstly create an object of the CameraController
. CameraController
takes two arguments CameraDescription
and ResolutionPreset
. initialize
the cameraController
and then we can start our image streaming using the startImageStream method. startImageStream
the method provides us the images, we will give these images to cameraImage, and then we will run our model.
CameraImage cameraImage;
CameraController cameraController;
initCamera() {
cameraController = CameraController(cameras[0], ResolutionPreset.medium);
cameraController.initialize().then((value) {
if (!mounted) return;
setState(() {
cameraController.startImageStream((image) {
cameraImage = image;
runModel();
});
});
});
}
Comments
Post a Comment