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

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


只有注冊用戶登錄后才能發(fā)表評論。
網站導航: 博客園   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>
            麻豆乱码国产一区二区三区| 玖玖精品视频| 国产精品夜夜夜一区二区三区尤| 亚洲美女黄色片| 亚洲免费黄色| 国产精品久久久爽爽爽麻豆色哟哟| 亚洲视频图片小说| 亚洲在线观看视频| 国产亚洲精品久| 欧美成人激情视频免费观看| 美国十次成人| 亚洲午夜电影网| 亚洲欧美日本在线| 1769国内精品视频在线播放| 亚洲第一精品电影| 欧美视频导航| 久久全球大尺度高清视频| 美女国内精品自产拍在线播放| 亚洲精品免费在线播放| 亚洲视频一区在线| 国产一区二区三区日韩欧美| 欧美国产日产韩国视频| 欧美色道久久88综合亚洲精品| 午夜亚洲一区| 美女网站久久| 欧美中文字幕视频| 欧美大片国产精品| 欧美自拍偷拍午夜视频| 免费成人在线观看视频| 午夜精品久久99蜜桃的功能介绍| 久久精品国产一区二区三区免费看| 亚洲人在线视频| 亚洲欧美另类中文字幕| 亚洲精品中文字| 欧美一区二区三区四区在线观看 | 国产精品播放| 久久亚洲国产精品日日av夜夜| 欧美成人69av| 久久久久久噜噜噜久久久精品| 欧美激情第五页| 久久久久久久久久久一区 | 性久久久久久| 一区二区免费在线播放| 久久久久高清| 欧美亚洲三区| 欧美四级在线| 亚洲精品美女在线观看播放| 黄色成人av在线| 亚洲欧美国产三级| 亚洲性视频网址| 欧美激情视频一区二区三区免费 | 在线精品视频一区二区| 亚洲四色影视在线观看| 99综合精品| 欧美成人网在线| 欧美成人黑人xx视频免费观看| 国产精品一卡二卡| 在线一区免费观看| 亚洲性色视频| 国产精品国产三级国产aⅴ浪潮 | 久久亚洲私人国产精品va媚药| 国产精品爽爽爽| 中文亚洲免费| 亚洲欧美美女| 国产精品久久久久毛片软件 | 久久一区国产| 黄色一区二区在线观看| 久久精品91| 免费成人网www| 亚洲国产网站| 欧美黑人在线播放| 亚洲精品美女久久7777777| 亚洲老板91色精品久久| 欧美激情一区二区三区高清视频| 欧美激情视频给我| 99国产一区二区三精品乱码| 欧美激情第五页| 一本色道久久| 欧美在线精品一区| 国产一区二区中文字幕免费看| 欧美淫片网站| 欧美高清视频一区| 一本色道久久综合精品竹菊 | 国产精品久久久久天堂| 亚洲欧美日韩一区| 久久亚洲精品视频| 亚洲美女黄色片| 欧美三级乱码| 欧美在线不卡| 最近中文字幕日韩精品 | 亚洲一区国产精品| 国产日韩三区| 欧美va亚洲va国产综合| 一本色道久久加勒比精品| 欧美一区二区三区免费视频| 国产亚洲视频在线| 欧美成人免费网站| 亚洲一区二区三区四区视频| 久久夜色精品一区| 99国产精品一区| 国产在线成人| 欧美日韩第一区日日骚| 先锋a资源在线看亚洲| 欧美激情视频在线播放| 亚洲欧美精品suv| 亚洲国产精品99久久久久久久久| 欧美日韩精品二区| 久久久久久网站| 亚洲小说欧美另类社区| 欧美国产激情| 久久久久久久久久久成人| 一区二区三区高清视频在线观看| 国产欧美精品在线观看| 欧美激情精品久久久久久蜜臀| 午夜精品影院| 99视频在线精品国自产拍免费观看| 久久精品国产亚洲a| 一区二区三区免费在线观看| 韩国精品在线观看| 国产精品久久久久9999高清| 麻豆乱码国产一区二区三区| 亚洲欧洲av一区二区| 亚洲三级免费| 欧美激情一区三区| 久久婷婷久久| 久久久999精品免费| 亚洲伊人色欲综合网| 日韩视频二区| 亚洲欧洲日韩女同| 亚洲成在人线av| 韩日欧美一区| 国产亚洲精品久| 国产欧美综合在线| 国产精品久久久久久模特| 欧美日韩成人在线观看| 欧美高清在线| 欧美激情1区2区3区| 久久综合给合| 久久综合伊人77777蜜臀| 久久精品一区二区国产| 午夜久久福利| 欧美在线观看日本一区| 欧美亚洲一区二区在线| 午夜精品久久久久久久久久久久| 一区二区欧美日韩| 亚洲视频高清| 亚洲欧美视频在线观看| 亚洲男女自偷自拍| 午夜视频久久久| 久久av在线看| 久久先锋影音| 欧美夫妇交换俱乐部在线观看| 玖玖综合伊人| 欧美福利电影网| 欧美日韩一区在线观看| 欧美午夜理伦三级在线观看| 欧美日韩综合| 国产九九视频一区二区三区| 国产日韩欧美夫妻视频在线观看| 国产女主播一区二区| 国产一区二区三区自拍| 一区二区三区中文在线观看| 亚洲福利视频二区| 99精品视频免费| 午夜电影亚洲| 免费成人av在线看| 亚洲精品少妇网址| 亚洲免费中文| 欧美xxx成人| 欧美网站在线| 韩日精品在线| 夜夜精品视频一区二区| 小辣椒精品导航| 欧美高清视频一区二区| 亚洲乱码国产乱码精品精天堂| 亚洲天堂av图片| 久久综合九色九九| 欧美性大战xxxxx久久久| 国产自产2019最新不卡| 亚洲精品久久久蜜桃 | 好吊日精品视频| 日韩午夜在线电影| 欧美伊人久久大香线蕉综合69| 你懂的网址国产 欧美| 99这里只有久久精品视频| 欧美中文在线视频| 欧美日韩精品二区| 在线看片欧美| 欧美在线免费| 亚洲精选成人| 麻豆成人在线播放| 国产农村妇女精品一二区| 日韩视频在线观看免费| 久久久久9999亚洲精品| 99精品欧美一区| 免费成人黄色片| 国产在线观看91精品一区| 亚洲一区三区视频在线观看| 免费久久精品视频| 欧美一区二区日韩一区二区|