You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
21 lines
600 B
21 lines
600 B
# 実験課題1
|
|
# 3.1 画像サイズ変換・画像の回転
|
|
|
|
import cv2
|
|
|
|
image_path = 'sample.jpg'
|
|
img = cv2.imread(image_path)
|
|
|
|
if img is not None:
|
|
height, width = img.shape[:2]
|
|
|
|
# サイズ変換
|
|
new_width, new_height = width // 2, height // 2
|
|
resized_img = cv2.resize(img, (new_width, new_height))
|
|
cv2.imwrite('3_1_resize.jpg', resized_img)
|
|
|
|
# 回転
|
|
center = (width // 2, height // 2)
|
|
rotation_matrix = cv2.getRotationMatrix2D(center, 45, 1.0)
|
|
rotated_img = cv2.warpAffine(img, rotation_matrix, (width, height))
|
|
cv2.imwrite('3_1_rotate.jpg', rotated_img) |