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

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>
            亚洲精品日韩在线观看| 小处雏高清一区二区三区| 欧美精品在欧美一区二区少妇| 欧美一站二站| 久久久国产精品一区二区中文| 欧美一级视频免费在线观看| 香蕉视频成人在线观看| 性伦欧美刺激片在线观看| 午夜精品在线视频| 久久国产福利| 欧美成人黑人xx视频免费观看| 欧美成人免费大片| 欧美日韩一区高清| 国产欧美日韩视频在线观看 | 亚洲亚洲精品三区日韩精品在线视频| 一级成人国产| 欧美在线播放一区| 免费精品视频| 国产精品久久九九| 国产综合色一区二区三区| 亚洲第一精品福利| 亚洲天堂av图片| 久久久综合网| 亚洲欧洲另类国产综合| 一区二区三区国产在线| 久久成人免费电影| 欧美极品影院| 黄色影院成人| 欧美一级日韩一级| 亚洲国产日韩在线| 亚洲一区在线看| 欧美成人蜜桃| 伊人久久大香线蕉综合热线| 亚洲一区二区日本| 噜噜噜噜噜久久久久久91| 亚洲黄色免费网站| 欧美在线视频一区二区| 欧美精品在线观看播放| 伊人久久久大香线蕉综合直播| 亚洲一二三区在线观看| 欧美国内亚洲| 久久精品国产99精品国产亚洲性色| 欧美三级乱人伦电影| 亚洲黄网站黄| 欧美99久久| 久久国产精彩视频| 国产伦理精品不卡| 亚洲一区免费观看| 欧美激情一区三区| 亚洲高清在线| 亚洲一区二区欧美日韩| 亚洲国产一区二区三区青草影视 | 欧美日韩国产黄| 亚洲国产二区| 麻豆精品传媒视频| 久久精品国产精品| 国产婷婷精品| 久久久久国色av免费观看性色| 一区二区三区高清视频在线观看| 欧美激情视频一区二区三区在线播放| 激情一区二区| 欧美a级一区二区| 久久久久9999亚洲精品| 黄色亚洲网站| 欧美成人黑人xx视频免费观看| 久久久99爱| 亚洲国产精品传媒在线观看| 欧美大胆成人| 欧美电影在线观看| 一本色道**综合亚洲精品蜜桃冫| 亚洲黑丝一区二区| 欧美日韩精品一区| 亚洲欧美日韩国产成人| 亚洲与欧洲av电影| 国产综合色产在线精品| 蜜臀av一级做a爰片久久| 久久天天综合| 亚洲美女视频网| 99在线视频精品| 国产精品五月天| 久久夜色精品国产欧美乱| 久久亚洲国产成人| 一本一本久久| 午夜精品久久99蜜桃的功能介绍| 国内成+人亚洲| 亚洲国产一区二区三区a毛片| 欧美日韩在线综合| 久久久99国产精品免费| 久久夜精品va视频免费观看| 99亚洲精品| 欧美亚洲一区二区在线观看| 亚洲激情一区| 亚洲一区二区3| 91久久久久久久久久久久久| 亚洲少妇在线| 亚洲韩国青草视频| 亚洲图色在线| 亚洲欧洲一区二区在线播放 | 亚洲午夜精品一区二区三区他趣| 国产精品一区视频网站| 欧美成人综合一区| 国产精品久久久久久久久久直播| 久久午夜影视| 国产精品成人v| 欧美搞黄网站| 国产亚洲精品一区二区| 欧美大片免费久久精品三p | 亚洲一级一区| 亚洲国产一区二区三区a毛片| 亚洲最新在线| 精品成人一区| 亚洲一区二区三区久久| 亚洲黄色影院| 欧美一级黄色网| 亚洲无线视频| 欧美成人免费网站| 久久久久久午夜| 国产精品裸体一区二区三区| 亚洲电影在线| 国产一区二区三区在线观看精品 | 蘑菇福利视频一区播放| 欧美一区二区三区免费大片| 欧美高清在线视频| 久热re这里精品视频在线6| 国产精品国产三级国产aⅴ浪潮| 欧美国产欧美综合| 影音先锋欧美精品| 欧美在线看片| 久久久精品999| 国产乱码精品一区二区三区不卡| 亚洲精品免费一区二区三区| 亚洲国产专区校园欧美| 久久人体大胆视频| 麻豆久久精品| 亚洲国产一区二区三区在线播 | 国产精品欧美久久| 亚洲免费电影在线观看| 亚洲美女黄色| 欧美日韩一卡二卡| 中文日韩在线视频| 国产精品99久久久久久有的能看| 欧美黄色小视频| 亚洲精品乱码久久久久久久久| 亚洲人成绝费网站色www| 欧美大片91| 日韩亚洲欧美高清| 亚洲一区二区三区在线看| 欧美日韩在线三区| 国产精品99久久99久久久二8 | 亚洲全黄一级网站| 99精品黄色片免费大全| 欧美日韩亚洲一区| 亚洲一区国产精品| 欧美中日韩免费视频| 黄色av日韩| 欧美大片在线影院| 一区二区三区视频在线观看 | 中文高清一区| 久久久国产亚洲精品| 在线看片一区| 欧美日韩精品二区| 亚洲男人天堂2024| 亚洲国产精品久久91精品| 欧美sm视频| 亚洲女女女同性video| 久久亚洲国产精品一区二区| 亚洲第一在线视频| 欧美日韩一区二区三区在线观看免| 亚洲视频专区在线| 久久综合网hezyo| 一区二区三区国产精品| 国产精品日韩一区二区| 久久精品视频免费| 亚洲精选一区| 久久精品国产清自在天天线| 亚洲激情午夜| 国产精品日韩在线一区| 久久夜色精品| 亚洲欧美国产毛片在线| 亚洲高清一区二区三区| 午夜亚洲性色福利视频| 亚洲激情第一区| 国产亚洲免费的视频看| 欧美日韩精品一区二区在线播放 | 久久久亚洲人| 一区二区高清视频在线观看| 久久综合给合| 亚洲主播在线播放| 亚洲国产精品小视频| 国产精品久久久久久妇女6080| 久久综合九色综合欧美狠狠| 亚洲视频图片小说| 亚洲韩国日本中文字幕| 久久综合色播五月| 欧美一级在线亚洲天堂| 在线视频欧美一区| 亚洲茄子视频| 有码中文亚洲精品| 国产午夜精品理论片a级大结局 | 一区二区三区欧美亚洲|