如何通过颤动向网络摄像机发送变焦命令?

问题描述 投票:0回答:1

尝试使用 easy_onvif 库通过 Flutter 控制 IP 摄像头,但无法让摄像头变焦。我尝试过使用库提供的 ZoomIn 函数,但没有成功。有谁知道如何让相机执行缩放命令?这是我用来与相机通信的代码:

setZoom() async {
    final onvif = await Onvif.connect(
        host: "192.168.1.18:8999", username: "", password: "");

    var profiles = await onvif.media.getProfiles();
    var profileToken = await profiles.first.token;

    var ptzCommand = await onvif.ptz;
    print("zoom+");
    await ptzCommand.zoomIn(profileToken);
    print("zoom++");
}

--SOS:许多连接以发送命令或流的 Flutter 库已被弃用,这使得我很难找到 Flutter 问题的答案,主要是对于初学者来说。

android flutter dart camera
1个回答
0
投票

ONVIF 连接和令牌命令可能需要很长时间。而且,变焦确实可以忽略不计。缩放命令需要放置在长按回调中。

这对我有用:

  1. 先连接相机。使用日志/打印语句确认其工作正常,没有任何问题
  2. 获取代币。这有时需要很长时间才能完成,所以添加日志来确认)
  3. 然后调用缩放命令

附注- 根据延迟,您可以看到屏幕缩放有明显的延迟。

这是代码:


class OnVIFService {
  OnVIFService();

  Onvif onvif;
  String token;

  Future<void> connect({@required String ip}) async {
    onvif = await Onvif.connect(
      host: ip,
      username: 'admin', // replace with your username
      password: '123456', // replace with your password
    );

    log('OnVIFService: connected to $ip');
  }

  Future<void> getToken() async {
    final profiles = await onvif.media.getProfiles();
    final profile = profiles.first;
    token = profile.token;

    log('OnVIFService: got token $token');
  }

  Future<void> moveLeft() async {
    await onvif.ptz.moveLeft(token);
  }

  Future<void> moveRight() async {
    await onvif.ptz.moveRight(token);
  }

  Future<void> moveUp() async {
    await onvif.ptz.moveUp(token);
  }

  Future<void> moveDown() async {
    await onvif.ptz.moveDown(token);
  }

  Future<void> stop() async {
    await onvif.ptz.stop(token);
  }

  Future<void> zoomIn() async {
    await onvif.ptz.zoomIn(token);
  }

  Future<void> zoomOut() async {
    await onvif.ptz.zoomOut(token);
  }
}
© www.soinside.com 2019 - 2024. All rights reserved.