【问题标题】:How to optimize flutter CameraImage to TensorImage?如何优化颤振CameraImage到TensorImage?
【发布时间】:2021-05-18 08:11:49
【问题描述】:

那个功能太慢了。那么 Flutter CameraImage 效率转换为 dart 中的 TensorImage 呢?

    var img = imglib.Image(image.width, image.height); // Create Image buffer

    Plane plane = image.planes[0];
    const int shift = (0xFF << 24);

    // Fill image buffer with plane[0] from YUV420_888
    for (int x = 0; x < image.width; x++) {
      for (int planeOffset = 0;
          planeOffset < image.height * image.width;
          planeOffset += image.width) {
        final pixelColor = plane.bytes[planeOffset + x];
        // color: 0x FF  FF  FF  FF
        //           A   B   G   R
        // Calculate pixel color
        var newVal =
            shift | (pixelColor << 16) | (pixelColor << 8) | pixelColor;

        img.data[planeOffset + x] = newVal;
      }
    }

    return img;
  }```

【问题讨论】:

    标签: flutter tensorflow dart tensorflow-lite flutter-image


    【解决方案1】:

    您的 for 循环似乎效率低下。整行(placeOffset 相同,x 不同)的数据会被一次性缓存,因此切换两个循环的顺序会更快。

    for (int y = 0; y < image.height; y++) {
      for (int x = 0; x < image.width; x++) {
        final pixelColor = plane.bytes[y * image.width + x];
        // ...
      }
    }
    

    但是,您的代码似乎并未从实际的摄像头流中读取数据。请参考此线程将 CameraImage 转换为 Image。

    How to convert Camera Image to Image in Flutter?

    【讨论】:

      猜你喜欢
      • 2019-06-16
      • 2021-11-25
      • 2021-06-27
      • 2022-08-23
      • 2020-03-11
      • 2021-07-04
      • 1970-01-01
      • 2020-10-13
      • 1970-01-01
      相关资源
      最近更新 更多