numpy np tips:使用opencv对数组插值放缩到固定形状 cv2.resize(res, dsize=(64, 64), interpolation=cv2.INTER_CUBIC)

res = cv2.resize(res, dsize=(64, 64), interpolation=cv2.INTER_CUBIC)

numpy np tips:使用opencv对数组插值放缩到固定形状 cv2.resize(res, dsize=(64, 64), interpolation=cv2.INTER_CUBIC)_第1张图片

  • 注意放缩的效果,即矩阵的形状是与参数相反的
import cv2
 
src = cv2.imread('D:/cv2-resize-image-original.png', cv2.IMREAD_UNCHANGED)

#percent by which the image is resized
scale_percent = 50

#calculate the 50 percent of original dimensions
width = int(src.shape[1] * scale_percent / 100)
height = int(src.shape[0] * scale_percent / 100)

# dsize
dsize = (width, height)

# resize image
output = cv2.resize(src, dsize)

cv2.imwrite('D:/cv2-resize-image-50.png',output) 

cv2.error: OpenCV(4.5.2) resize.cpp:4051: error: (-215:Assertion failed) !ssize.empty() in function ‘cv::resize’

原因: None- 空图像 - 显示 ssize.empty()
# 我的是数组维度[1,1,h,w] 用a = np.squeeze(a) https://blog.csdn.net/ResumeProject/article/details/125446333

参考与更多

https://stackoverflow.com/questions/67737650/cv2-error-opencv4-5-2-resize-cpp4051-error-215assertion-failed-ssize
https://www.w3bai.com/en-US/jquery/jquery_dimensions.html
https://pythonexamples.org/python-opencv-cv2-resize-image/

你可能感兴趣的:(语言学习笔记,python)