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

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 閱讀(777) 評論(0)  編輯 收藏 引用


只有注冊用戶登錄后才能發表評論。
網站導航: 博客園   IT新聞   BlogJava   博問   Chat2DB   管理


青青草原综合久久大伊人导航_色综合久久天天综合_日日噜噜夜夜狠狠久久丁香五月_热久久这里只有精品
  • <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>
            欧美中文字幕视频在线观看| 亚洲欧美精品在线观看| 你懂的成人av| 最新69国产成人精品视频免费| 欧美成人免费在线| 欧美不卡高清| 亚洲在线免费| 久久精品日产第一区二区三区| 国产亚洲一区精品| 欧美岛国在线观看| 欧美日韩情趣电影| 欧美亚洲在线| 久久精品国产亚洲aⅴ| 136国产福利精品导航网址| 欧美国产精品中文字幕| 欧美大片国产精品| 亚洲一区二区三区精品动漫| 午夜精品久久久久久99热软件| 精品成人乱色一区二区| 亚洲欧洲视频| 国产精品日韩在线观看| 免费av成人在线| 欧美日韩国产成人在线观看| 久久精品色图| 欧美日韩高清在线一区| 久久精品在线观看| 欧美精品一区二区久久婷婷| 久久不射网站| 欧美精品久久久久久久久久| 欧美在线视频二区| 欧美激情 亚洲a∨综合| 久久九九热免费视频| 欧美精品入口| 可以看av的网站久久看| 国产精品久久久久aaaa樱花| 欧美电影美腿模特1979在线看 | 亚洲尤物在线| 91久久精品网| 亚欧美中日韩视频| 亚洲网站视频福利| 麻豆91精品| 久久久久久久久岛国免费| 欧美日韩国产999| 欧美成人免费网| 国产无遮挡一区二区三区毛片日本| 91久久精品久久国产性色也91| 国内自拍亚洲| 亚洲免费网站| 亚洲欧美日韩一区在线观看| 欧美激情一区| 亚洲国产精品成人综合| 伊人久久成人| 久久国产精品久久w女人spa| 亚洲欧美一区二区三区在线| 欧美女人交a| 亚洲激情一区| 亚洲精品一区在线观看| 可以免费看不卡的av网站| 久久精品国产免费| 国产精品永久免费| 亚洲中字在线| 欧美一级理论片| 国产精品亚洲人在线观看| 亚洲另类一区二区| 一区二区久久| 欧美体内谢she精2性欧美| 日韩午夜免费| 亚洲手机视频| 欧美日韩中文字幕| 这里只有精品丝袜| 亚洲一区图片| 国产精品影视天天线| 午夜精品一区二区三区在线| 久久国产精品久久国产精品| 国产一区二区日韩精品| 久久精品二区三区| 欧美岛国激情| 99国产精品| 国产精品免费在线| 欧美一区二区三区精品电影| 免费亚洲一区二区| 亚洲免费av网站| 国产精品国产福利国产秒拍| 午夜视频在线观看一区| 免费欧美网站| 一区二区三区成人 | 午夜精品理论片| 久久精品国产久精国产思思| 加勒比av一区二区| 欧美成人69av| 亚洲一级影院| 麻豆久久精品| 亚洲一区二区少妇| 国内精品久久久久影院优| 母乳一区在线观看| 亚洲视频播放| 欧美高清视频一区| 亚洲一区二区三区精品在线观看| 国产欧美一区二区三区久久 | 美女主播精品视频一二三四| 亚洲精品一区二区三区樱花| 久久疯狂做爰流白浆xx| 在线观看欧美日韩国产| 伊人一区二区三区久久精品| 能在线观看的日韩av| 亚洲精品在线视频观看| 久久精品视频免费| 亚洲国产老妈| 国产伦精品一区二区| 免费观看成人鲁鲁鲁鲁鲁视频| 这里只有精品电影| 欧美激情精品| 久久黄色影院| 亚洲香蕉在线观看| 在线日韩一区二区| 国产欧美日韩精品一区| 欧美激情综合网| 久久久国产成人精品| 一道本一区二区| 欧美韩国日本综合| 欧美一区激情| 亚洲欧美日韩人成在线播放| 亚洲欧洲在线观看| 亚洲人在线视频| 亚洲福利视频网| 国产精品美女| 欧美激情在线| 久久精品免费看| 亚洲一品av免费观看| 亚洲国产视频一区二区| 久久露脸国产精品| 久久高清福利视频| 午夜国产不卡在线观看视频| 99日韩精品| 亚洲国产欧美一区| 亚洲福利视频一区| 激情欧美一区| 狠久久av成人天堂| 国产嫩草一区二区三区在线观看 | 麻豆91精品| 久久精品人人爽| 欧美在线看片a免费观看| 亚洲欧美日韩在线播放| 亚洲午夜久久久久久久久电影院 | 亚洲黄色av一区| 在线免费观看视频一区| 欲色影视综合吧| 在线观看亚洲a| 亚洲夫妻自拍| 亚洲精品免费一二三区| 亚洲国产精品久久人人爱蜜臀 | 欧美吻胸吃奶大尺度电影| 欧美日韩国产精品成人| 欧美日韩国产不卡| 欧美午夜免费电影| 国产精品免费一区二区三区在线观看| 国产精品美女诱惑| 国产无遮挡一区二区三区毛片日本| 国产婷婷成人久久av免费高清 | 欧美日韩一区在线观看视频| 欧美日韩精品免费观看| 欧美性色综合| 国产欧美日韩精品在线| 狠狠色综合播放一区二区| 亚洲国产欧美日韩| avtt综合网| 欧美一区二区日韩一区二区| 久久国产一区| 亚洲国产精品va在线看黑人| 亚洲免费激情| 欧美一区二区三区在线观看视频| 久久精品亚洲精品国产欧美kt∨| 免费不卡中文字幕视频| 欧美日韩一区二区三区视频| 国产区精品在线观看| 亚洲国产婷婷香蕉久久久久久99| 一区二区三区**美女毛片| 久久成人国产精品| 欧美激情精品久久久久久蜜臀| 99视频一区| 久久久久久亚洲精品不卡4k岛国| 欧美美女福利视频| 韩国在线一区| 一区二区三区产品免费精品久久75| 篠田优中文在线播放第一区| 欧美国产日本在线| 亚洲性色视频| 欧美激情精品久久久久久黑人| 国产精品少妇自拍| 亚洲精品字幕| 久久久xxx| 亚洲午夜精品| 欧美精品一区二区三区视频 | 老司机久久99久久精品播放免费| 欧美日韩在线视频观看| 在线日韩av永久免费观看| 午夜精品免费视频| 亚洲人成在线影院| 久久国产黑丝| 国产精品一区二区三区观看|