尝试使用 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 问题的答案,主要是对于初学者来说。
ONVIF 连接和令牌命令可能需要很长时间。而且,变焦确实可以忽略不计。缩放命令需要放置在长按回调中。
这对我有用:
附注- 根据延迟,您可以看到屏幕缩放有明显的延迟。
这是代码:
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);
}
}