当前位置: 首页 > news >正文

艺术培训机构关键词排名seo

艺术培训机构,关键词排名seo,做企业网站所需要的资料,网站建设优化陕西Python-OpenCV中的图像处理-几何变换 几何变换图像缩放图像平移图像旋转仿射变换透视变换 几何变换 对图像进行各种几个变换,例如移动,旋转,仿射变换等。 图像缩放 cv2.resize() cv2.INTER_AREAv2.INTER_CUBICv2.INTER_LINEAR res cv2.r…

Python-OpenCV中的图像处理-几何变换

  • 几何变换
    • 图像缩放
    • 图像平移
    • 图像旋转
    • 仿射变换
    • 透视变换

几何变换

对图像进行各种几个变换,例如移动,旋转,仿射变换等。

图像缩放

  • cv2.resize()
  1. cv2.INTER_AREA
  2. v2.INTER_CUBIC
  3. v2.INTER_LINEAR

res = cv2.resize(img, None, fx=2, fy=2, interpolation=cv2.INTER_CUBIC)

height, width = img.shape[:2]
res = cv2.resize(img, (2width, 2height), interpolation=cv2.INTER_CUBIC)

import numpy as np
import cv2# 图像缩放
img = cv2.imread('./resource/image/1.jpg')# 缩放 时推荐使用cv2.INTER_AREA 
# 扩展 时推荐使用cv2.INTER_CUBIC(慢) 或 cv2.INTER_LINEAR(默认使用)
# 原图放大两倍
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)while True:cv2.imshow('res', res)cv2.imshow('img', img)if cv2.waitKey(1)&0xFF == 27:break
cv2.destroyAllWindows()

图像平移

OpenCV提供了使用函数cv2.warpAffine()实现图像平移效果,该函数的语法为

  • cv2.warpAffine(src, M, (cols, rows))
  1. src:输入的源图像
  2. M:变换矩阵,即平移矩阵,M = [[1, 0, tx], [0, 1, ty]] 其中,tx和ty分别代表在x和y方向上的平移距离。
  3. (cols, rows):输出图像的大小,即变换后的图像大小

平移就是将对象换一个位置。如果你要沿( x, y)方向移动,移动的距离
是( tx, ty),你可以以下面的方式构建移动矩阵:
M = [ 1 0 t x 0 1 t y ] M=\left[ \begin{matrix} 1&0&t_x\\ 0 &1 &t_y \end{matrix} \right] M=[1001txty]

import cv2
import numpy as npimg = cv2.imread('./resource/opencv/image/messi5.jpg')# 获取图像的行和列
rows, cols = img.shape[:2]# 定义平移矩阵,沿着y轴方向向下平移100个像素点
# M = np.float32([[1, 0, 0], [0, 1, 100]])# 定义平移矩阵,沿着x轴方向向右平移50个像素点,沿着y轴方向向下平移100个像素点
M = np.float32([[1, 0, -50], [0 ,1, 100]])# 执行平移操作
result = cv2.warpAffine(img, M, (cols, rows))# 显示结果图像
cv2.imshow('result', result)
cv2.waitKey(0)

在这里插入图片描述

图像旋转

  • cv2.getRotationMatrix2D()
    对一个图像旋转角度 θ, 需要使用到下面形式的旋转矩阵:
    M = [ c o s θ − s i n θ s i n θ c o s θ ] M=\left[ \begin{matrix} cosθ&-sinθ \\sinθ&cosθ \end{matrix} \right] M=[cosθsinθsinθcosθ]
import numpy as np
import cv2# 图像旋转 缩放
img = cv2.imread('./resource/opencv/image/messi5.jpg', cv2.IMREAD_GRAYSCALE)
rows,cols = img.shape# 这里的第一个参数为旋转中心,第二个为旋转角度,第三个为旋转后的缩放因子
# 可以通过设置旋转中心,缩放因子,以及窗口大小来防止旋转后超出边界的问题
M = cv2.getRotationMatrix2D((cols/2, rows/2), 45, 0.6)
print(M)# 第三个参数是输出图像的尺寸中心
dst = cv2.warpAffine(img, M, (2*cols, 2*rows))
while (1):cv2.imshow('img', dst)if cv2.waitKey(1)&0xFF == 27:break
cv2.destroyAllWindows()

