裁剪:
# 图像裁剪
# 利用python切片获取长宽信息
h, w = Img.shape[:2]
l, t = int(w/4), int(h/4)
r, b = int(w*3/4), int(h*3/4)
cropped = Img[t:b, l:r]
cv.imshow('cropped', cropped)
cv.waitKey(0)
获取图片长宽信息,计算出想要的图片长宽间距
缩放:
# 图像缩放
scaled = cv.resize(Img, (int(w/4), int(h/4)))
cv.imshow('scaled', scaled)
cv.waitKey(0)
scaled2 = cv.resize(scaled, (w, h), interpolation=cv.INTER_LINEAR)
cv.imshow('scaled2', scaled2)
cv.waitKey(0)
关于cv.resize函数:
resize(img, (w, h))中w表示宽度,h表示高度。
详细的函数介绍在这个链接里有:https://blog.csdn.net/m0_46653437/article/details/113196992?ops_request_misc=%257B%2522request%255Fid%2522%253A%2522162659547816780264020734%2522%252C%2522scm%2522%253A%252220140713.130102334.pc%255Fall.%2522%257D&request_id=162659547816780264020734&biz_id=0&utm_medium=distribute.pc_search_result.none-task-blog-2~all~first_rank_v2~rank_v29-2-113196992.pc_search_result_cache&utm_term=scaled+%3D+cv.resize%28Img%2C+%28int%28w%2F4%29%2C+int%28h%2F4%29%29%2C+interpolation%3Dcv.INTER_LINEAR%29&spm=1018.2226.3001.4187
代码来源:https://blog.csdn.net/weixin_45081640/article/details/118147714