当前位置:网站首页>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处理。
查看打印输出:
边栏推荐
- [function recursion] do you know all five classic examples of simple recursion?
- UVA 11080 – Place the Guards(二分图判定)
- margin 等高布局
- Mahout-Pearson correlation的实现
- Deployment, recall and deletion solutions - stsadm and PowerShell "suggestions collection"
- 刚开户的能买什么股票呢?炒股账户安全吗
- [matrix multiplication] [noi 2012] [cogs963] random number generator
- 反诈困境,国有大行如何破局?
- Static analysis of software defects codesonar 5.2 release
- Helix QAC 2020.2 new static test tool maximizes the coverage of standard compliance
猜你喜欢
![[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)

The new version of onespin 360 DV has been released, refreshing the experience of FPGA formal verification function

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

Jenkins user rights management

Problems encountered in installing mysql8 for Ubuntu and the detailed installation process

Details of C language integer and floating-point data storage in memory (including details of original code, inverse code, complement, size end storage, etc.)

使用枚举实现英文转盲文

Focusing on safety in 1995, Volvo will focus on safety in the field of intelligent driving and electrification in the future

How to meet the dual needs of security and confidentiality of medical devices?

恶魔奶爸 B3 少量泛读,完成两万词汇量+
随机推荐
国家正规的股票交易app有哪些?使用安不安全
EasyUI date control emptying value
UVA 11080 – place the guards
Onespin | solve the problems of hardware Trojan horse and security trust in IC Design
What stocks can a new account holder buy? Is the stock trading account safe
The new version of onespin 360 DV has been released, refreshing the experience of FPGA formal verification function
Insufficient permissions
Is embedded system really safe? [how does onespin comprehensively solve the IC integrity problem for the development team]
反诈困境,国有大行如何破局?
单词反转实现「建议收藏」
How to integrate Google APIs with Google's application system (1) -introduction to Google APIs
The little money made by the program ape is a P!
UVA 11080 – Place the Guards(二分图判定)
How does codesonar help UAVs find software defects?
Ten thousand word summary data storage, three knowledge points
Is it safe to open an account of BOC shares in kainiu in 2022?
解决使用uni-app MediaError MediaError ErrorCode -5
Code of "digital image processing principle and Practice (matlab version)" part2[easy to understand]
Intelligent software analysis platform embold
sqlHelper的增删改查