getCameraImagePredictionList method

Future<List<double>> getCameraImagePredictionList(
  1. CameraImage cameraImage,
  2. int rotation, {
  3. List<double> mean = torchVisionNormMeanRGB,
  4. List<double> std = torchVisionNormSTDRGB,
  5. CameraPreProcessingMethod cameraPreProcessingMethod = CameraPreProcessingMethod.imageLib,
  6. PreProcessingMethod preProcessingMethod = PreProcessingMethod.imageLib,
})

Retrieves a list of predictions for a camera image.

Takes a cameraImage and rotation as input. Optional parameters include mean, std, cameraPreProcessingMethod, and preProcessingMethod. Returns a Future that resolves to a List of double values representing the predictions. Throws an Exception if unable to process the image bytes.

Implementation

Future<List<double>> getCameraImagePredictionList(
    CameraImage cameraImage, int rotation,
    {List<double> mean = torchVisionNormMeanRGB,
    List<double> std = torchVisionNormSTDRGB,
    CameraPreProcessingMethod cameraPreProcessingMethod =
        CameraPreProcessingMethod.imageLib,
    PreProcessingMethod preProcessingMethod =
        PreProcessingMethod.imageLib}) async {
  // Perform preprocessing based on the chosen camera pre-processing method
  if (cameraPreProcessingMethod == CameraPreProcessingMethod.imageLib) {
    Uint8List? bytes =
        await ImageUtilsIsolate.convertCameraImageToBytes(cameraImage);
    if (bytes == null) {
      throw Exception("Unable to process image bytes");
    }
    // Retrieve the image predictions for the preprocessed image bytes
    return await getImagePredictionList(bytes,
        mean: mean, std: std, preProcessingMethod: preProcessingMethod);
  }
  // Retrieve the image predictions for the camera image planes
  return await getImagePredictionListFromBytesList(
      cameraImage.planes.map((e) => e.bytes).toList(),
      cameraImage.width,
      cameraImage.height,
      mean: mean,
      std: std);
}