dart 如何发送变焦命令到IP摄像机Flutter?

nnvyjq4y  于 2024-01-04  发布在  Flutter
关注(0)|答案(1)|浏览(230)

尝试使用easy_onvif库使用Flutter控制IP摄像机,但我无法让摄像机缩放。我尝试使用库提供的zoomIn函数,但没有成功。有人知道如何让摄像机执行缩放命令吗?下面是我用来与摄像机通信的代码:

  1. setZoom() async {
  2. final onvif = await Onvif.connect(
  3. host: "192.168.1.18:8999", username: "", password: "");
  4. var profiles = await onvif.media.getProfiles();
  5. var profileToken = await profiles.first.token;
  6. var ptzCommand = await onvif.ptz;
  7. print("zoom+");
  8. await ptzCommand.zoomIn(profileToken);
  9. print("zoom++");
  10. }

字符串
--SOS:许多连接发送命令或流的flutter库都被弃用了,这使得我很难找到flutter问题的答案,主要是作为一个初学者。

nnt7mjpx

nnt7mjpx1#

ONVIF connect和token命令可能需要很长时间。而且,缩放真的可以忽略不计。Zoom命令需要放在长按回调中。
以下是对我有效的方法:
1.首先连接摄像机。使用日志/打印语句确认它工作正常,没有任何问题
1.获取令牌。这偶尔需要很长时间才能完成,因此添加日志以确认)
1.然后调用zoom命令
P.S. -根据延迟,您可以看到屏幕缩放有显着延迟。
代码如下:

  1. class OnVIFService {
  2. OnVIFService();
  3. Onvif onvif;
  4. String token;
  5. Future<void> connect({@required String ip}) async {
  6. onvif = await Onvif.connect(
  7. host: ip,
  8. username: 'admin', // replace with your username
  9. password: '123456', // replace with your password
  10. );
  11. log('OnVIFService: connected to $ip');
  12. }
  13. Future<void> getToken() async {
  14. final profiles = await onvif.media.getProfiles();
  15. final profile = profiles.first;
  16. token = profile.token;
  17. log('OnVIFService: got token $token');
  18. }
  19. Future<void> moveLeft() async {
  20. await onvif.ptz.moveLeft(token);
  21. }
  22. Future<void> moveRight() async {
  23. await onvif.ptz.moveRight(token);
  24. }
  25. Future<void> moveUp() async {
  26. await onvif.ptz.moveUp(token);
  27. }
  28. Future<void> moveDown() async {
  29. await onvif.ptz.moveDown(token);
  30. }
  31. Future<void> stop() async {
  32. await onvif.ptz.stop(token);
  33. }
  34. Future<void> zoomIn() async {
  35. await onvif.ptz.zoomIn(token);
  36. }
  37. Future<void> zoomOut() async {
  38. await onvif.ptz.zoomOut(token);
  39. }
  40. }

字符串

展开查看全部

相关问题