当前位置:网站首页>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处理。
查看打印输出:
边栏推荐
- Usage of MySQL subquery keywords (exists)
- Micro service remote debug, nocalhost + rainbow micro service development second bullet
- Demon daddy A1 speech listening initial challenge
- How to integrate Google APIs with Google's application system (1) -introduction to Google APIs
- The new version of onespin 360 DV has been released, refreshing the experience of FPGA formal verification function
- 开户必须往账户里面赚钱吗,资金安全吗?
- Awk processing JSON processing
- 现在网上开户安全么?想知道我现在在南宁,到哪里开户比较好?
- Tensorflow2. How to run under x 1 Code of X
- Hdu4876zcc love cards (multi check questions)
猜你喜欢
The new version of onespin 360 DV has been released, refreshing the experience of FPGA formal verification function
How does codesonar help UAVs find software defects?
Jenkins user rights management
Solve the problem of using uni app mediaerror mediaerror errorcode -5
Magic weapon - sensitive file discovery tool
Ten thousand word summary data storage, three knowledge points
SQL injection error report injection function graphic explanation
[200 opencv routines] 223 Polygon fitting for feature extraction (cv.approxpolydp)
Is embedded system really safe? [how does onespin comprehensively solve the IC integrity problem for the development team]
Cantata9.0 | new features
随机推荐
目标:不排斥 yaml 语法。争取快速上手
Use br to recover backup data on azure blob storage
Is it safe to open an account of BOC shares in kainiu in 2022?
MinGW MinGW-w64 TDM-GCC等工具链之间的差别与联系「建议收藏」
Codesonar enhances software reliability through innovative static analysis
Cantata9.0 | new features
神兵利器——敏感文件发现工具
Goal: do not exclude yaml syntax. Try to get started quickly
Implement secondary index with Gaussian redis
object-c编程tips-timer「建议收藏」
Use br to back up tidb cluster data to azure blob storage
Nine degree 1201 - traversal of binary sort number - binary sort tree "suggestions collection"
AADL inspector fault tree safety analysis module
死锁的产生条件和预防处理[通俗易懂]
Backup tidb cluster to persistent volume
Demon daddy A3 stage near normal speed speech flow initial contact
Datatable data conversion to entity
Focusing on safety in 1995, Volvo will focus on safety in the field of intelligent driving and electrification in the future
C语言 整型 和 浮点型 数据在内存中存储详解(内含原码反码补码,大小端存储等详解)
Postgresql数据库character varying和character的区别说明