1. 程式人生 > >OpenCV---如何對影象進行雙線性插值運算(7)

OpenCV---如何對影象進行雙線性插值運算(7)

附程式碼如下:

import cv2 as cv
import numpy as np
def resize():
    src = cv.imread("D:/matplotlib/0.jpg")
    cv.imshow("input",src)
    h, w = src.shape[:2]
    print(h,w)
    dst = cv.resize(src,(w//2,h//2),interpolation = cv.INTER_LINEAR)
    cv.imshow("output",dst)
    cv.waitKey(0)
    cv.destroyAllWindows()
resize()

執行結果:

程式碼解釋:

import cv2 as cv
import numpy as np
def resize():
    src = cv.imread("D:/matplotlib/0.jpg")
    #讀取影象
    cv.imshow("input",src)
    #顯示影象
    h, w = src.shape[:2]
    #輸出影象屬性
    print(h,w)
    dst = cv.resize(src,(w//2,h//2),interpolation = cv.INTER_LINEAR)
    #縮小影象並進行雙線性插值計算
    cv.imshow("output",dst)
    #顯示插值後的結果
    cv.waitKey(0)
    cv.destroyAllWindows()
resize()