【问题标题】:when using pyinstaller when connecting to the webcam all is well, when connecting to the IP camera an error occurs使用 pyinstaller 连接网络摄像头时一切正常,连接网络摄像头时出现错误
【发布时间】:2020-01-02 13:06:33
【问题描述】:

当使用 pyinstaller 连接到网络摄像头时一切正常,当连接到 IP 摄像头时出现错误: 错误文本:文件“15.py”,第 8 行,在 cv2.error: OpenCV(4.1.0) C:\projects\opencv-python\opencv\modules\highgui\src\window.cpp:352: error: (-215:Assertion failed) size.width>0 && size。函数'cv::imshow'中的高度>0

import cv2
stream = cv2.VideoCapture('rtsp://192.168.161.70/1')


while True:

    r, f = stream.read()
    cv2.imshow('IP Camera stream',f)
    #r,f = imutils.resize(f, width=400)

    if cv2.waitKey(1) & 0xFF == ord('q'):
        break

cv2.destroyAllWindows()

我尝试过这样调试,但没有成功

import imutils
import cv2######################ip camers
stream = cv2.VideoCapture('rtsp://admin:admin@192.168.161.70:554/Streaming/Channels/201')



while True:

    r, f = stream.read()
    if r==False:
        cv2.waitKey(1000)
        print('false')
        stream.open ('rtsp://admin:admin@192.168.161.70:554/Streaming/Channels/201')
    else:
        cv2.imshow('IP Camera stream',f)
        f = imutils.resize(f, width=400)

        if cv2.waitKey(1) & 0xFF == ord('q'):
            break

cv2.destroyAllWindows()
input()

【问题讨论】:

  • 我建议您始终检查 VideoCapture.read(在您的情况下为 r)的返回值,以避免此类错误并能够更快地进行调试。问题是它无法连接到相机,你确定ip是正确的吗?你确定端口是正确的(默认情况下没有端口是 80,通常 rtsp 在 554 上)?你确定没有防火墙阻止连接吗?
  • 是的,相机是我在 VLC 媒体播放器中检查的工作。在本网站的示例中,我指出了错误的行。抱歉,请更正此 'rtsp://admin:admin@192.168.161.70:554/Streaming/Channels/201'。当我运行文件 *.py 时一切正常。但是我用 pyinstaller 转换 *.exe 中的文件后都不起作用。关于调试,我添加了尝试用于调试的代码。

标签: opencv pyinstaller


【解决方案1】:

我解决了我的问题。在转换 pyinstaller 之前,不要在带有 *.exe 文件的文件夹中添加文件 opencv_ffmpeg410_64.dll。为了正确工作,需要从带有 *.exe 文件的文件夹内的 opencv 文件夹中复制此文件

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-12-20
    • 1970-01-01
    • 1970-01-01
    • 2021-10-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多