Ship_Tilt_Detection/resize_image.py

43 lines
1.5 KiB
Python
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#coding=utf-8
import cv2
# import numpy as np
# from PIL import Image, ImageDraw, ImageFont
#
# # 当前目录读取一张图片499Kb1920*1080
# img = cv.imread('hintersee01.jpg')
#
# # 压缩图片226Kb
# cv.imwrite('temp/compress1.jpg', img, [cv.IMWRITE_JPEG_QUALITY, 50])
#
# # 调整长宽(长宽指定数值,非等比例缩放时图片会变形)
# img2 = cv.resize(img, (500,500), interpolation=cv.INTER_CUBIC)
# cv.imwrite('temp/resize2.jpg', img2)
#
# # 调整长宽(长宽各调整为原来的一半,即 0.5
# img3 = cv.resize(img, (0,0), fx=0.5, fy=0.5, interpolation=cv.INTER_CUBIC)
# cv.imwrite('temp/resize3.jpg', img3)
## 遍历一个文件夹下的所有图像
def bianli_pics(path1,path2):
import os
img_folder = path1
img_list = [os.path.join(nm) for nm in os.listdir(img_folder) if nm[-3:] in ['jpg', 'png', 'gif']]
## print(img_list) 将所有图像遍历并存入一个列表
## ['test_14.jpg', 'test_15.jpg', 'test_9.jpg', 'test_17.jpg', 'test_16.jpg']
for i in img_list:
path = os.path.join(path1, i)
## print(path)
## ./input/test_14.jpg
## ./input/test_15.jpg
image = cv2.imread(path) ## 逐个读取
img2 = cv2.resize(image, (1920, 1080), interpolation=cv2.INTER_CUBIC)
# img2 = cv2.resize(image, (960, 540), interpolation=cv2.INTER_CUBIC)
cv2.imwrite(path2+i, img2)
print('',i)
if __name__ == "__main__":
path1 = "./dataPath/images"
path2 = "./dataPath/images3/"
bianli_pics(path1,path2)