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设计】。

相关文章

python在Windows下安装setuptools(easy_install工具)步骤详解

python在Windows下安装setuptools(easy_install工具)步骤详解

本文讲述了python在Windows下安装setuptools(easy_install工具)的方法。分享给大家供大家参考,具体如下: 【题外话介绍下setuptools】 setup...

python+selenium select下拉选择框定位处理方法

一、前言 总结一下python+selenium select下拉选择框定位处理的两种方式,以备后续使用时查询; 二、直接定位(XPath) 使用Firebug找到需要定位到的元素,直接...

python 实现让字典的value 成为列表

如果想让字典的VALUE成为字典,只有最开始让其成为列表,如下面程序中的b >>> b={} >>> b={1:['sdad']} >>...

python 图片二值化处理(处理后为纯黑白的图片)

python 图片二值化处理(处理后为纯黑白的图片)

先随便招一张图片test.jpg做案例 然后对图片进行处理 # 图片二值化 from PIL import Image img = Image.open('test.jpg')...

python实现向微信用户发送每日一句 python实现微信聊天机器人

分享几个Python针对微信的小工具,供大家参考,具体内容如下 用Python实现向微信用户发送每日一句 # -*- coding:utf-8 -*- from __future__...