while(读取一个字符)
读取图像
if 字符 = r
旋转一个角度
else if 字符 = s
保存图像
else if 字符 = q
break;
from pynput import keyboard
import cv2
import numpy as np
import re
import cv2 as cv
import numpy as np
import os
import os.path
import glob
def rotateImg(img,angel):
rows, cols = img.shape
M = cv2.getRotationMatrix2D(((cols - 1) / 2.0, (rows - 1) / 2.0), angel, 1)
img = cv2.warpAffine(img, M, (cols, rows))
cv2.namedWindow("旋转图像")
cv2.imshow('旋转图像', img)
cv2.waitKey(1000)
cv2.destroyWindow("旋转图像")
if __name__ == '__main__':
SourceImgPath = "C:\\darknet-master\\VOCdevkit\\VOC2007\\JPEGImages" + '\\'
total_sou = os.listdir(SourceImgPath)
for img_source in total_sou:
ImgPath = os.path.join('%s%s' % (SourceImgPath, img_source))
img1 = cv2.imread(ImgPath, 0)
rotate_angel = 5
while 1:
line = input()
print(line[0:1])
if (line[0:1] == 'r'):
cv2.destroyAllWindows()
rotateImg(img1, rotate_angel)
rotate_angel += 30
elif (line[0:1] == 's'):
rows, cols = img1.shape
M = cv2.getRotationMatrix2D(((cols - 1) / 2.0, (rows - 1) / 2.0), rotate_angel, 1)
img1 = cv2.warpAffine(img1, M, (cols, rows))
cv.imwrite(ImgPath, img1)
elif (line[0:1] == 'q'):
break