opencv: cv2.flip 图像翻转 进行 数据增强

Syntax

flip(src, flipCode[, dst])

args

flipCodeAnno
1水平翻转
0垂直翻转
-1水平垂直翻转

Demo

Original Image 原图像:
这里写图片描述

Flipped Horizontally 水平翻转:

Flipped Vertically 垂直翻转:

Flipped Horizontally & Vertically 水平垂直翻转:
这里写图片描述

Code

# 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)

Appendix

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

$ 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.
:
  • 39
    点赞
  • 68
    收藏
    觉得还不错? 一键收藏
  • 12
    评论
评论 12
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值