Python Opencv实践 - 图像缩放

复制代码
import cv2 as cv
import numpy as np
import matplotlib.pyplot as plt

img_cat = cv.imread("../SampleImages/cat.jpg", cv.IMREAD_COLOR)
plt.imshow(img_cat[:,:,::-1])

#图像绝对尺寸缩放
#cv.resize(src, dsize[, dst[, fx[, fy[, interpolation]]]])
#指定Size大小,按照绝对尺寸进行缩放
#interpolation:cv.INTER_LINEAR 双线性插值
#               cv.INTER_NEAREST 最近邻插值
#               cv.INTER_AREA 像素区域重采样(默认)
#               cv.INTER_CUBIC 双三次插值
#参考资料:https://blog.csdn.net/li_l_il/article/details/83218838
rows,cols = img_cat.shape[:2]
print(rows,cols)
img_resize1 = cv.resize(img_cat, ((int)(cols/3),int(rows/2)), interpolation = cv.INTER_CUBIC)
plt.imshow(img_resize1[:,:,::-1])

#图像相对尺寸缩放
#同样使用resize函数,只是把Size设置为None,然后设定fx,fy参数,分别表示x和y的缩放因子
img_resize2 = cv.resize(img_cat, None, fx=0.3, fy=0.7, interpolation = cv.INTER_LINEAR)
plt.imshow(img_resize2[:,:,::-1])
相关推荐
花酒锄作田4 小时前
使用 pkgutil 实现动态插件系统
python
前端付豪7 小时前
LangChain链 写一篇完美推文?用SequencialChain链接不同的组件
人工智能·python·langchain
曲幽8 小时前
FastAPI实战:打造本地文生图接口,ollama+diffusers让AI绘画更听话
python·fastapi·web·cors·diffusers·lcm·ollama·dreamshaper8·txt2img
老赵全栈实战8 小时前
Pydantic配置管理最佳实践(一)
python
阿尔的代码屋14 小时前
[大模型实战 07] 基于 LlamaIndex ReAct 框架手搓全自动博客监控 Agent
人工智能·python
AI探索者1 天前
LangGraph StateGraph 实战:状态机聊天机器人构建指南
python
AI探索者1 天前
LangGraph 入门:构建带记忆功能的天气查询 Agent
python
FishCoderh1 天前
Python自动化办公实战:批量重命名文件,告别手动操作
python
躺平大鹅1 天前
Python函数入门详解(定义+调用+参数)
python
曲幽1 天前
我用FastAPI接ollama大模型,差点被asyncio整崩溃(附对话窗口实战)
python·fastapi·web·async·httpx·asyncio·ollama