赞
踩
首先一下是我的代码,读取的是监控视频rtsp数据
q = queue.Queue(5) cap = cv2.VideoCapture("rtsp://user:passwod@xx.xx.xx.xx/") def func1(): while cap.isOpened(): try: ret, img0 = cap.read() if q.qsize() >= 5: q.get() else: q.put(img0) except Exception as e: print(str(e)) # time.sleep(0.005) def func2(): while True: img0 = q.get() cv2.imshow("win2", cv2.resize(img0, (1024, 800))) if cv2.waitKey(5) & 0xFF == ord('q'): cv2.destroyAllWindows() break time.sleep(0.01) cap.release() if __name__ == '__main__': t1 = threading.Thread(target=func1) t2 = threading.Thread(target=func2) t1.start() t2.start()
[h264 @ 0x3000e00] error while decoding MB 209 68, bytestream
[h264 @ 0x3000e00] non-existing PPS 2 referenced
[h264 @ 0x3000e00] decode_slice_header error[NULL @ 0x2f39100] SEI type 79 size 1568 truncated at 960
[NULL @ 0x2f39100] missing picture in access unit with size 5728
[h264 @ 0x2f3bfc0] SEI type 79 size 1568 truncated at 951
[h264 @ 0x2f3bfc0] no frame![rtsp @ 0x2f35c40] RTP: PT=60: bad cseq 307a expected=232b
[NULL @ 0x2f39100] crop values invalid 1 7 4 0 / 16 32
[h264 @ 0x2f3bfc0] crop values invalid 1 7 4 0 / 16 32[rtsp @ 0x2f35c40] Undefined type (31)
[rtsp @ 0x2f35c40] RTP: PT=60: bad cseq 6b86 expected=5fb5
[h264 @ 0x2fa2300] cabac decode of qscale diff failed at 207 39
[h264 @ 0x2fa2300] error while decoding MB 207 39, bytestream 738[h264 @ 0x2f3bfc0] left block unavailable for requested intra4x4 mode -1
[NULL @ 0x2f39100] missing picture in access unit with size 47925
[h264 @ 0x358e240] no frame![h264 @ 0x2fa2300] top block unavailable for requested intra mode -1
[h264 @ 0x2fa2300] error while decoding MB 13 0, bytestream 53962
[h264 @ 0x2f3bfc0] number of reference frames (0+2) exceeds max (1; probably corrupt input), discarding one
[h264 @ 0x2f3bfc0] Missing reference picture, default is 65584
[h264 @ 0x3000e00] top block unavailable for requested intra mode
[h264 @ 0x3000e00] error while decoding MB 10 0, bytestream 54023
[h264 @ 0x2f3bfc0] Reference 4 >= 4
[h264 @ 0x2f3bfc0] error while decoding MB 88 0, bytestream 33732结束程序的错误:
cv2.error: OpenCV(3.4.9) /io/opencv/modules/imgproc/src/resize.cpp:4045: error: (-215:Assertion failed) !ssize.empty() in function ‘resize’
以上所有错误信息是整理过后的,主要发生在程序运行期间
错误信息主要分为 h264、 NULL、rtsp,以及程序在最后运行时的错误 cv2.error
cv2.error 导致了整个程序的结束
经过很长时间的研究发现,忽略了一件很重要的事情----硬件设备配置
opencv读取的如果是图片信息,那么不存在硬件配置的问题,发生的错误肯定是代码上的问题,比如路径写错了之类的。
但在此处,我读取的是视频数据,opencv处理视频的方式就是将每一帧的图片获取出来,进一步进行处理分析,此过程是相当消耗cpu运行的。将此程序运行起来后,可以很明显的发现视频窗口会有明显的卡顿,这时就已经发生了丢包丢帧的问题,查看cpu你会发现cpu的占用率可能是100%,所以丢帧丢包报错就很正常了,最后cpu处理不过来,就会发生cv2.error的问题,告诉你error: (-215:Assertion failed) !ssize.empty() in function ‘resize’,然后程序就结束了。
所以如果用opencv读取视频数据,首要的问题是要注意你的硬件配置cpu是否负担的起读取视频的消耗。以上代码换个16核或者32核处理器应该是不会报错的
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。