Python OpenCV学习笔记之:图像几何变换
2016-12-06 00:00
771 查看
摘要: 代码地址:https://github.com/juxiangwu/tensorflow-learning/tree/master/opencv
# -*- coding: utf-8 -*- # 图像几何变换 import cv2 import numpy as np # 大小变换 img = cv2.imread('../../../datas/images/fish.jpg') res = cv2.resize(img,None,fx=2, fy=2, interpolation = cv2.INTER_CUBIC) # 第二种大小变换方法 height, width = img.shape[:2] res = cv2.resize(img,(2*width, 2*height), interpolation = cv2.INTER_CUBIC) # 平移变换 gray = cv2.cvtColor(img,cv2.COLOR_RGB2GRAY) rows,cols = gray.shape M = np.float32([[1,0,100],[0,1,50]]) dst = cv2.warpAffine(gray,M,(cols,rows)) cv2.imshow("image",dst) # 旋转 M = cv2.getRotationMatrix2D((cols/2,rows/2),90,1) dst = dst = cv2.warpAffine(gray,M,(cols,rows)) cv2.imshow("rotate",dst) # 仿射变换 rows,cols,ch = img.shape pts1 = np.float32([[50,50],[200,50],[50,200]]) pts2 = np.float32([[10,100],[200,50],[100,250]]) M = cv2.getAffineTransform(pts1,pts2) dst = cv2.warpAffine(img,M,(cols,rows)) cv2.imshow("image",img) cv2.imshow("affine transform",dst) # 透视变换 pts1 = np.float32([[56,65],[368,52],[28,387],[389,390]]) pts2 = np.float32([[0,0],[300,0],[0,300],[300,300]]) M = cv2.getPerspectiveTransform(pts1,pts2) dst = cv2.warpPerspective(img,M,(300,300)) cv2.imshow("perspective transform",dst) cv2.waitKey() cv2.destroyAllWindows()
相关文章推荐
- Python3+OpenCV学习笔记(二):图像几何变换及补边、裁剪
- Python OpenCV学习笔记之:图像轮廓处理
- Python OpenCV学习笔记之:图像直方图反向投影
- Python OpenCV学习笔记之:图像模板匹配
- Python OpenCV学习笔记之:图像Lucas-Kanad流光算法
- Python下opencv使用笔记(三)(图像的几何变换)
- Python OpenCV学习笔记之:图像梯度处理:Laplacian,Sobel算子
- 【OpenCV学习笔记】十四、图像几何变换
- python3.6.3+opencv3.3.0学习笔记六--存储视频和图像
- Opencv Python版学习笔记(一)图像直方图
- python3.6.3+opencv3.3.0学习笔记三--本地图像显示
- Python OpenCV学习笔记之:图像读取,显示及保存
- OpenCV之Python学习笔记(1)(2): 图像的载入、显示和保存 图像元素的访问、通道分离与合并
- opencv python学习笔记(五)图像的算术与
- Python OpenCV学习笔记之:图像阈值操作
- Python OpenCV学习笔记之:图像直方图均衡化
- Python OpenCV学习笔记之:图像直方图反向投影(backprojection)原理简单实现
- Python OpenCV学习笔记之:计算彩色图像各通道的直方图及图像区域直方图
- Python下opencv使用笔记(三)(图像的几何变换)
- python3.6.3+opencv3.3.0学习笔记四--获取摄像头图像