·cv::flip()函数将图像绕着x轴或者y轴或者同时绕x轴和y轴翻转。函数原型:
void cv::flip(
cv::InputArray src, // input array
cv::OutputArray dst, // result array size and type of src
int flipCode = 0 // >0:y-flip, 0:x-flip, <0:both
);
默认情况下flipCode=0,表示图像绕x轴翻转。如果flipCode >0 表示图像绕y轴翻转;如果flipCode <0,表示图像绕x轴和y轴同时翻转。
win32系统上进行视频处理时可能用到该函数进行图像格式变换,即坐标原点在左上角和左下角的变换。
使用示例
std::string strFilename = "Test.bmp";
cv::Mat img = cv::imread(strFilename);
cv::namedWindow(strFilename, cv::WINDOW_NORMAL);
cv::imshow(strFilename, img);
cv::waitKey(0);
cv::Mat dst;
cv::flip(img, dst, 0); // 绕x翻转,上下颠倒
cv::imshow(strFilename, dst);
cv::waitKey(0);
cv::flip(img, dst, 1); // 绕y轴翻转,左右颠倒
cv::imshow(strFilename, dst);
cv::waitKey(0);
cv::flip(img, dst, -1); // 同时绕x和y翻转,上下左右都颠倒
cv::imshow(strFilename, dst);
cv::waitKey(0);
显示结果:

?  
?
?
?
?
|