OpenCV Image Flip 图像翻转

需要使用到OpenCV的图像翻转操作,查了一些flip函数的文档,发现非常confusing,不明白到底0是水平翻转还是1是水平翻转。
最后不得已自己实验才弄清楚。

OpenCV 图像坐标系

在OpenCV里面,坐标系的原点在左上角,row为Y轴,col为X轴。从左上角往下,Y变大,往右,X变大。
这和python里面很多其他的图像处理库不一样,比如PIL和skimage,这些库是python原生态的,是以行列坐标为XY坐标的,也就是从左上角往下,X变大,往右,Y变大。
由此可见,OpenCV和PIL(以及skimage)的xy坐标是反的,这是需要注意的。

Flip

// C++:

void cv::flip(InputArray src, OutputArray dst, int flipCode )

# Python:

dst = cv.flip(src, flipCode[, dst])

Parameters

src input array.
dst output array of the same size and type as src.
flipCode a flag to specify how to flip the array; 0 means flipping around the x-axis and positive value (for example, 1) means flipping around y-axis. Negative value (for example, -1) means flipping around both axes.

从这段描述来看,0代表上下翻转(aroud X-axis),1 代表左右翻转(around Y-axis)

你可能感兴趣的:(computer-vision,python)