青青草原综合久久大伊人导航_色综合久久天天综合_日日噜噜夜夜狠狠久久丁香五月_热久久这里只有精品

Geometric Transformations of Images

https://docs.opencv.org/3.0-beta/doc/py_tutorials/py_imgproc/py_geometric_transformations/py_geometric_transformations.html

Goals

  • Learn to apply different geometric transformation to images like translation, rotation, affine transformation etc.
  • You will see these functions: cv2.getPerspectiveTransform

Transformations

OpenCV provides two transformation functions, cv2.warpAffine and cv2.warpPerspective, with which you can have all kinds of transformations. cv2.warpAffine takes a 2x3 transformation matrix while cv2.warpPerspective takes a 3x3 transformation matrix as input.

Scaling

Scaling is just resizing of the image. OpenCV comes with a function cv2.resize() for this purpose. The size of the image can be specified manually, or you can specify the scaling factor. Different interpolation methods are used. Preferable interpolation methods are cv2.INTER_AREA for shrinking and cv2.INTER_CUBIC (slow) & cv2.INTER_LINEAR for zooming. By default, interpolation method used is cv2.INTER_LINEAR for all resizing purposes. You can resize an input image either of following methods:

import cv2 import numpy as np  img = cv2.imread('messi5.jpg')  res = cv2.resize(img,None,fx=2, fy=2, interpolation = cv2.INTER_CUBIC)  #OR  height, width = img.shape[:2] res = cv2.resize(img,(2*width, 2*height), interpolation = cv2.INTER_CUBIC) 

Translation

Translation is the shifting of object’s location. If you know the shift in (x,y) direction, let it be (t_x,t_y), you can create the transformation matrix \textbf{M} as follows:

M = \begin{bmatrix} 1 & 0 & t_x \\ 0 & 1 & t_y  \end{bmatrix}

You can take make it into a Numpy array of type np.float32 and pass it into cv2.warpAffine() function. See below example for a shift of (100,50):

import cv2 import numpy as np  img = cv2.imread('messi5.jpg',0) rows,cols = img.shape  M = np.float32([[1,0,100],[0,1,50]]) dst = cv2.warpAffine(img,M,(cols,rows))  cv2.imshow('img',dst) cv2.waitKey(0) cv2.destroyAllWindows() 

Warning

 

Third argument of the cv2.warpAffine() function is the size of the output image, which should be in the form of (width, height). Remember width = number of columns, and height = number of rows.

See the result below:

Translation

Rotation

Rotation of an image for an angle \theta is achieved by the transformation matrix of the form

M = \begin{bmatrix} cos\theta & -sin\theta \\ sin\theta & cos\theta   \end{bmatrix}

But OpenCV provides scaled rotation with adjustable center of rotation so that you can rotate at any location you prefer. Modified transformation matrix is given by

\begin{bmatrix} \alpha &  \beta & (1- \alpha )  \cdot center.x -  \beta \cdot center.y \\ - \beta &  \alpha &  \beta \cdot center.x + (1- \alpha )  \cdot center.y \end{bmatrix}

where:

\begin{array}{l} \alpha =  scale \cdot \cos \theta , \\ \beta =  scale \cdot \sin \theta \end{array}

To find this transformation matrix, OpenCV provides a function, cv2.getRotationMatrix2D. Check below example which rotates the image by 90 degree with respect to center without any scaling.

img = cv2.imread('messi5.jpg',0) rows,cols = img.shape  M = cv2.getRotationMatrix2D((cols/2,rows/2),90,1) dst = cv2.warpAffine(img,M,(cols,rows)) 

See the result:

Rotation of Image

Affine Transformation

In affine transformation, all parallel lines in the original image will still be parallel in the output image. To find the transformation matrix, we need three points from input image and their corresponding locations in output image. Then cv2.getAffineTransform will create a 2x3 matrix which is to be passed to cv2.warpAffine.

Check below example, and also look at the points I selected (which are marked in Green color):