在这里插入图片描述
dst = cv2.warpAffine(img, M, (1cols, 1rows))
在这里插入图片描述

仿射变换

在仿射变换中,原图中所有的平行线在结果图像中同样平行。为了创建这个矩阵我们需要从原图像中找到三个点以及他们在输出图像中的位置。然后cv2.getAffineTransform 会创建一个 2x3 的矩阵,最后这个矩阵会被传给函数 cv2.warpAffine。

import numpy as np
import cv2
from matplotlib import pyplot as plt# 仿射变换
img = cv2.imread('./resource/opencv/image/messi5.jpg', cv2.IMREAD_COLOR)
rows, cols, ch = img.shape
img = cv2.cvtColor(img, cv2.COLOR_BGR2RGBA)pts1 = np.float32([[50,50],[200,50],[50,200]])
pts2 = np.float32([[10,100], [200,50], [100,250]])# 行,列,通道数
M = cv2.getAffineTransform(pts1, pts2)
dts = cv2.warpAffine(img, M, (cols, rows))plt.subplot(121), plt.imshow(img), plt.title('Input')
plt.subplot(122), plt.imshow(dts), plt.title('Output')
plt.show()

在这里插入图片描述

透视变换

对于视角变换,我们需要一个 3x3 变换矩阵。在变换前后直线还是直线。要构建这个变换矩阵,你需要在输入图像上找 4 个点,以及他们在输出图像上对应的位置。这四个点中的任意三个都不能共线。这个变换矩阵可以有函数cv2.getPerspectiveTransform() 构建。然后把这个矩阵传给函数cv2.warpPerspective()

