gpt4 book ai didi

python - Try-Catch Exception 在 OpenCV-python 中不起作用

转载 作者:行者123 更新时间:2023-12-02 16:18:16 25 4
gpt4 key购买 nike

所以我特意在 cv2.VideoCapture() 中放置了一个文件,该文件在我的计算机中不存在以测试我已放入代码中的 try-catch 系统,但由于某种原因,它仍然会发出与我相同的错误没有将 try-catch 放入我的代码中。我该如何解决??
代码:

import numpy as np
import cv2



try:
cap = cv2.VideoCapture('trial.mkv')
while (cap.isOpened()):
ret, frame = cap.read()

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

cap.release()
cv2.destroyAllWindows()
except:
print("no file found")
错误:
[ERROR:0] global C:\Users\appveyor\AppData\Local\Temp\1\pip-req-build-cff9bdsm\opencv\modules\videoio\src\cap.cpp (142) cv::VideoCapture::open VIDEOIO(CV_IMAGES): raised OpenCV exception:

OpenCV(4.4.0) C:\Users\appveyor\AppData\Local\Temp\1\pip-req-build-cff9bdsm\opencv\modules\videoio\src\cap_images.cpp:253: error: (-5:Bad argument) CAP_IMAGES: can't find starting number (in the name of file): trial.mkv in function 'cv::icvExtractPattern'

最佳答案

try/except 捕获到错误时声明和 stderr msg 仍然被打印,这只是意味着库只是将所有错误消息发送到 stderr .OpenCV众所周知,图书馆有这个问题,并且有办法解决它。你应该在这里阅读详细的答案 - OpenCv errorHow to stop OpenCV error message from printing in Python

关于python - Try-Catch Exception 在 OpenCV-python 中不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63733744/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com