Python+OpenCV:仿射变换和透射变换

拼搏现实的明天。 2022-12-20 14:53 425阅读 0赞

Python+OpenCV:仿射变换和透射变换

仿射变换

  1. ####################################################################################################
  2. # 仿射图像
  3. def lmc_cv_affining():
  4. """
  5. 函数功能: 仿射图像.
  6. """
  7. # 读取图像
  8. image = lmc_cv.imread('D:/99-Research/Python/Image/CheckerBoard.jpg')
  9. # 仿射图像
  10. rows, cols, channel = image.shape
  11. pts1 = np.float32([[50, 50], [200, 50], [50, 200]])
  12. pts2 = np.float32([[10, 100], [200, 50], [100, 250]])
  13. matrix = lmc_cv.getAffineTransform(pts1, pts2)
  14. affining_image = lmc_cv.warpAffine(image, matrix, (cols, rows))
  15. # 显示图像
  16. pyplot.figure('Image Display')
  17. pyplot.subplot(121)
  18. pyplot.imshow(image)
  19. pyplot.title('Input')
  20. pyplot.subplot(122)
  21. pyplot.imshow(affining_image)
  22. pyplot.title('Output')
  23. pyplot.show()
  24. # 根据用户输入保存图像
  25. if ord("q") == (lmc_cv.waitKey(0) & 0xFF):
  26. # 销毁窗口
  27. pyplot.close()
  28. return

watermark_type_ZmFuZ3poZW5naGVpdGk_shadow_10_text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L2xpdWJpbmc4NjA5_size_16_color_FFFFFF_t_70

透射变换

  1. image = lmc_cv.imread('D:/99-Research/Python/Image/Sudoku.jpg')
  2. # 透视图像
  3. rows, cols, channel = image.shape
  4. pts1 = np.float32([[33, 47], [424, 43], [2, 498], [441, 511]])
  5. pts2 = np.float32([[0, 0], [300, 0], [0, 300], [300, 300]])
  6. matrix = lmc_cv.getPerspectiveTransform(pts1, pts2)
  7. perspectiving_image = lmc_cv.warpPerspective(image, matrix, (300, 300))
  8. # 显示图像
  9. pyplot.figure('Image Display')
  10. pyplot.subplot(121)
  11. pyplot.imshow(image)
  12. pyplot.title('Input')
  13. pyplot.subplot(122)
  14. pyplot.imshow(perspectiving_image)
  15. pyplot.title('Output')
  16. pyplot.show()
  17. # 根据用户输入保存图像
  18. if ord("q") == (lmc_cv.waitKey(0) & 0xFF):
  19. # 销毁窗口
  20. pyplot.close()
  21. return

watermark_type_ZmFuZ3poZW5naGVpdGk_shadow_10_text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L2xpdWJpbmc4NjA5_size_16_color_FFFFFF_t_70 1

发表评论

表情:
评论列表 (有 0 条评论,425人围观)

还没有评论,来说两句吧...

相关阅读

    相关 仿变换

    仿射变换是平移、缩放、旋转、对称、错切五种变换的组合,其数学表达形式如下: ⎧⎩⎨⎪⎪x′=a11x\+a12y\+x0y′=a12x\+a22y\+y0 采用

    相关 GDAL仿变换

    一、仿射变换(Affine GeoTransform)有六个参数,描述的是栅格行列号和地理坐标之间的关系。 在GDAL中可以通过函数GDALDataset::GetGeoTr

    相关 pytorch---仿变换

    一、仿射变换 图片的旋转、平移、缩放等可以看做一个像素的重采样过程。将原图的像素映射到目标图像的对应位置上,可以