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

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>
            免费毛片一区二区三区久久久| 久久久久久久一区二区| 国产一区二区福利| 亚洲欧美日本国产专区一区| 欧美日韩精品一二三区| 午夜精品999| 99精品久久久| 亚洲另类自拍| 亚洲视屏在线播放| 一区二区欧美视频| 午夜精品理论片| 久久精品中文字幕免费mv| 久久亚洲视频| 欧美日韩国产色站一区二区三区 | 亚洲午夜在线| 亚洲午夜久久久久久久久电影网| 欧美激情在线免费观看| 国产精品美女久久久| 国产日韩精品一区二区三区在线| 日韩视频免费观看| 亚洲欧美日韩国产一区二区| 午夜综合激情| 欧美日韩视频在线第一区| 欧美成人中文字幕在线| 欧美日韩高清在线播放| 国产精品蜜臀在线观看| 亚洲美女在线国产| 好吊日精品视频| 欧美日韩一区二区三区在线| 国产欧美视频在线观看| 日韩视频在线一区| 男女av一区三区二区色多| 亚洲欧美日韩精品| 欧美精品一区二区三区蜜臀 | 久久精品国产一区二区三区| 巨胸喷奶水www久久久免费动漫| 亚洲日本一区二区| 性欧美长视频| 国产精品午夜电影| 亚洲欧美日韩网| 中文无字幕一区二区三区| 欧美精品一区二区精品网 | 国产喷白浆一区二区三区| 亚洲精品国产无天堂网2021| 在线观看一区| 一区二区亚洲欧洲国产日韩| 午夜一区不卡| 国产精品久久久久一区二区三区| 欧美黄色成人网| 亚洲伦理在线免费看| 亚洲精品欧美极品| 国产精品一卡| 欧美www在线| 欧美—级高清免费播放| 亚洲欧美三级在线| 久久激五月天综合精品| 一二三四社区欧美黄| 午夜精品亚洲一区二区三区嫩草| 久久久在线视频| 欧美精品久久一区| 国产亚洲欧美在线| 欧美电影在线观看完整版| 一区二区三区国产盗摄| 国产主播一区二区三区| 亚洲精品你懂的| 国产精品一级| 欧美成人亚洲成人日韩成人| 国产精品国产三级国产a| 在线电影院国产精品| 亚洲欧美精品在线观看| 欧美日韩在线视频一区| 噜噜噜91成人网| 久久精品欧洲| 午夜在线视频一区二区区别| 欧美日韩第一区日日骚| 亚洲国产高潮在线观看| 欧美大片一区二区三区| 久久婷婷国产综合精品青草 | 亚洲国产精品99久久久久久久久| 亚洲色诱最新| 欧美精品18| 亚洲欧洲美洲综合色网| 亚洲一区二区三区午夜| 亚洲欧美日韩国产成人| 国产精品久久久久久久久| 欧美一区二区三区四区在线| 欧美色图首页| 欧美中文字幕精品| 亚洲国产精品ⅴa在线观看| 亚洲国产一区二区视频| 欧美日韩精品一本二本三本| 午夜精品久久久久久久99樱桃| 9色porny自拍视频一区二区| 宅男精品视频| 国产综合久久久久久鬼色| 久久久一区二区| 99精品欧美一区二区三区| 欧美一级专区| 亚洲综合另类| 在线看片日韩| 国产日本欧美一区二区三区在线 | 免费影视亚洲| 日韩视频在线播放| 久久久蜜桃精品| 亚洲免费高清视频| 每日更新成人在线视频| 欧美一区二区日韩| 亚洲香蕉在线观看| 亚洲精品国产无天堂网2021| 国产精品区一区二区三区| 一本色道久久加勒比88综合| 性欧美超级视频| 亚洲欧美www| 亚洲欧美国产视频| 亚洲一区二区三区久久| 国产精品激情电影| 一区二区三区色| 欧美天堂亚洲电影院在线观看| 欧美大成色www永久网站婷| 午夜精品久久久久久久99水蜜桃 | 久久久午夜电影| 久久久久久欧美| 国产一区三区三区| 国产精品欧美激情| 国产日韩欧美综合精品| 国产精品美女视频网站| 国产亚洲精品激情久久| 国产字幕视频一区二区| 伊人夜夜躁av伊人久久| 在线成人亚洲| 一区二区欧美激情| 亚洲欧美日韩第一区| 亚洲一区二区三区四区五区午夜| 亚洲日韩欧美视频一区| 国产精品久久午夜| 国内精品美女av在线播放| 美女被久久久| 欧美激情五月| 亚洲成人中文| 欧美中文在线字幕| 在线亚洲免费视频| 欧美 日韩 国产一区二区在线视频 | 欧美在线免费一级片| 麻豆9191精品国产| 在线中文字幕一区| 亚洲国产欧美一区二区三区同亚洲 | 亚洲激情国产| 午夜天堂精品久久久久| 亚洲欧美日韩在线高清直播| 99re在线精品| 欧美人与禽猛交乱配| 亚洲国产精品毛片| 亚洲精品国产精品国产自| 免费不卡在线观看| 亚洲国产欧洲综合997久久| 亚洲电影免费观看高清完整版| 亚洲国产精品久久人人爱蜜臀 | 久久精品一区二区| 亚洲二区在线观看| 久久久久久网址| 亚洲高清自拍| 这里只有视频精品| 国产精品自在在线| 久久高清国产| 亚洲一区二区免费在线| 国产精品试看| 欧美在线视频二区| 欧美激情精品久久久| 国产亚洲精品aa午夜观看| 亚洲欧美激情视频| 欧美国产先锋| 亚洲影视在线| 伊人久久大香线| 欧美另类高清视频在线| 午夜精品一区二区在线观看| 欧美sm视频| 在线免费观看日本一区| 久久综合一区二区| 欧美伊人久久大香线蕉综合69| 欧美精品七区| 欧美高清在线一区二区| 日韩视频二区| 久久久久国产精品一区| 亚洲免费福利视频| 久久精品毛片| 亚洲视频高清| 亚洲欧洲一区二区在线观看| 国产精品美女久久| 免费看精品久久片| 欧美一区二区精美| 日韩午夜三级在线| 一本色道久久综合亚洲91| 国产欧美日韩另类视频免费观看| 亚洲视频999| 欧美激情免费在线| 久久这里只有精品视频首页| 亚洲欧美国产日韩天堂区| 9l国产精品久久久久麻豆| 在线观看福利一区| 黑人操亚洲美女惩罚|