search
尋找貓咪~QQ 地點 桃園市桃園區 Taoyuan , Taoyuan

fanfuhan OpenCV 教學013 ~ OpenCV的-013圖片翻轉(顛倒/轉向/旋轉) – jashliao部落格

fanfuhan OpenCV 教學013 ~ OpenCV的-013圖片翻轉(顛倒/轉向/旋轉)

資料來源: https://fanfuhan.github.io/

https://fanfuhan.github.io/2019/03/27/opencv-013/

GITHUB:https://github.com/jash-git/fanfuhan_ML_OpenCV


X軸翻轉,flipcode = 0
Y軸翻轉, flipcode = 1

XY軸翻轉, flipcode = -1


C++

#include 
#include 

using namespace std;
using namespace cv;

/*
 * 图像翻转
 */
int main() {
    Mat src = imread("../images/test.png");
    if (src.empty()) {
        cout << "could not load image.." << endl;
    }
    imshow("input", src);

    Mat dst;
    // X轴 倒影
    flip(src, dst, 0);
    imshow("x_flip", dst);

    // Y轴 镜像
    flip(src, dst, 1);
    imshow("y_flip", dst);

    // XY轴 对角
    flip(src, dst, -1);
    imshow("xy_flip", dst);

    waitKey(0);
    return 0;
}

Python

import cv2 as cv
import numpy as np

src = cv.imread("D:/vcprojects/images/test.png")
cv.namedWindow("input", cv.WINDOW_AUTOSIZE)
cv.imshow("input", src)

# X Flip 倒影
dst1 = cv.flip(src, 0);
cv.imshow("x-flip", dst1);

# Y Flip 镜像
dst2 = cv.flip(src, 1);
cv.imshow("y-flip", dst2);

# XY Flip 对角
dst3 = cv.flip(src, -1);
cv.imshow("xy-flip", dst3);

# custom y-flip
h, w, ch = src.shape
dst = np.zeros(src.shape, src.dtype)
for row in range(h):
    for col in range(w):
        b, g, r = src[row, col]
        dst[row, w - col - 1] = [b, g, r]
cv.imshow("custom-y-flip", dst)

cv.waitKey(0)
cv.destroyAllWindows()



熱門推薦

本文由 jashliaoeuwordpress 提供 原文連結

寵物協尋 相信 終究能找到回家的路
寫了7763篇文章,獲得2次喜歡
留言回覆
回覆
精彩推薦