我正在研究实时对象检测模块,参考以下存储库:https ://github.com/shaqian/flutter_realtime_detection 。我面临的存储库问题是在某些设备上工作,包括模拟器。因此,为了调试,我试图获取我提供给检测模型的数据,即 img.planes.map((plane){return plane.bytes}).toList(); 并将其转换为图像,以下代码片段是:
List<int> b = [];
if (widget.cameras == null || widget.cameras.length < 1) {
print('No camera is found');
} else {
controller = new CameraController(
widget.cameras[0],
ResolutionPreset.medium,
);
controller.initialize().then((_) {
if (!mounted) {
return;
}
controller.startImageStream((CameraImage img) async {
if (!isDetecting) {
isDetecting = true;
b = img.planes
.map((plane) {
return plane.bytes;
})
.cast<int>()
.toList();
图像预览小部件:
Image.memory(
Uint8List.fromList(b),
在 Image.memory 小部件的地方,我得到:
日志是:
======== Exception caught by image resource service ================================================
解析图像编解码器时引发以下 _Exception:异常:图像数据无效
When the exception was thrown, this was the stack:
#0 _futurize (dart:ui/painting.dart:5394:5)
#1 ImageDescriptor.encoded (dart:ui/painting.dart:5262:12)
#2 instantiateImageCodec (dart:ui/painting.dart:2048:60)
<asynchronous suspension>
==================================================== ====================================================
Reloaded 1 of 652 libraries in 1,895ms.
W/examplerealtim( 7731): JNI critical lock held for 51.849ms on
Thread[16,tid=7769,Runnable,Thread*=0xdcf10a10,peer=0x130405e8,"Binder:7731_3"]
W/examplerealtim( 7731): JNI critical lock held for 50.358ms on
Thread[3,tid=7806,Runnable,Thread*=0xdcf04610,peer=0x12d80078,"Binder:7731_5"]
请帮忙。谢谢