当前位置: 移动技术网 > IT编程>脚本编程>Python > Python-opencv 双线性插值实例

Python-opencv 双线性插值实例

2020年03月09日  | 移动技术网IT编程  | 我要评论

鬼打鬼之黄金道长,55健康,没有共产党员就没有新中国伴奏

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

#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 双线性插值实例就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持移动技术网。

如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复

相关文章:

验证码:
移动技术网