s1083519 作業1
Assignment #1
1083519 戴尼爾
Topic: Image Rotation
撰寫一個程式將一張圖像的(a)整張圖像,(b)中心內切圓區域,旋轉一個角度(逆時針旋
轉0 度至359 度):利用一個滑動條(trackbar)控制旋轉角度。
Environment
Language: Python (version 3.8.16)
Environment:
- Windows 11
- OpenCV 4.7.0
- Conda 22.9.0
(An IDE was not used with the development of these programs.)
Program Overview
a. Rotation of entire image:
The rotation functions using 2 key functions: getRotationMatrix2D() and warpAffine()
- getRotationMatrix2D recieves 3 arguements:
- center: the central point around which the rotation happens
- angle: the angle of rotation
- scale: scaling factor for the image
The resulting matrix is then used as the parameters through which warpAffine() transforms the image.
- warpAffine recieves 3 arguements:
- source: the source image to be transformed
- M: the exact affine transformation to do, given by getRotationMatrix2D
- dsize: size of the output transformed image
b. Rotation of central circular portion:
The second program's rotation functions in much the same way; however, this time only a general area of the original image can be rotated. We achieve this affect by applying masks to our image, effectively limiting the transformation into the central circular area.
- First, a blank mask (np.zeros) is created, which is then made circular with cv2.circle. This circular mask is applied to our image through bitwise_and() to make our central circle,
- The circle is then "subtracted" from the original image. Both version are saved, and we now have both rotating object and static surroundings separated.
- The same functions shown in the first program are this time only applied to the circular middle section within our callback function, and the final rotated state is then combined with the outer section for imshow().
Program In Action
Image 1: 1st program, rotated 10 degrees.
Image 1: 1st program, rotated 161 degrees.
Image 3: 2nd program, rotated 58 degrees.
Image 4: 2nd program, rotated 347 degrees.
留言
張貼留言