Python-opencv 双线性插值实例

yipeiwu_com5年前Python基础

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

#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 双线性插值实例就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持【听图阁-专注于Python设计】。

相关文章

django-rest-swagger的优化使用方法

如下所示: requirements.txt django==1.10.5 djangorestframework==3.5.3 django-rest-swagger==2.1...

python统计cpu利用率的方法

本文实例讲述了python统计cpu利用率的方法。分享给大家供大家参考。具体实现方法如下: #-*-coding=utf-8-*- import win32pdh import ti...

实例讲解python中的序列化知识点

在程序运行的过程中,所有的变量都是在内存中,比如,定义一个dict: d = dict(name='Bob', age=20, score=88) 可以随时修改变量,比如把name...

pygame实现成语填空游戏

pygame实现成语填空游戏

最近看到很多人玩成语填字游戏,那么先用pygame来做一个吧,花了大半天终于完成了,附下效果图。 偷了下懒程序没有拆分,所有程序写在一个文件里,主要代码如下: # -*- codi...

python判断设备是否联网的方法

本文实例为大家分享了python判断设备是否联网的具体代码,供大家参考,具体内容如下 直接上代码,就是用判断socket能不连上的方法来判断。 #!/usr/bin/env pyth...