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

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>
            久久精品一二三区| 国产精品白丝av嫩草影院| 欧美激情亚洲精品| 久久久精品一品道一区| 亚洲欧美在线磁力| 午夜精品在线视频| 久久久久久婷| 亚洲国产精品悠悠久久琪琪| 亚洲第一级黄色片| 亚洲午夜电影| 亚洲欧美日韩电影| 久久精品女人| 欧美福利一区| 亚洲人成网站在线观看播放| 亚洲一区激情| 欧美一区二区啪啪| 久久综合综合久久综合| 欧美日韩少妇| 国产有码一区二区| 亚洲美女精品一区| 久久国产精品一区二区三区四区| 免费欧美在线| 亚洲精品专区| 欧美在线视频网站| 欧美日韩伦理在线免费| 国内精品久久国产| 亚洲一区二区三区视频播放| 美女免费视频一区| 亚洲自拍电影| 欧美日韩调教| 91久久夜色精品国产九色| 亚洲免费在线观看视频| 欧美黄色精品| 欧美在线免费观看| 国产精品欧美经典| 亚洲最新视频在线| 裸体歌舞表演一区二区| 亚洲欧美日本日韩| 欧美四级在线观看| 亚洲美女免费视频| 欧美成人久久| 久久久国产一区二区| 国产精品一区在线观看你懂的| 亚洲精品久久久久久久久| 久久精品在线播放| 亚洲欧美日韩专区| 国产精品久久毛片a| 一二三区精品| 亚洲国产高清一区二区三区| 久久精品日韩一区二区三区| 国产日韩欧美电影在线观看| 亚洲欧美日韩在线| 国产精品99久久99久久久二8| 欧美精品三区| 99精品欧美一区二区蜜桃免费| 国产精品久久久久aaaa九色| 欧美尤物一区| 欧美激情小视频| 欧美巨乳在线观看| 欧美三级电影一区| 久久国产精品亚洲77777| 欧美激情一区在线观看| 免费观看成人网| 亚洲综合色视频| 久久米奇亚洲| 国产女精品视频网站免费| 这里只有精品视频| 亚洲人成网站999久久久综合| 亚洲网站在线看| 久久九九国产精品怡红院| 韩国精品一区二区三区| 久久中文字幕导航| 玖玖玖国产精品| 亚洲精品社区| 一区二区三欧美| 国产精品国产三级国产普通话三级| 99国产精品国产精品毛片| 亚洲国产婷婷香蕉久久久久久99 | 午夜精品视频在线| 国内精品伊人久久久久av一坑 | 最新国产の精品合集bt伙计| 欧美jizz19hd性欧美| 亚洲国内自拍| 亚洲国产欧美国产综合一区| 欧美三日本三级三级在线播放| 这里只有精品视频| 亚洲影视在线播放| 136国产福利精品导航网址| 亚洲国产精品久久久久婷婷老年 | 在线精品在线| 最新亚洲一区| 国产欧美一区二区色老头 | 一本色道88久久加勒比精品| 国产精品一区二区久久国产| 欧美成人精品一区二区| 欧美午夜电影在线| 久久全国免费视频| 欧美.com| 久久精品女人天堂| 欧美日本精品| 久久综合久久久久88| 欧美无砖砖区免费| 免费视频亚洲| 亚洲欧美激情一区| 国产精品国产精品| 蜜桃av一区二区| 欧美三级小说| 欧美黄色小视频| 国产噜噜噜噜噜久久久久久久久| 欧美激情视频在线播放| 国产精品久久久久久久久久久久久| 久久午夜精品| 欧美三级欧美一级| 亚洲高清不卡av| 国内外成人在线视频| 亚洲一区二区高清视频| 亚洲精品资源| 久久久欧美一区二区| 欧美在线观看www| 欧美网站在线| 一本到12不卡视频在线dvd| 亚洲国产精品专区久久| 午夜欧美大尺度福利影院在线看| 9人人澡人人爽人人精品| 免费日韩av电影| 久久综合精品国产一区二区三区| 国产日韩免费| 午夜一区二区三视频在线观看| 亚洲综合视频网| 欧美午夜在线一二页| 亚洲欧洲日本专区| 亚洲精品视频在线播放| 欧美成人tv| 亚洲欧洲日韩女同| 日韩午夜中文字幕| 欧美成人日本| 亚洲国产精品久久人人爱蜜臀 | 欧美国产日韩一区二区三区| 久久国产主播精品| 国产婷婷色一区二区三区| 亚洲永久在线| 欧美淫片网站| 国产一区二区欧美日韩| 久久久国产午夜精品| 美女日韩欧美| 亚洲人成网在线播放| 欧美大成色www永久网站婷| 亚洲黄色一区二区三区| 亚洲国产婷婷| 欧美日韩精品高清| 亚洲网站啪啪| 久久久综合视频| 18成人免费观看视频| 欧美国产日韩二区| 亚洲色图综合久久| 久久久久.com| 亚洲精选中文字幕| 国产精品久久久久久久久久直播| 亚洲一区国产一区| 可以免费看不卡的av网站| 亚洲精品国产精品国自产在线| 欧美日韩aaaaa| 亚洲永久在线观看| 久久视频精品在线| 亚洲精品一区在线| 国产精品日韩欧美| 久久综合狠狠综合久久激情| 欧美午夜一区二区| 一区二区av在线| 国产精品高潮粉嫩av| 午夜精品电影| 亚洲电影在线| 亚洲欧美日韩在线| 亚洲黄色影片| 国产精品中文字幕欧美| 美女精品国产| 亚洲欧美视频| 亚洲免费观看高清在线观看| 久久久精品一区二区三区| 一区二区av| 亚洲国产另类精品专区| 国产精品自拍在线| 欧美激情a∨在线视频播放| 先锋影音一区二区三区| 亚洲精品免费在线观看| 毛片一区二区| 欧美主播一区二区三区美女 久久精品人 | 欧美影院视频| 99精品久久久| 亚洲第一色在线| 久久久99久久精品女同性| 一区二区三区色| 亚洲电影免费观看高清完整版在线 | 午夜精品视频在线观看| 亚洲精品亚洲人成人网| 久久久久久久综合日本| 亚洲欧美色婷婷| 亚洲另类视频| 激情自拍一区| 狠狠操狠狠色综合网|