Untitled

 avatar
unknown
plain_text
4 months ago
1.0 kB
17
Indexable
import cv2
import numpy as np

# Image size
h, w = 640, 480

# Center of the image
center = np.array([w / 2., h / 2.], dtype=np.float32)

# Scale
scale = np.array([w / 200., h / 200.], dtype=np.float32)

# Output size (width, height)
output_size = [192, 256]

# Compute source/destination points
src_w = scale[0] * 200
dst_w, dst_h = output_size

src_dir = np.array([0, -src_w * 0.5], dtype=np.float32)
dst_dir = np.array([0, -dst_w * 0.5], dtype=np.float32)

src_point = center
dst_point = np.array([dst_w * 0.5, dst_h * 0.5], dtype=np.float32)

# Build 3 points for affine transform
src = np.zeros((3,2), dtype=np.float32)
src[0,:] = src_point
src[1,:] = src_point + src_dir
src[2,:] = [src_point[0] - src_dir[1], src_point[1] + src_dir[0]]

dst = np.zeros((3,2), dtype=np.float32)
dst[0,:] = dst_point
dst[1,:] = dst_point + dst_dir
dst[2,:] = [dst_point[0] - dst_dir[1], dst_point[1] + dst_dir[0]]

#Affine transform
trans = cv2.getAffineTransform(src, dst)
print("Affine transform matrix:\n", trans)
Editor is loading...
Leave a Comment