admin管理员组

文章数量:1125036

I am working on a Flutter application that uses the camera package and the image package to process images captured from the camera. I am trying to convert a CameraImage to an img.Image object for further processing, but I am encountering the following error:

Error generating face embedding: type 'int' is not a subtype of type 'Color' in type cast

Code

img.Image _convertCameraImageToImage(CameraImage cameraImage) {
  final int width = cameraImage.width;
  final int height = cameraImage.height;

   final img.Image rgbImage = img.Image(width: width, height: height);

   int byteIndex = 0;
      for (int y = 0; y < height; y++) {
        for (int x = 0; x < width; x++) {
        // Read pixel value; adjust based on your camera's format
        final int value = cameraImage.planes[0].bytes[byteIndex++];

       // Assuming grayscale for simplicity. Adjust if needed.
       final int red = value;
       final int green = value;
       final int blue = value;
       final int alpha = 255; // Full opacity

       // Set the pixel value using ARGB format directly
       final int pixel = (alpha << 24) | (red << 16) | (green << 8) | blue;

       // This line throws the error
      rgbImage.setPixel(x, y, pixel as img.Color);
   }
 }
 return rgbImage;
}

Error Details The error happens on this line:

rgbImage.setPixel(x, y, pixel as img.Color);

本文标签: