opencv图片缩放与镜像
2024-09-06 16:19:11
一个练习的代码,先对图片进行缩放,然后再做镜像:
import cv2
import numpy as np
img = cv2.imread("src.jpg", 1)
cv2.imshow("src",img)
imgInfo = img.shape
height = imgInfo[0]
width = imgInfo[1]
deep = imgInfo[2]
#图片大,镜像后太高屏幕显示不全,这里先缩放
matScale = np.float32([[0.8,0,0], [0,0.8,0]])
scale = cv2.warpAffine(img, matScale, (int(width*0.8), int(height*0.8)))
cv2.imshow("scale", scale)
#重新获取缩放后的图片高与宽
imgInfo = scale.shape
height = imgInfo[0]
width = imgInfo[1]
#镜像的图片信息
newImgInfo = (height * 2, width, deep)
dest = np.zeros(newImgInfo, np.uint8)
#镜像
for i in range(0, height):
for j in range(0, width):
dest[i,j] = scale[i,j]
dest[height*2 - i -1, j] = scale[i, j]
#画一个镜像与原图分割线
for i in range(0, width):
dest[height, i] = (0,0,255)
cv2.imshow("dst", dest)
cv2.waitKey(0)
三张图片效果如下:
最新文章
- DIV+CSS布局网站基本框架
- 2076 Problem F Quick Brown Fox
- asp.net截取指定长度的字符串内容
- 安卓应用运营知识:VersionCode和VersionName
- android ping网络是否成功
- 【转载】干货来袭!Linux小白最佳实践:《超容易的Linux系统管理入门书》(连载七)LAMP集成安装
- 关于Mysql Can't connect to mysql server on localhost(10061)的问题解决
- Ubuntu系列Crontab日记记录
- 转载:struts标签<;s:date>;的使用
- start.sh
- C++ #if #endif #define #ifdef #ifndef #if defined #if !defined详解 (转)
- php的函数参数按照从左到右来赋值
- leetcode — sqrtx
- jquery实现全选 反选 取消
- 洛谷P1044 栈
- 一块移动硬盘怎样兼容Mac和Windows系统,并且可以在time machine上使用
- 转-Asynchronous bulk transfer using libusb
- JS 原型链 prototypt 和隐式原型 _proto_
- JavaScript DOM 元素属性 状态属性
- 在JS数组指定位置插入元素
热门文章
- Flask-Limit使用详细说明
- java 基本语法(十三) 数组(六)数组的常见异常
- 数据可视化实例(三): 散点图(pandas,matplotlib,numpy)
- day5 python代码块,流程控制
- Cyber Security - Palo Alto Security Policies(2)
- Dresdon二次开发
- cmd : 代理设置/检验代理设置成功
- CodeForces - 722C Destroying Array (并查集/集合的插入和删除)
- 解决win10安装flask-mysqldb报错 Python2.7
- C++11 STL Regex正则表达式与字符串字段解析