opencv图像旋转和翻转,cv2.flip,cv2.rotate
opencv
OpenCV: 开源计算机视觉库
项目地址:https://gitcode.com/gh_mirrors/opencv31/opencv
免费下载资源
·
目录
翻转图像
opencv中使用cv2.filp可以实现图像翻转
def flip(src, flipCode, dst=None)
- src:输入图像
- flipCode:flipCode 一个标志来指定如何翻转数组;0表示上下翻转,正数表示左右翻转,负数表示上下左右都翻转。
- dst:输出图像
下面代码对图像进行不同旋转。
import cv2
import numpy as np
lp = cv2.resize(cv2.imread('../images/lp.jpg'), None, fx=0.7, fy=0.7)
# 翻转 0表示上下,正数表示左右,负数表示上下左右都翻转
new_lp1 = cv2.flip(lp, 0)
new_lp2 = cv2.flip(lp, 1)
new_lp3 = cv2.flip(lp, -1)
cv2.imshow('lp', np.hstack((lp, new_lp1, new_lp2, new_lp3)))
cv2.waitKey(0)
cv2.destroyAllWindows()
图像旋转
opencv中使用cv2.rotate进行图像旋转
def rotate(src, rotateCode, dst=None)
- src:输入图像
- rotateCode:翻转角度,3种选择,90度,180度,270度
- dst:输出图像
对于rotateCode的选择如下
参数 | 描述 |
---|---|
ROTATE_90_CLOCKWISE | 顺时针旋转90度 |
ROTATE_180 | 旋转180度 |
ROTATE_90_COUNTERCLOCKWISE | 逆时针旋转90度,也就是顺时针旋转270度 |
下面代码对3个参数进行使用
import cv2
lp = cv2.resize(cv2.imread('../images/lp.jpg'), None, fx=0.7, fy=0.7)
# 平移 3种旋转,使用cv2.ROTATE_xxx进行选择
lp1 = cv2.rotate(lp, cv2.ROTATE_90_CLOCKWISE)
lp2 = cv2.rotate(lp, cv2.ROTATE_90_COUNTERCLOCKWISE)
lp3 = cv2.rotate(lp, cv2.ROTATE_180)
cv2.imshow('lp', lp)
cv2.imshow('lp1', lp1)
cv2.imshow('lp2', lp2)
cv2.imshow('lp3', lp3)
cv2.waitKey(0)
cv2.destroyAllWindows()
GitHub 加速计划 / opencv31 / opencv
166
15
下载
OpenCV: 开源计算机视觉库
最近提交(Master分支:4 个月前 )
c623a5af
Android camera refactoring #26646
This patch set does not contain any functional changes. It just cleans up the code structure to improve readability and to prepare for future changes.
* videoio(Android): Use 'unique_ptr' instead of 'shared_ptr'
Using shared pointers for unshared data is considered an antipattern.
* videoio(Android): Make callback functions private static members
Don't leak internal functions into global namespace. Some member
variables are now private as well.
* videoio(Android): Move resolution matching into separate function
Also make internally used member functions private.
* videoio(Android): Move ranges query into separate function
Also remove some unneccessary initialisations from initCapture().
* videoio(Android): Wrap extremly long source code lines
* videoio(Android): Rename members of 'RangeValue'
### 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
11 小时前
7728dd33
Fix potential READ memory access #26782
This fixes https://oss-fuzz.com/testcase-detail/4923671881252864 and https://oss-fuzz.com/testcase-detail/5048650127966208
### 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
- [x] The PR is proposed to the proper branch
- [x] 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
13 小时前
更多推荐
已为社区贡献14条内容
所有评论(0)