img = cv2.imread('drawing.png') 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))  plt.subplot(121),plt.imshow(img),plt.title('Input') plt.subplot(122),plt.imshow(dst),plt.title('Output') plt.show() 

See the result:

Affine Transformation

Perspective Transformation

For perspective transformation, you need a 3x3 transformation matrix. Straight lines will remain straight even after the transformation. To find this transformation matrix, you need 4 points on the input image and corresponding points on the output image. Among these 4 points, 3 of them should not be collinear. Then transformation matrix can be found by the function cv2.getPerspectiveTransform. Then apply cv2.warpPerspective with this 3x3 transformation matrix.

See the code below:

img = cv2.imread('sudokusmall.png') rows,cols,ch = img.shape  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))  plt.subplot(121),plt.imshow(img),plt.title('Input') plt.subplot(122),plt.imshow(dst),plt.title('Output') plt.show() 

Result:

Perspective Transformation

Additional Resources

  1. “Computer Vision: Algorithms and Applications”, Richard Szeliski

Exercises

Help and Feedback

You did not find what you were looking for?
  • Ask a question on the Q&A forum.
  • If you think something is missing or wrong in the documentation, please file a bug report.

posted on 2017-10-12 15:28 zmj 閱讀(759) 評論(0)  編輯 收藏 引用

