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.
48 lines
1.6 KiB
48 lines
1.6 KiB
import cv2
|
|
import numpy as np
|
|
|
|
|
|
class GeoChange:
|
|
def __init__(self, imgPath):
|
|
self.path = imgPath
|
|
|
|
def extend(self, size):
|
|
img = cv2.imread(self.path)
|
|
img = cv2.resize(img, (0, 0), fx=size, fy=size, interpolation=cv2.INTER_LINEAR)
|
|
cv2.imwrite("saved Img/size.bmp", img)
|
|
|
|
def move(self, x, y):
|
|
img = cv2.imread(self.path)
|
|
height, width, channel = img.shape
|
|
# 构建平移矩阵
|
|
matrix = np.float32([[1, 0, x], [0, 1, y]])
|
|
img = cv2.warpAffine(img, matrix, (width, height))
|
|
cv2.imwrite("saved Img/move.bmp", img)
|
|
|
|
def horizon_flip(self):
|
|
img = cv2.imread(self.path)
|
|
horizon = cv2.flip(img, 1, dst=None)
|
|
cv2.imwrite("saved Img/horizon.bmp", horizon)
|
|
|
|
def vertical_flip(self):
|
|
img = cv2.imread(self.path)
|
|
vertical = cv2.flip(img, 0, dst=None)
|
|
cv2.imwrite("saved Img/vertical.bmp", vertical)
|
|
|
|
def rotation(self, degree):
|
|
img = cv2.imread(self.path)
|
|
rows, cols, depth = img.shape
|
|
matrix = cv2.getRotationMatrix2D((cols / 2, rows / 2), degree, 1)
|
|
img = cv2.warpAffine(img, matrix, (cols, rows))
|
|
cv2.imwrite("saved Img/rotation.bmp", img)
|
|
|
|
def affine(self):
|
|
img = cv2.imread(self.path)
|
|
img = cv2.resize(img, (256, 256))
|
|
rows, cols = img.shape[: 2]
|
|
post1 = np.float32([[50, 50], [200, 50], [50, 200]])
|
|
post2 = np.float32([[10, 100], [200, 50], [100, 250]])
|
|
M = cv2.getAffineTransform(post1, post2)
|
|
result = cv2.warpAffine(img, M, (rows, cols))
|
|
cv2.imwrite("saved Img/affine.bmp", result)
|