前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >cv2.flip

cv2.flip

作者头像
狼啸风云
修改2022-09-03 20:27:04
6400
修改2022-09-03 20:27:04
举报
文章被收录于专栏:计算机视觉理论及其实现

Syntax

代码语言:javascript
复制
flip(src, flipCode[, dst])

args

flipCode

Anno

1

水平翻转

0

垂直翻转

-1

水平垂直翻转

Demo

Original Image

Flipped Horizontally

Flipped Vertically

Flipped Horizontally & Vertically

Code

代码语言:javascript
复制
# encoding:utf-8

import cv2
image = cv2.imread("girl.jpg")

# Flipped Horizontally 水平翻转
h_flip = cv2.flip(image, 1)
cv2.imwrite("girl-h.jpg", h_flip)

# Flipped Vertically 垂直翻转
v_flip = cv2.flip(image, 0)
cv2.imwrite("girl-v.jpg", v_flip)

# Flipped Horizontally & Vertically 水平垂直翻转
hv_flip = cv2.flip(image, -1)
cv2.imwrite("girl-hv.jpg", hv_flip)

也可打开 help 功能 具体查看 接口设置:

代码语言:javascript
复制
$ python
Python 3.6.3 |Anaconda, Inc.| (default, Oct 13 2017, 12:02:49)
[GCC 7.2.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import cv2
>>> help(cv2.flip)


Help on built-in function flip:

flip(...)
    flip(src, flipCode[, dst]) -> dst
    .   @brief Flips a 2D array around vertical, horizontal, or both axes.
    .   
    .   The function cv::flip flips the array in one of three different ways (row
    .   and column indices are 0-based):
    .   \f[\texttt{dst} _{ij} =
    .   \left\{
    .   \begin{array}{l l}
    .   \texttt{src} _{\texttt{src.rows}-i-1,j} & if\;  \texttt{flipCode} = 0 \\
    .   \texttt{src} _{i, \texttt{src.cols} -j-1} & if\;  \texttt{flipCode} > 0 \\
    .   \texttt{src} _{ \texttt{src.rows} -i-1, \texttt{src.cols} -j-1} & if\; \texttt{flipCode} < 0 \\
    .   \end{array}
    .   \right.\f]
    .   The example scenarios of using the function are the following:
    .   *   Vertical flipping of the image (flipCode == 0) to switch between
    .   top-left and bottom-left image origin. This is a typical operation
    .   in video processing on Microsoft Windows\* OS.
本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
原始发表:2019/10/23 ,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档