青青草原综合久久大伊人导航_色综合久久天天综合_日日噜噜夜夜狠狠久久丁香五月_热久久这里只有精品
  • <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>
            亚洲精品日韩在线观看| 亚洲小说春色综合另类电影| 尤物在线精品| 久久久久久久久久久久久久一区| 激情欧美丁香| 国产精品久久久一区麻豆最新章节| 狼人社综合社区| 久久精品免费观看| 久久综合九九| 久久福利电影| 久久久亚洲综合| 久久人人97超碰精品888| 久久久久欧美精品| 亚洲高清在线观看| 欧美成在线观看| 欧美xx视频| 欧美777四色影视在线| 亚洲日韩成人| 香蕉免费一区二区三区在线观看| 久久蜜臀精品av| 免费91麻豆精品国产自产在线观看| 男男成人高潮片免费网站| 欧美日韩在线一二三| 国产午夜精品全部视频播放| 最新国产拍偷乱拍精品 | 国产精品任我爽爆在线播放| 国产精品久久毛片a| 好吊色欧美一区二区三区视频| 亚洲欧洲一区二区天堂久久 | 久久久无码精品亚洲日韩按摩| 噜噜噜91成人网| 99在线精品观看| 久久这里只有精品视频首页| 国产精品私房写真福利视频 | 欧美日本网站| 狠狠色丁香婷婷综合| 亚洲一区日韩| 免费一级欧美片在线播放| 亚洲精品美女在线| 久久亚洲综合网| 国产精品一区二区久激情瑜伽| 黄色一区二区在线观看| 亚洲无线一线二线三线区别av| 麻豆九一精品爱看视频在线观看免费| 亚洲欧洲在线播放| 美国成人直播| 国产一区二区三区精品欧美日韩一区二区三区 | 国内成+人亚洲| 久久人人精品| 亚洲综合99| 欧美理论在线| 亚洲国产日韩欧美在线99 | 亚洲免费网站| 欧美.日韩.国产.一区.二区| 西瓜成人精品人成网站| 欧美另类高清视频在线| 一区二区三区在线看| 久久久久中文| 欧美一区二区三区在线看| 欧美日韩三级在线| 一区免费在线| 久久亚洲欧美国产精品乐播| 欧美一区二区成人| 国产一区高清视频| 久热精品在线视频| 久久精品91久久久久久再现| 国产一区二区三区成人欧美日韩在线观看 | 亚洲免费在线精品一区| 欧美系列亚洲系列| 亚洲欧美日本日韩| 午夜精品视频在线观看一区二区| 国产欧美精品在线| 裸体一区二区| 欧美成va人片在线观看| 一本色道久久综合亚洲精品高清| 91久久久亚洲精品| 国产精品jizz在线观看美国| 性高湖久久久久久久久| 久久国产免费| 99视频在线观看一区三区| 正在播放欧美一区| 国内精品模特av私拍在线观看| 欧美sm重口味系列视频在线观看| 欧美精品国产精品| 欧美一区观看| 欧美成人中文字幕| 新片速递亚洲合集欧美合集| 欧美在线视频一区二区| 亚洲精品乱码久久久久久按摩观 | 美女视频网站黄色亚洲| 夜夜嗨av一区二区三区四季av| 亚洲一区二区免费在线| 一区在线免费观看| 一区二区高清在线观看| 韩国av一区二区三区四区| 亚洲国产成人av在线| 欧美视频亚洲视频| 欧美sm视频| 国产日韩精品一区二区| 亚洲精品123区| 国内精品久久久久久久影视蜜臀 | 亚洲一区高清| 久久精品国产免费| 亚洲欧美一区二区视频| 亚洲欧美精品一区| 久久精品欧美| 99这里只有久久精品视频| 亚洲综合第一页| 亚洲日本中文字幕| 午夜一区二区三视频在线观看| 亚洲激情视频网站| 亚洲制服欧美中文字幕中文字幕| 亚洲国产精品视频一区| 欧美一级网站| 性xx色xx综合久久久xx| 欧美日韩午夜在线视频| 你懂的视频欧美| 国产亚洲亚洲| 亚洲一区二区在线| 一区二区福利| 欧美大片专区| 欧美黑人国产人伦爽爽爽| 好男人免费精品视频| 亚洲欧美在线免费| 午夜免费久久久久| 欧美三日本三级少妇三2023| 最新日韩av| 亚洲人体大胆视频| 嫩草影视亚洲| 欧美91大片| 亚洲福利视频二区| 久久在线免费观看| 欧美福利视频在线| 亚洲国产精品一区制服丝袜| 久久久久国产精品一区二区| 久久免费国产| 伊人久久噜噜噜躁狠狠躁| 久久国产精品久久久久久电车| 久久九九免费| 精品69视频一区二区三区| 久久精品视频在线看| 免费亚洲电影在线观看| 亚洲国产成人精品女人久久久| 久久在线播放| 亚洲人成精品久久久久| aⅴ色国产欧美| 欧美日韩一区三区四区| 亚洲特级毛片| 久久久人成影片一区二区三区 | 亚洲国产精品久久91精品| 黄色亚洲免费| 欧美+日本+国产+在线a∨观看| 亚洲国产综合在线| 亚洲性色视频| 国产精品日韩精品欧美精品| 西西人体一区二区| 欧美成在线视频| 宅男噜噜噜66一区二区66| 国产精品视频自拍| 久久夜色精品亚洲噜噜国产mv| 91久久国产综合久久| 午夜精品久久久久久久99热浪潮| 国产美女精品一区二区三区| 久久久7777| 日韩视频免费看| 久久se精品一区精品二区| 亚洲盗摄视频| 欧美视频日韩视频| 久久精品女人| 国产日韩欧美一区二区三区在线观看| 久久久噜噜噜| 91久久线看在观草草青青| 欧美日一区二区三区在线观看国产免| 亚洲欧美国产制服动漫| 另类av一区二区| 日韩视频―中文字幕| 国产精品国产三级国产aⅴ入口 | 在线看视频不卡| 欧美日韩亚洲综合一区| 久久久精品视频成人| 亚洲深夜福利网站| 欧美韩日一区二区| 久久久亚洲一区| 亚洲欧美日韩一区在线| 亚洲品质自拍| 激情六月综合| 国产深夜精品| 国产精品美腿一区在线看 | 欧美在线一级视频| 一区二区三区日韩欧美| 在线精品一区| 国产一区二区三区的电影 | 亚洲肉体裸体xxxx137| 久久乐国产精品| 欧美一级大片在线免费观看| 99国产精品视频免费观看| 亚洲大片在线| 在线观看福利一区| 国语自产精品视频在线看一大j8 | 欧美成人有码|