flip, rotate

梁丘赞
2023-12-01
import cv2

import matplotlib.pylab as plt
import os

def readimg(path):
    name_dir = []
    for i in os.listdir(path):
        name = os.path.join(i)
        name_dir.append(name)
    return name_dir

path = 'images'
img = readimg(path)

for i in range(len(img)):
    image = cv2.imread(path + '/' + img[i])
    cv2.imwrite('image_flip/' + img[i].split('.')[0] + '_0.png',image)
    image_90 = cv2.rotate(image,cv2.ROTATE_90_CLOCKWISE)
    cv2.imwrite('image_flip/' + img[i].split('.')[0] + '_0_90.png',image_90)
    image_180 = cv2.rotate(image,cv2.ROTATE_180)
    cv2.imwrite('image_flip/' + img[i].split('.')[0] + '_0_180.png',image_180)
    image_270 = cv2.rotate(image,cv2.ROTATE_90_COUNTERCLOCKWISE)
    cv2.imwrite('image_flip/' + img[i].split('.')[0] + '_0_270.png',image_270)
    
    image1 = cv2.flip(image, 1)  # 水平翻转
    cv2.imwrite('image_flip/' + img[i].split('.')[0] + '_1.png',image1)
    image1_90 = cv2.rotate(image1,cv2.ROTATE_90_CLOCKWISE)
    cv2.imwrite('image_flip/' + img[i].split('.')[0] + '_1_90.png',image1_90)
    image1_180 = cv2.rotate(image1,cv2.ROTATE_180)
    cv2.imwrite('image_flip/' + img[i].split('.')[0] + '_1_180.png',image1_180)
    image1_270 = cv2.rotate(image1,cv2.ROTATE_90_COUNTERCLOCKWISE)
    cv2.imwrite('image_flip/' + img[i].split('.')[0] + '_1_270.png',image1_270)

 类似资料:

相关阅读

相关文章

相关问答