首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >颤振/照相机插件0.5.3上的设备定位不正确

颤振/照相机插件0.5.3上的设备定位不正确
EN

Stack Overflow用户
提问于 2019-08-16 16:56:08
回答 1查看 1.5K关注 0票数 0

我对“颤振”和“飞镖”都很陌生,我正尝试使用小米MI9SE (ANDROID)上的摄像头插件来检测我的TensorFlow Lite模型上的物体。所有的工作模式都在肖像模式,但当我打开智能手机景观视图预览不旋转,保持肖像的方向,并似乎不正确。

我试过使用其他版本的相机插件,但没有用。

detectObjectOnFrame代码:

代码语言:javascript
复制
         ` Tflite.detectObjectOnFrame(
            bytesList: img.planes.map((plane) {
              return plane.bytes;
            }).toList(),
            model: widget.model == yolo ? "YOLO" : "SSDMobileNet",
            imageHeight: img.height,
            imageWidth: img.width,
            imageMean: widget.model == yolo ? 0 : 127.5,
            imageStd: widget.model == yolo ? 255.0 : 127.5,
            numResultsPerClass: 1,
            threshold: widget.model == yolo ? 0.2 : 0.4,
          ).then((recognitions) {
            int endTime = new DateTime.now().millisecondsSinceEpoch;
            print("Detection took ${endTime - startTime}");

            widget.setRecognitions(recognitions, img.height, img.width);

            isDetecting = false;`

CAMERA.DART文件:

代码语言:javascript
复制
final List cameras;
final Callback setRecognitions;
final String model;

Camera(this.cameras, this.model, this.setRecognitions);

_CameraState createState() => new _CameraState();
}

class _CameraState extends State {
CameraController controller;
bool isDetecting = false;

void initState() {
super.initState();

if (widget.cameras == null || widget.cameras.length < 1) {
  print('No camera is found');
} else {
  controller = new CameraController(
    widget.cameras[0],
    ResolutionPreset.high,
  );
  controller.initialize().then((_) {
    if (!mounted) {
      return;
    }
    setState(() {});

    controller.startImageStream((CameraImage img) {
      if (!isDetecting) {
        isDetecting = true;

        int startTime = new DateTime.now().millisecondsSinceEpoch;

        if (widget.model == mobilenet) {
          ..........
           .......... (Ignored code)

            isDetecting = false;
          });
        } else {
          Tflite.detectObjectOnFrame(
           ..........
           .......... (Ignored code)

          });
        }
      }
    });
  });
}
}

void dispose() {
controller?.dispose();
super.dispose();
}

Widget build(BuildContext context) {
if (controller == null || !controller.value.isInitialized) {
return Container();
}

var tmp = MediaQuery.of(context).size;
var screenH = math.max(tmp.height, tmp.width);
var screenW = math.min(tmp.height, tmp.width);
tmp = controller.value.previewSize;
var previewH = math.max(tmp.height, tmp.width);
var previewW = math.min(tmp.height, tmp.width);
var screenRatio = screenH / screenW;
var previewRatio = previewH / previewW;

return OverflowBox(
  maxHeight:
      screenRatio > previewRatio ? screenH : screenW / previewW * previewH,
  maxWidth:
      screenRatio > previewRatio ? screenH / previewH * previewW : screenW,
  child: CameraPreview(controller),
);
}
}

HOME.DART:

代码语言:javascript
复制
setState(() {
_model = model;
});
loadModel();
}

setRecognitions(recognitions, imageHeight, imageWidth) {
setState(() {
_recognitions = recognitions;
_imageHeight = imageHeight;
_imageWidth = imageWidth;
});
}

@override
Widget build(BuildContext context) {
Size screen = MediaQuery.of(context).size;
return Scaffold(
body: _model == ""
? Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
RaisedButton(
child: const Text(yolo),
onPressed: () => onSelect(yolo),
),
],
),
)
: Stack(
children: [
Camera(
widget.cameras,
_model,
setRecognitions,
),
BndBox(
_recognitions == null ? [] : _recognitions,
math.max(_imageHeight, _imageWidth),
math.min(_imageHeight, _imageWidth),
screen.height,
screen.width,
_model),
],
),
);
}
}

Pubspec.yaml:

代码语言:javascript
复制
flutter_test:
sdk: flutter

camera: ^0.5.3
tflite: 1.0.4

这段代码在风景视图上给了我不正确的图像,预览不会和智能手机一起打开。

我很感激你的帮助。谢谢。

EN

回答 1

Stack Overflow用户

发布于 2019-08-17 12:16:57

在景观模式下,您可以在RotatedBox周围放置一个CameraPreview。它不应该将输入更改为detectObjectOnFrame():帧将到达TFlite,所以如果涉及到一些特殊的旋转,您应该禁用它。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/57528473

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档