如果我直接从命令提示符输入连接字符串,为什么我只能从 python opencv2 打开 rtsp 捕获?

问题描述

这是我遇到过的最奇怪的错误之一。我有以下 python 代码

import cv2 as cv

def newCamera():
  return frameIterator(
    'rtsp://admin:p4ssword@172.16.20.59:544/cam/realmonitor?channel=1&subtype=1'
  )

# return an infinite iterator of frames from an amcrest camera
def frameIterator(rtspConnStr):
  cap = cv.VideoCapture(rtspConnStr)
  return (
    cap.read() for _ in iter(int,1)
  )

在 python REPL 中,如果我这样做:

>>> import amcrest
>>> amcrest.frameIterator('rtsp://admin:p4ssword@172.16.20.59:544/cam/realmonitor?channel=1&subtype=1')
<generator object frameIterator.<locals>.<genexpr> at 0x7fe5ed350350>
>>> amcrest.newCamera()
[tcp @ 0x29fb180] Connection to tcp://172.16.20.59:544?timeout=0 Failed: Connection refused

我无法解释这种行为。比较 rtsp 连接字符串产生 True。我唯一的猜测是 ctypes 对它们进行了不同的编组,但我无法弄清楚。有什么帮助吗?谢谢!

编辑:这一切都在一个名为 amcrest.py文件中,因此 import amcrest :)

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)