s1091536 作業1
1.題目說明:
撰寫一個程式將一張圖像(下圖)的(a)整張圖像,(b)中心內切圓區域,旋轉一個角度(逆時針旋 轉 0 度至 359 度):利用一個滑動條(trackbar)控制旋轉角度。
2.開發環境:
OS: Windows 11
Editor: PyCharm
Language: python 3.8
Package: OpenCV 4.7.0
Language: python 3.8
Package: OpenCV 4.7.0
4.方法及實作:
(a)概念:
畫出Mask並利用cv2的bitwise_and功能做出圓形分割。
(b)程式:
使用 getRotationMatrix2D 得到旋轉矩陣,用於旋轉所需圖形。
M = cv2.getRotationMatrix2D(center, angle, 1)
rotated_img = cv2.warpAffine(img,M,(cols,rows))
使用Trackbar
cv2.createTrackbar('Degree','Rotated image',0,359,full_img_rotate)
#track bar 移動會return值給 x
def full_img_rotate(x):
# create 3 channel Mask img
circle = np.zeros((rows,cols,3), np.uint8)
畫出內部全白的圓(反之黑色則將255設為0)
circle = cv2.circle(circle, center,(int)(min(cols,rows)/2),(255,255,255),-1) # white circle, filled
留言
張貼留言