1. 程式人生 > >OpenCV---如何輸出映象影象(5)

OpenCV---如何輸出映象影象(5)

附程式碼如下:

import cv2 as cv
import numpy as np
def mirror():
    src = cv.imread("D:/matplotlib/0.jpg")
    cv.imshow("q",src)
    h,w,ch = np.shape(src)
    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("output",dst)
    cv.waitKey(0)
    cv.destroyAllWindows()
mirror()

執行效果:

程式碼解釋:

import cv2 as cv
import numpy as np
def mirror():
    src = cv.imread("D:/matplotlib/0.jpg")
    cv.imshow("q",src)
    h,w,ch = np.shape(src)
    #顯示影象的屬性
    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("output",dst)
    #output
    cv.waitKey(0)
    cv.destroyAllWindows()
mirror()