当前位置:网站首页>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-07 21:33: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处理。
查看打印输出:
边栏推荐
- Insufficient permissions
- How much does it cost to develop a small program mall?
- Helix QAC 2020.2 new static test tool maximizes the coverage of standard compliance
- Implementation of mahout Pearson correlation
- 数值法求解最优控制问题(〇)——定义
- Addition, deletion, modification and query of sqlhelper
- Ten thousand word summary data storage, three knowledge points
- sqlHelper的增删改查
- 开户还得用身份证银行卡安全吗,我是小白不懂
- Datatable data conversion to entity
猜你喜欢
The little money made by the program ape is a P!
Jenkins user rights management
Onespin | solve the problems of hardware Trojan horse and security trust in IC Design
How does codesonar help UAVs find software defects?
Cantata9.0 | new features
The latest version of codesonar has improved functional security and supports Misra, c++ parsing and visualization
Using enumeration to realize English to braille
SQL注入报错注入函数图文详解
Use camunda to do workflow design and reject operations
Intelligent software analysis platform embold
随机推荐
openGl超级宝典学习笔记 (1)第一个三角形「建议收藏」
Nine degree 1201 - traversal of binary sort number - binary sort tree "suggestions collection"
UVA 12230 – crossing rivers (probability) "suggested collection"
Numerical method for solving optimal control problem (0) -- Definition
Codesonar enhances software reliability through innovative static analysis
Hdu4876zcc love cards (multi check questions)
POJ 3140 Contestants Division「建议收藏」
How to meet the dual needs of security and confidentiality of medical devices?
Demon daddy B3 read extensively in a small amount, and completed 20000 vocabulary+
Demon daddy B2 breaks through grammar and completes orthodox oral practice
Postgresql数据库character varying和character的区别说明
Tensorflow2. How to run under x 1 Code of X
Use br to back up tidb cluster data to azure blob storage
Use br to recover backup data on azure blob storage
Develop those things: go plus c.free to free memory, and what are the reasons for compilation errors?
Can Huatai Securities achieve Commission in case of any accident? Is it safe to open an account
Ubuntu安装mysql8遇到的问题以及详细安装过程
Take the intersection of two sets
使用高斯Redis实现二级索引
Demon daddy C