日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程语言 > python >内容正文

python

Python-OpenCV 笔记5 -- 几何变换(Geometric Transformations)

發布時間:2025/3/12 python 23 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Python-OpenCV 笔记5 -- 几何变换(Geometric Transformations) 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

Python-OpenCV 筆記5 – 幾何變換(Geometric Transformations)


1、縮放(Scaling)

# 函數原型 cv.resize(src, dsize[, dst[, fx[, fy[, interpolation]]]])# 實例 cv2.resize(img,None,fx=2, fy=2)height, width = img.shape[:2] res = cv2.resize(img,(2*width, 2*height))
  • dsize:輸出圖片的尺寸
  • fx:x軸縮放因子
  • fy:x軸縮放因子
  • interpolation:插值方法

2、平移(Translation)

# 實例,x軸平移100,y軸平移50 rows, cols = img.shape M = np.float32([[1,0,100],[0,1,50]]) dst = cv2.warpAffine(img,M,(cols,rows))

3、旋轉(Rotation)

# 函數原型 getRotationMatrix2D(center, angle, scale)# 實例 rows,cols = img.shape # 注意減1 M = cv.getRotationMatrix2D(((cols-1)/2.0,(rows-1)/2.0), 90, 1) dst = cv.warpAffine(img,M,(cols,rows))
  • center:旋轉中心
  • angle: 旋轉角度(°),正值代表順時針(默認為左上角).
  • scale:縮放比例

4、仿射變換(Affine Transformation)

# 函數原型 cv2.warpAffine(src, M, dsize[, dst[, flags[, borderMode[, borderValue]]]] )# 實例 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))
  • M: 3×3 變換矩陣
  • dsize:輸出圖片的尺寸

5、透視變換(Perspective Transformation)

# 函數原型 warpPerspective(src, M, dsize[, dst[, flags[, borderMode[, borderValue]]]])# 實例 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))

總結

以上是生活随笔為你收集整理的Python-OpenCV 笔记5 -- 几何变换(Geometric Transformations)的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。