图片序列 (标注数据) 规范化重命名 (rename)
程序员文章站
2022-05-09 09:18:54
...
图片序列 (标注数据) 规范化重命名 (rename)
1. rename_file_multiple_images.py
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# Yongqiang Cheng
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
import os
import sys
import cv2
print("\nsys.version: %s" % (sys.version))
image_path = "/home/strong/demo_workspace/rename_file/vehicle_source_data_20191215/vehicle_source_data_20191215_p1"
prefix = "20191215"
# dsize = (width, height)
dsize = (1280, 720)
def inference(image_path, prefix, dsize):
image_dir = image_path + '/'
filepath = os.listdir(image_dir)
# filepath.sort()
image_path_new = image_path + "_rename"
image_dir_new = image_path_new + '/'
if not os.path.exists(image_dir_new):
os.makedirs(image_dir_new)
num = 0
for imagename in filepath:
oldname = image_dir + imagename.strip()
if ".jpg" not in oldname:
continue
img = cv2.imread(oldname)
# print(image_path_name)
img_height, img_width, img_channel = img.shape
# dsize = (width, height)
if img_height > dsize[1] or img_width > dsize[0]:
continue
padnum = str(num + 1).zfill(6)
newname = image_dir_new + ("%s_" % (prefix)) + padnum + '.jpg'
os.rename(oldname, newname)
print(oldname, ">>>>>>======>>>>>>", newname)
num += 1
if __name__ == '__main__':
current_directory = os.path.dirname(os.path.abspath(__file__))
print("current_directory:", current_directory)
print("__file__:", __file__)
print("os.path.abspath(__file__):", os.path.abspath(__file__))
print("os.path.dirname(os.path.abspath(__file__)):", os.path.dirname(os.path.abspath(__file__)))
print("os.getcwd():", os.getcwd())
print("os.curdir:", os.curdir)
print("os.path.abspath(os.curdir):", os.path.abspath(os.curdir))
print("sys.path[0]:", sys.path[0])
inference(image_path, prefix, dsize)
上一篇: PHP开发框架:LuckyPHP
下一篇: 数据-mysql中的事务处理,请大神指教