(-215:Assertion failed) number < max_number in function 'cv::icvExtractPattern' 错误?

(-215:Assertion failed) number < max_number in function 'cv::icvExtractPattern' error?

我正在尝试 运行 这个 python 脚本作为一个 exe 文件 - 使用 pyinstaller,它引发了我这个错误:

[ERROR:0] global C:\projects\opencv-python\opencv\modules\videoio\src\cap.cpp (415) cv::VideoWriter::open VIDEOIO(CV_IMAGES): raised OpenCV exception: OpenCV(4.2.0) C:\projects\opencv-python\opencv\modules\videoio\src\cap_images.cpp:267: error: (-215:Assertion failed) number < max_number in function 'cv::icvExtractPattern'

当我运行将其作为python 脚本时,它运行良好。 python 脚本:

SCREEN_SIZE = (1920, 1080)
FPS = 20.0
fourcc = cv2.VideoWriter_fourcc(*"XVID")
out = cv2.VideoWriter("output.avi", fourcc, FPS, SCREEN_SIZE)

我在命令行中使用 pyinstaller:

pyinstaller --onefile python_script.py

我应该更改什么才能使其正常工作?

主要解决方法:可能是DLL错误

我想你的问题与 this issue. There is a workaround suggested in this comment 有关。它建议 运行 pyinstaller 为

pyinstaller -F --add-data opencv_ffmpeg410_64.dll;. python_script.py

确保适应您的 OpenCV 版本。确保这个 dll 存在于任何地方。

选择: 我相信错误

python\opencv\modules\videoio\src\cap_images.cpp:267: error: (-215:Assertion failed) number < max_number in function 'cv::icvExtractPattern'

是由此处 fourcc = cv2.VideoWriter_fourcc(*"XVID") 这一行引起的,其中设置的值是 > 最大值。

你可以尝试将fourcc设置为-1。然后,它将为您提供用于编写​​的视频编解码器的选择。我发现未压缩的视频选择适用于大多数平台。