[OpenCV] Samples 18: Load image and check its attributes
本篇内容:
* 图片读取
* 图片高宽
* 图片ROI
* 图片缩放
- Ref: http://blog.csdn.net/u012005313/article/details/51943442
官网2.3.2参考:Geometric Image Transformations
interpolation - 插值方法。共有5种:
1)INTER_NEAREST - 最近邻插值法
2)INTER_LINEAR - 双线性插值法(默认)
3)INTER_AREA - 基于局部像素的重采样(resampling using pixel area relation)。对于图像抽取(image decimation)来说,这可能是一个更好的方法。但如果是放大图像时,它和最近邻法的效果类似。
4)INTER_CUBIC - 基于4x4像素邻域的3次插值法
5)INTER_LANCZOS4 - 基于8x8像素邻域的Lanczos插值
通过matplotlib.pyplot显示图片,有新意。
import cv2
import matplotlib.pyplot as plt img = cv2.imread('flower.jpg')
# 插值:interpolation
# None本应该是放图像大小的位置的,后面设置了缩放比例,
#所有就不要了
res1 = cv2.resize(img,None,fx=2,fy=2,interpolation=cv2.INTER_CUBIC)
#直接规定缩放大小,这个时候就不需要缩放因子
height,width = img.shape[:2]
res2 = cv2.resize(img,(2*width,2*height),interpolation=cv2.INTER_CUBIC)
plt.subplot(131)
plt.imshow(img)
plt.subplot(132)
plt.imshow(res1)
plt.subplot(133)
plt.imshow(res2)
功能的代码实例:
for name in filteredFiles:
# 1.读取图片
img = cv2.imread(join(dirPath, name))
print("-----------------------")
print("Debug:", name, img.shape)
# 2.(高,长,channel)
rows = img.shape[0]
cols = img.shape[1]
start_row = 0
start_col = 0
if (rows > cols):
# vertical
start_row = (rows - cols) // 2
else:
# horizon
start_col = (cols - rows) // 2
min_edge=min(rows, cols)
# 3.截取局部区域 ROI
imgROI=img[start_row:start_row+min_edge, start_col:start_col+min_edge]
print("Debug:", imgROI.shape)
# cv2.imshow("show", imgROI)
# cv2.waitKey(0)
# 4.缩放
# ref: http://blog.csdn.net/u012005313/article/details/51943442
# ref: http://blog.csdn.net/on2way/article/details/46801063
# 如果想要收缩图像,那么使用重采样差值法效果最好;
# 如果想要放大图像,那么最好使用3次差值法或者线性差值法(文档推荐的).
img_zo = cv2.resize(imgROI, (final_size, final_size), interpolation=cv2.INTER_AREA)
print("Debug:", img_zo.shape)
# cv2.imshow("show", img_zo)
# cv2.waitKey(0)
ret_name = "square_"+name
[OpenCV] Samples 18: Load image and check its attributes的更多相关文章
- [OpenCV] Samples 10: imagelist_creator
yaml写法的简单例子.将 $ ./ 1 2 3 4 5 命令的参数(代表图片地址)写入yaml中. 写yaml文件. 参考:[OpenCV] Samples 06: [ML] logistic re ...
- [OpenCV] Samples 16: Decompose and Analyse RGB channels
物体的颜色特征决定了灰度处理不是万能,对RGB分别处理具有相当的意义. #include <iostream> #include <stdio.h> #include &quo ...
- [OpenCV] Samples 06: [ML] logistic regression
logistic regression,这个算法只能解决简单的线性二分类,在众多的机器学习分类算法中并不出众,但它能被改进为多分类,并换了另外一个名字softmax, 这可是深度学习中响当当的分类算法 ...
- [OpenCV] Samples 06: logistic regression
logistic regression,这个算法只能解决简单的线性二分类,在众多的机器学习分类算法中并不出众,但它能被改进为多分类,并换了另外一个名字softmax, 这可是深度学习中响当当的分类算法 ...
- [OpenCV] Samples 13: opencv_version
cv::CommandLineParser的使用. I suppose CommandLineParser::has("something") should be true whe ...
- [OpenCV] Samples 12: laplace
先模糊再laplace,也可以替换为sobel等. 变换效果后录成视频,挺好玩. #include "opencv2/videoio/videoio.hpp" #include & ...
- [OpenCV] Samples 09: image
根据需求,转化为不同的颜色格式,split后处理各自通道. plImage <==> Mat 格式转换 Mat --> plImage 简单写法: IplImage copy = m ...
- [OpenCV] Samples 03: cout_mat
操作Mat元素时:I.at<double>(1,1) = CV_PI; /* * * cvout_sample just demonstrates the serial out capab ...
- [OpenCV] Samples 02: [ML] kmeans
注意Mat作为kmeans的参数的含义. 扩展:高维向量的聚类. #include "opencv2/highgui.hpp" #include "opencv2/cor ...
随机推荐
- World final 2017 题解
链接:https://pan.baidu.com/s/1kVQc9d9 Problem A: #include <cstdio> #include <algorithm> #i ...
- Qt 4.8.2.+VS2008静态编译
一.下载Qt 4.8.2-opensource. 二.解压到C:\Qt\4.8.2_static 修改C:\Qt\4.8.2_static\projects.pro文件,删除demos,doc,exa ...
- java三大特性--多态(1)
定义 对象具有多种形态 类型 引用的多态: 父类的引用指向自身对象 父类的引用指向子类对象 TrafficTool traffictool=new TrafficTool();//父类的引用指向本身类 ...
- ZooKeeper开发手册中文翻译
本文假设你已经具有一定分布式计算的基础知识.你将在第一部分看到以下内容: ZooKeeper数据模型 ZooKeeper Sessions ZooKeeper Watches 一致性保证(Consis ...
- [Axure RP] – 鼠标滑入按钮时自动下拉表单的设计示例
转:http://blog.qdac.cc/?p=2197 Axure RP 是个好东东呀,大大方便了程序员与客户之间的前期调研时的交流.不过有一些控制并没有鼠标移入和移出的操作,比如 HTML 按钮 ...
- Knockout.Js官网学习(Mapping高级用法二)
使用ignore忽略不需要map的属性 如果在map的时候,你想忽略一些属性,你可以使用ignore累声明需要忽略的属性名称集合: " }; var mapping = { 'ignore' ...
- yolov3源码darknet在vscode下调试
1. 安装配置: https://pjreddie.com/darknet/yolo/ darknet文件夹下make命令搞定: 2. 配置vscode 打开安装好的vscode并安装扩展C/C++( ...
- 解决微信小程序ios端滚动卡顿的问题
方案1:直接使用微信小程序提供的 “scroll-view " 组件. <scroll-view scroll-y style="height: 100%;"> ...
- Revit选择增强插件易蜀预选择过滤器
Revit本身提供的选择过滤器能让我们快速选择到我们需要的图元,而将那些不需要的图元排除在选择集之外,如下图所示,假如我们需要选择全部的风管弯头,那么一种方法,我们可以点选,还有就是框选所有弯头,这样 ...
- 11G新特性 -- flashback data archive(2)
创建Flashback Data Archive用户需要授予dba或flashback archive administer系统特权.flashback archive administer系统特权包 ...