当前位置:网站首页>Cv2.resize function reports an error: error: (-215:assertion failed) func= 0 in function ‘cv::hal::resize‘

Cv2.resize function reports an error: error: (-215:assertion failed) func= 0 in function ‘cv::hal::resize‘

2022-07-07 21:37:00 1 + 1= Wang

Report errors

In the use of cv2.resize() The following error was encountered when resizing the picture .

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’

Error code

The error code is as follows :

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)

solve

The reason is that the read image is converted into numpy array It is defined as “int32” type , and cv2.resize Function parameters must be floating point , Therefore, the solution is as follows :

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)

That is, first convert the image array to floating point , It's going on resize Handle .

View printouts :
 Insert picture description here

原网站

版权声明
本文为[1 + 1= Wang]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/188/202207071844258969.html