python pixels <= CV_IO_MAX_IMAGE_PIXELS in function ‘cv::validateInputImageSize‘ 解决方法

python 在读取大的图像的时候出现 

cv2.error: OpenCV(4.7.0) D:\a\opencv-python\opencv-python\opencv\modules\imgcodecs\src\loadsave.cpp:79: error: (-215:Assertion failed) pixels <= CV_IO_MAX_IMAGE_PIXELS in function 'cv::validateInputImageSize'
错误。

import cv2
img_path = r"E:\data\map\2307041910\19\2307041910.tif"  # 图像大小 54528*67840
img = cv2.imread(img_path)
print(img.shape)
Traceback (most recent call last):
  File "D:/workspace/python/real_work/test.py", line 6, in <module>
    img = cv2.imread(img_path)
cv2.error: OpenCV(4.7.0) D:\a\opencv-python\opencv-python\opencv\modules\imgcodecs\src\loadsave.cpp:79: error: (-215:Assertion failed) pixels <= CV_IO_MAX_IMAGE_PIXELS in function 'cv::validateInputImageSize'

原因:By default number of pixels must be less than 2^30.

解决方法: Limit can be set using system variable OPENCV_IO_MAX_IMAGE_PIXELS

具体实现: python 程序前面增加如下两句

import os
os.environ["OPENCV_IO_MAX_IMAGE_PIXELS"] = pow(2, 40).__str__()
import os
os.environ["OPENCV_IO_MAX_IMAGE_PIXELS"] = pow(2, 40).__str__()

import cv2
img_path = r"E:\data\map\2307041910\19\2307041910.tif"  # 图像大小 54528*67840
img = cv2.imread(img_path)
print(img.shape)
(54528, 67840, 3)

Process finished with exit code 0

参考:

Assertion failed) pixels <= CV_IO_MAX_IMAGE_PIXELS in function 'validateInputImageSize' | Giving me headaches · Issue #15829 · opencv/opencv · GitHub

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值