当前位置:网站首页>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处理。
查看打印输出:
边栏推荐
- clickhouse笔记03-- Grafana 接入ClickHouse
- Implementation of recommendation system collaborative filtering in spark
- Cyberspace Security penetration attack and defense 9 (PKI)
- Intval MD5 bypass [wustctf2020] plain
- CONDA common commands: install, update, create, activate, close, view, uninstall, delete, clean, rename, change source, problem
- Plus SBOM: assembly line BOM pbom
- Cmake learning notes (II) generation and use of Library
- 跌荡的人生
- 如何用因果推断和实验驱动用户增长? | 7月28日TF67
- [fluent -- example] case 1: comprehensive example of basic components and layout components
猜你喜欢

MLX90640 红外热成像仪测温传感器模块开发笔记(五)

【运维、实施精品】月薪10k+的技术岗位面试技巧

Leetcode 1184. distance between bus stops

The larger the convolution kernel, the stronger the performance? An interpretation of replknet model
![[advanced C language] dynamic memory management](/img/b7/6586b35500eb8f39a3ea8c125fb572.png)
[advanced C language] dynamic memory management

Shell常用脚本:获取网卡IP地址
![[300 opencv routines] 239. accurate positioning of Harris corner detection (cornersubpix)](/img/a6/c45a504722f5fd6e3c9fb8e51c6bb5.png)
[300 opencv routines] 239. accurate positioning of Harris corner detection (cornersubpix)

Zero basic learning canoe panel (12) -- progress bar

Atcoder beginer contest 261 f / / tree array

Detailed explanation of flex box
随机推荐
go : gin 自定义日志输出格式
JS sorts according to the attributes of the elements in the array
Can flinkcdc import multiple tables in mongodb database together?
【运维、实施精品】月薪10k+的技术岗位面试技巧
Deployment of Apache website services and implementation of access control
MySQL remote connection permission error 1045 problem
程序员奶爸自制AI喂奶检测仪,预判宝宝饿点,不让哭声影响老婆睡眠
我想问DMS有没有定时备份某一个数据库的功能?
Chapter5 : Deep Learning and Computational Chemistry
Make a general cascade dictionary selection control based on jeecg -dictcascadeuniversal
吕蒙正《破窑赋》
感动中国人物刘盛兰
Oran special series-21: major players (equipment manufacturers) and their respective attitudes and areas of expertise
零基础学习CANoe Panel(12)—— 进度条(Progress Bar)
基于JEECG制作一个通用的级联字典选择控件-DictCascadeUniversal
Zero basic learning canoe panel (15) -- CAPL output view
Mysql 远程连接权限错误1045问题
How to use causal inference and experiments to drive user growth| July 28 tf67
Leetcode 1184. distance between bus stops
Zero basic learning canoe panel (12) -- progress bar