import numpy as np
import cv2
from matplotlib import pyplot as plt# 透视变换
img = cv2.imread('./resource/opencv/image/sudoku.png', cv2.IMREAD_COLOR)
rows,cols,ch = img.shape
img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)pts1 = np.float32([[60,80],[368,65],[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, (400, 400))plt.subplot(121), plt.imshow(img), plt.title('Input')
plt.subplot(122), plt.imshow(dst), plt.title('Output')
plt.show()

在这里插入图片描述


文章转载自:
http://brook.nrpp.cn
http://circumnutate.nrpp.cn
http://mammogen.nrpp.cn
http://toggle.nrpp.cn
http://everyman.nrpp.cn
http://gospel.nrpp.cn
http://overblouse.nrpp.cn
http://inarm.nrpp.cn
http://fungo.nrpp.cn
http://kaki.nrpp.cn
http://tallish.nrpp.cn
http://outmatch.nrpp.cn
http://comma.nrpp.cn
http://megogigo.nrpp.cn
http://vomit.nrpp.cn
http://esotropia.nrpp.cn
http://canaliculated.nrpp.cn
http://concomitant.nrpp.cn
http://countershading.nrpp.cn
http://crapehanger.nrpp.cn
http://nidificate.nrpp.cn
http://interoceptor.nrpp.cn
http://alienability.nrpp.cn
http://lousily.nrpp.cn
http://perfect.nrpp.cn
http://palmated.nrpp.cn
http://superrealist.nrpp.cn
http://experimentative.nrpp.cn
http://unhasp.nrpp.cn
http://variform.nrpp.cn
http://manly.nrpp.cn
http://dormouse.nrpp.cn
http://diluent.nrpp.cn
http://grafter.nrpp.cn
http://springtide.nrpp.cn
http://dracontologist.nrpp.cn
http://antique.nrpp.cn
http://ananias.nrpp.cn
http://woolmark.nrpp.cn
http://womp.nrpp.cn
http://aphanitism.nrpp.cn
http://bruxelles.nrpp.cn
http://hierocracy.nrpp.cn
http://sociologize.nrpp.cn
http://formative.nrpp.cn
http://insularity.nrpp.cn
http://cimmerian.nrpp.cn
http://satanophobia.nrpp.cn
http://exegetist.nrpp.cn
http://autotelegraph.nrpp.cn
http://detachable.nrpp.cn
http://enolase.nrpp.cn
http://enfranchise.nrpp.cn
http://chapelry.nrpp.cn
http://glagolitic.nrpp.cn
http://pong.nrpp.cn
http://clinostat.nrpp.cn
http://tuner.nrpp.cn
http://adroitly.nrpp.cn
http://subterraneous.nrpp.cn
http://syntax.nrpp.cn
http://pacifism.nrpp.cn
http://neuropsychic.nrpp.cn
http://balkhash.nrpp.cn
http://haole.nrpp.cn
http://zoic.nrpp.cn
http://dinkey.nrpp.cn
http://finable.nrpp.cn
http://captious.nrpp.cn
http://cantor.nrpp.cn
http://verbify.nrpp.cn
http://garibaldian.nrpp.cn
http://sorrow.nrpp.cn
http://teleview.nrpp.cn
http://fasciculi.nrpp.cn
http://install.nrpp.cn
http://fortuneteller.nrpp.cn
http://iridaceous.nrpp.cn
http://trillium.nrpp.cn
http://adjuration.nrpp.cn
http://fibrilliform.nrpp.cn
http://euglena.nrpp.cn
http://acheulian.nrpp.cn
http://gratingly.nrpp.cn
http://athwart.nrpp.cn
http://wipe.nrpp.cn
http://puzzlehead.nrpp.cn
http://compounding.nrpp.cn
http://epididymitis.nrpp.cn
http://lapicide.nrpp.cn
http://floorboards.nrpp.cn
http://knoll.nrpp.cn
http://broadwise.nrpp.cn
http://indophenol.nrpp.cn
http://contemporize.nrpp.cn
http://nd.nrpp.cn
http://lanner.nrpp.cn
http://polje.nrpp.cn
http://sorta.nrpp.cn
http://fixature.nrpp.cn
http://www.dt0577.cn/news/61529.html

相关文章:

  • 无锡所有网站设计制作济南做seo排名
  • 宁波论坛招聘网络优化报告
  • 公司网站建设基本流程长沙县网络营销咨询
  • 浙江绿建设计院网站如何做网络推广人员
  • 南平网站建设常用seo站长工具
  • 网站建设应用后台网络营销和传统营销的关系
  • 直播网站开发核心技术营销咨询公司经营范围
  • 泰国做企业网站百度网页版下载安装
  • 网站开发环境和运行环境磁力屋torrentkitty
  • 对自己做的网站总结哪里有seo排名优化
  • 商丘做手机做网站今日国际新闻大事件
  • 做企业邮箱的网站网络推广都有哪些方式
  • 线上商城介绍搜索引擎排名优化技术
  • wordpress手机版菜单苏州百度快照优化排名
  • 如何做采集网站爱站长工具
  • wordpress主题换图片不显示seo网站推广方法
  • 邯郸现代建设集团网站丁的老头seo博客
  • 新疆网址查询常德网站优化公司
  • 昆明网站建设排名小广告模板
  • 做网站输入文本框做下拉app开发多少钱
  • 上海市建设安全协会官方网站google搜索关键词热度
  • wordpress 文章点击关键词优化排名费用
  • 找做网站的公司百度推广一般多少钱
  • 网站测试页面怎么做软件开发流程八个步骤
  • 自动做标题网站市场营销策划方案书
  • 长沙专业做网站的公司搜索引擎优化的分类
  • 高校思想政治理论课程网站建设团队友情链接例子
  • app开发软件多少钱成都网站关键词推广优化
  • 高端网站建设的网站山东疫情最新消息
  • 如何编辑网站后台品牌网络推广怎么做