python-opencv-cv2.resize()函数详解
opencv
OpenCV: 开源计算机视觉库
项目地址:https://gitcode.com/gh_mirrors/opencv31/opencv
·
1.cv2.resize()参数说明?
cv2.resize(src, dsize, dst=None, fx=None, fy=None, interpolation=None)
| 参数 | 描述 |
|---|---|
| src | 【必需】输入原图像 |
| dsize | 【必需】输出图像的大小 |
| fx | 【可选】width方向的缩放比例 |
| fy | 【可选】height方向的缩放比例 |
| interpolation(插值) | 【可选】这个是指定插值的方式 |
dsize形参的数组的宽度在前,高度在后(output_width,output_height)
图像缩放之后,肯定像素要进行重新计算的,就靠这个参数来指定重新计算像素的方式,有以下几种:
INTER_NEAREST - 最邻近插值
INTER_LINEAR - 双线性插值,如果最后一个参数你不指定,默认使用这种方法
INTER_CUBIC - 4x4像素邻域内的双立方插值
INTER_LANCZOS4 - 8x8像素邻域内的Lanczos插值
2.代码示例
import cv2
img = cv2.imread('图片所在路径')
# 默认使用双线性插值法
img = cv2.resize(img,(300,300))#固定长宽
img = cv2.resize(img,None,fx=0.5,fy=0.5)#固定比例
cv.imshow("img",img)
cv.waitKey(0)
cv.destroyAllWindows()
3.最近邻插值与双线性插值
数值分析学习插值没想到这里还用上了,如果有小伙伴想了解图像处理: 五种 插值法,可以参看则篇博文。
OpenCV: 开源计算机视觉库
最近提交(Master分支:3 个月前 )
2a29d87e
Fix null pointer dereference in G-API stateful kernels 8 小时前
c0373447
Introduce option to generate Java code with finalize() or Cleaners interface #28159
Closes https://github.com/opencv/opencv/issues/22260
Replaces https://github.com/opencv/opencv/pull/23467
The PR introduce configuration option to generate Java code with Cleaner interface for Java 9+ and old-fashion finalize() method for old Java and Android. Mat class and derivatives are manually written. The PR introduce 2 base classes for it depending on the generator configuration.
Pros:
1. No need to implement complex and error prone cleaner on library side.
2. No new CMake templates, easier to modify code in IDE.
Cons:
1. More generator branches and different code for modern desktop and Android.
TODO:
- [x] Add Java version check to cmake
- [x] Use Cleaners for ANDROID API 33+
### Pull Request Readiness Checklist
See details at https://github.com/opencv/opencv/wiki/How_to_contribute#making-a-good-pull-request
- [x] I agree to contribute to the project under Apache 2 License.
- [x] To the best of my knowledge, the proposed patch is not based on a code under GPL or another license that is incompatible with OpenCV
- [ ] The PR is proposed to the proper branch
- [ ] There is a reference to the original bug report and related work
- [ ] There is accuracy test, performance test and test data in opencv_extra repository, if applicable
Patch to opencv_extra has the same branch name.
- [ ] The feature is well documented and sample code can be built with the project CMake
9 小时前
AtomGit 是由开放原子开源基金会联合 CSDN 等生态伙伴共同推出的新一代开源与人工智能协作平台。平台坚持“开放、中立、公益”的理念,把代码托管、模型共享、数据集托管、智能体开发体验和算力服务整合在一起,为开发者提供从开发、训练到部署的一站式体验。
更多推荐


所有评论(0)