python3.6使用opencv的resize方法不定时报错

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了python3.6使用opencv的resize方法不定时报错相关的知识,希望对你有一定的参考价值。

ret, frame = video_capture.read()small_frame = cv2.resize(frame, None, fx=0.15, fy=0.15)rgb_small_frame = small_frame[:, :, ::-1]small_frame = cv2.resize(frame, None, fx=0.15, fy=0.15)这一行报错报错代码:OpenCV Error: Assertion failed (ssize.width > 0 && ssize.height > 0) in cv::resize, file C:\projects\opencv-python\opencv\modules\imgproc\src\resize.cpp, line 4044Traceback (most recent call last): File "E:/python/cam/My_face_recognition.py", line 35, in <module> small_frame = cv2.resize(frame, None, fx=0.15, fy=0.15)cv2.error: C:\projects\opencv-python\opencv\modules\imgproc\src\resize.cpp:4044: error: (-215) ssize.width > 0 && ssize.height > 0 in function cv::resize
OpenCV Error: Assertion failed (ssize.width > 0 && ssize.height > 0) in cv::resize, file C:\projects\opencv-python\opencv\modules\imgproc\src\resize.cpp, line 4044
Traceback (most recent call last):
File "E:/python/cam/My_face_recognition.py", line 35, in <module>
small_frame = cv2.resize(frame, None, fx=0.15, fy=0.15)
cv2.error: C:\projects\opencv-python\opencv\modules\imgproc\src\resize.cpp:4044: error: (-215) ssize.width > 0 && ssize.height > 0 in function cv::resize

参考技术A 应该是frame变量从摄像头中加载图像失败导致的frame的尺寸变为0导致的。在获取frame以后一定要使用frame.empty()函数判断一下获取的图像是否正确,否则接下来所有对frame的操作都会失败。

以上是关于python3.6使用opencv的resize方法不定时报错的主要内容,如果未能解决你的问题,请参考以下文章

Anaconda默认Python3.8版本创建Python3.6版本环境并安装opencv3.4.1.15,使用pycharm作为IDE

基于Python3.6+OpenCV行人检测(GUI界面)

OpenCV 图片尺寸缩放——resize函数

OpenCV 图片尺寸缩放——resize函数

SIFT图像特征提取 python3.6 + opencv3.3代码

ubuntu18.04 安装python3.6 opencv3.8.4