This commit is contained in:
louiscklaw
2025-01-31 22:57:47 +08:00
parent b1cd1d4662
commit b3cc8e8323
764 changed files with 722101 additions and 0 deletions

View File

@@ -0,0 +1,5 @@
*.jpg
*.png
*.bmp
*.gif
*.webp

View File

@@ -0,0 +1,9 @@
# -*- coding:utf8 -*-
import os
# 生成路径列表文件
os.system("dir /b/s/p/w *.jpg > neg.txt")
os.system("pause")

View File

@@ -0,0 +1,26 @@
import os
from PIL import Image
# 获取指定目录下的所有png图片
def get_all_png_files(dir):
files_list = []
for root, dirs, files in os.walk(dir):
for file in files:
if os.path.splitext(file)[1] == '.png':
files_list.append(os.path.join(root, file))
return files_list
# 批量转换png图片为jpg格式
def png2jpg(files_list):
for file in files_list:
img = Image.open(file)
new_file = os.path.splitext(file)[0] + '.jpg'
img.convert('RGB').save(new_file)
if __name__ == '__main__':
dir = './' #png图片目录
files_list = get_all_png_files(dir)
png2jpg(files_list)

View File

@@ -0,0 +1,26 @@
# -*- coding:utf8 -*-
import cv2
import numpy as np
import os
import re
import shutil
from pathlib2 import Path
# 批量灰度化图片
def GrayPic(srcImgDir):
for item in srcImgDir.rglob("*.jpg"):
# 获取图片名
imgName = item.name
img=cv2.imread(imgName)
gray=cv2.cvtColor(img,cv2.COLOR_BGR2GRAY)
cv2.imwrite("gray"+imgName,gray)
if __name__ == '__main__':
# 文件路径--跟代码同目录
srcImgPath = Path("./")
GrayPic(srcImgPath)
os.system("pause")

View File

@@ -0,0 +1,27 @@
# -*- coding:utf8 -*-
import os
import re
import shutil
from pathlib2 import Path
# 批量命名图片
def renamePic(srcImgDir):
i=0
for item in srcImgDir.rglob("*.jpg"):
# 获取图片名
imgName = item.name
newName = str(i)+".jpg"
i=i+1
# 重命名
print(f"prepare to rename {imgName}")
item.rename(newName)
if __name__ == '__main__':
# 文件路径--跟代码同目录
srcImgPath = Path("./")
renamePic(srcImgPath)
os.system("pause")

View File

@@ -0,0 +1,8 @@
# -*- coding:utf8 -*-
import os
os.system("copy .\\neg.txt ..\\")
os.system("pause")