当前位置:网站首页>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处理。
查看打印输出:
边栏推荐
- sqlHelper的增删改查
- object-c编程tips-timer「建议收藏」
- HDU4876ZCC loves cards(多校题)
- How to meet the dual needs of security and confidentiality of medical devices?
- awk处理JSON处理
- Restore backup data on persistent volumes
- 95年专注安全这一件事 沃尔沃未来聚焦智能驾驶与电气化领域安全
- [matrix multiplication] [noi 2012] [cogs963] random number generator
- Micro service remote debug, nocalhost + rainbow micro service development second bullet
- Use br to back up tidb cluster data to azure blob storage
猜你喜欢
Default constraint and zero fill constraint of MySQL constraint
SQL injection error report injection function graphic explanation
![[200 opencv routines] 223 Polygon fitting for feature extraction (cv.approxpolydp)](/img/1e/055df228853d9b464fc4bcbde0a7ee.png)
[200 opencv routines] 223 Polygon fitting for feature extraction (cv.approxpolydp)

Onespin | solve the problems of hardware Trojan horse and security trust in IC Design

An overview of the latest research progress of "efficient deep segmentation of labels" at Shanghai Jiaotong University, which comprehensively expounds the deep segmentation methods of unsupervised, ro

C语言多角度帮助你深入理解指针(1. 字符指针2. 数组指针和 指针数组 、数组传参和指针传参3. 函数指针4. 函数指针数组5. 指向函数指针数组的指针6. 回调函数)

C语言 整型 和 浮点型 数据在内存中存储详解(内含原码反码补码,大小端存储等详解)

Use camunda to do workflow design and reject operations
Mysql子查询关键字的使用方式(exists)
Codesonar enhances software reliability through innovative static analysis
随机推荐
【矩阵乘】【NOI 2012】【cogs963】随机数生成器
Demon daddy C
Is embedded system really safe? [how does onespin comprehensively solve the IC integrity problem for the development team]
Numerical method for solving optimal control problem (0) -- Definition
I wrote a markdown command line gadget, hoping to improve the efficiency of sending documents by garden friends!
C语言 整型 和 浮点型 数据在内存中存储详解(内含原码反码补码,大小端存储等详解)
Demon daddy A1 speech listening initial challenge
SQL injection error report injection function graphic explanation
Insufficient permissions
Ten thousand word summary data storage, three knowledge points
Cantata9.0 | new features
HDU4876ZCC loves cards(多校题)
MySQL storage expression error
Use br to back up tidb cluster data to azure blob storage
Devil daddy B1 hearing the last barrier, break through with all his strength
A brief understanding of the in arc__ bridge、__ bridge_ Retained and__ bridge_ transfer
Contour layout of margin
awk处理JSON处理
Implement secondary index with Gaussian redis
Intelligent transportation is full of vitality. What will happen in the future? [easy to understand]