如何解决如何将 flutter CameraImage 优化为 TensorImage?
那个函数太慢了。那么 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;
}```
解决方法
似乎您的 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。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。