当前位置:网站首页>cv2.resize函数报错:error: (-215:Assertion failed) func != 0 in function ‘cv::hal::resize‘
cv2.resize函数报错:error: (-215:Assertion failed) func != 0 in function ‘cv::hal::resize‘
2022-07-25 12:43:00 【1 + 1=王】
报错
在使用cv2.resize() 对图片调整大小时遇到了以下错误。
img_array = cv2.resize(img_array,(1024,1024))
cv2.error: OpenCV(4.5.2) C:\Users\runneradmin\AppData\Local\Temp\pip-req-build-1bq9o88m\opencv\modules\imgproc\src\resize.cpp:3929: error: (-215:Assertion failed) func != 0 in function ‘cv::hal::resize’
错误代码
报错的代码如下:
img = Image.open(r'E:\workspace\PyCharmProject\dem_feature\dem\512\label\1.png')
img_array = np.array(img).astype("int32")
print(img_array.shape)
img_array = cv2.resize(img_array,(1024,1024))
print(img_array)
print(img_array.shape)
解决
原因是在将读取的图像转化为numpy array时将其定义为了“int32”型,而cv2.resize函数的参数必须是浮点型的,因此解决如下:
img = Image.open(r'E:\workspace\PyCharmProject\dem_feature\dem\512\label\1.png')
img_array = np.array(img).astype("float")
print(img_array.shape)
img_array = cv2.resize(img_array,(1024,1024))
print(img_array)
print(img_array.shape)
即先将图片数组转换为浮点型,在进行resize处理。
查看打印输出:
边栏推荐
- Detailed explanation of switch link aggregation [Huawei ENSP]
- Implementation of recommendation system collaborative filtering in spark
- 基于JEECG制作一个通用的级联字典选择控件-DictCascadeUniversal
- I want to ask whether DMS has the function of regularly backing up a database?
- Is the securities account opened by qiniu safe? How to open an account
- Vim技巧:永远显示行号
- Seven lines of code made station B crash for three hours, but "a scheming 0"
- [operation and maintenance, implementation of high-quality products] interview skills for technical positions with a monthly salary of 10k+
- 2022 年中回顾 | 大模型技术最新进展 澜舟科技
- Want to go whoring in vain, right? Enough for you this time!
猜你喜欢

“蔚来杯“2022牛客暑期多校训练营2 补题题解(G、J、K、L)

【OpenCV 例程 300篇】239. Harris 角点检测之精确定位(cornerSubPix)

【历史上的今天】7 月 25 日:IBM 获得了第一项专利;Verizon 收购雅虎;亚马逊发布 Fire Phone

AtCoder Beginner Contest 261E // 按位思考 + dp

Alibaba cloud technology expert Qin long: reliability assurance is a must - how to carry out chaos engineering on the cloud?

AtCoder Beginner Contest 261 F // 树状数组

程序员奶爸自制AI喂奶检测仪,预判宝宝饿点,不让哭声影响老婆睡眠

Vim技巧:永远显示行号

基于JEECG制作一个通用的级联字典选择控件-DictCascadeUniversal

Kyligence was selected into Gartner 2022 data management technology maturity curve report
随机推荐
Oran special series-21: major players (equipment manufacturers) and their respective attitudes and areas of expertise
感动中国人物刘盛兰
如何理解Keras中的指标Metrics
Moving Chinese figure liushenglan
Requirements specification template
Business visualization - make your flowchart'run'(3. Branch selection & cross language distributed operation node)
The programmer's father made his own AI breast feeding detector to predict that the baby is hungry and not let the crying affect his wife's sleep
CONDA common commands: install, update, create, activate, close, view, uninstall, delete, clean, rename, change source, problem
yum和vim须掌握的常用操作
Perf performance debugging
我想问DMS有没有定时备份某一个数据库的功能?
Kyligence 入选 Gartner 2022 数据管理技术成熟度曲线报告
【AI4Code】《InferCode: Self-Supervised Learning of Code Representations by Predicting Subtrees》ICSE‘21
Interviewer: "classmate, have you ever done a real landing project?"
【AI4Code】《Contrastive Code Representation Learning》 (EMNLP 2021)
吕蒙正《破窑赋》
需求规格说明书模板
《富兰克林自传》修身
Experimental reproduction of image classification (reasoning only) based on caffe resnet-50 network
MySQL implements inserting data from one table into another table