用户登录
用户注册

分享至

Python-opencv 双线性插值实例

  • 作者: 对面疾风啊
  • 来源: 51数据库
  • 2020-08-11
今天小编就为大家分享一篇Python-opencv 双线性插值实例,具有很好的参考价值,希望对大家有所帮助。一起跟随小编过来看看吧

我就废话不多说了,直接上代码吧!

#coding=utf-8
import cv2
import numpy as np
'''双线性插值'''
img = cv2.imread('timg.jpeg', cv2.CV_LOAD_IMAGE_GRAYSCALE) # load the gray image
cv2.imwrite('img.jpg', img)
h, w = img.shape[:2]

# shrink to half of the original
a1 = np.array([[0.5, 0, 0], [0, 0.5, 0]], np.float32)
d1 = cv2.warpAffine(img, a1, (w, h), borderValue=125)

# shrink to half of the original and move
a2 = np.array([[0.5, 0, w /4], [0, 0.5, h / 4]], np.float32)
d2 = cv2.warpAffine(img, a2, (w, h),flags=cv2.INTER_NEAREST,borderValue=125)
# rotate based on d2
a3 = cv2.getRotationMatrix2D((w / 2, h / 2), 90, 1)
d3 = cv2.warpAffine(d2, a3, (w, h),flags=cv2.INTER_LINEAR, borderValue=125)

cv2.imshow('img',img)
cv2.imshow('d1',d1)
cv2.imshow('d2',d2)
cv2.imshow('d3',d3)
cv2.waitKey(0)
cv2.destroyAllWindows()

以上这篇Python-opencv 双线性插值实例就是小编分享给大家的全部内容了,希望能给大家一个参考,

软件
前端设计
程序设计
Java相关