update,
This commit is contained in:
5
vinniesniper-54816/task1/_lab/007-test/negdata.1/.gitignore
vendored
Normal file
5
vinniesniper-54816/task1/_lab/007-test/negdata.1/.gitignore
vendored
Normal file
@@ -0,0 +1,5 @@
|
||||
*.jpg
|
||||
*.png
|
||||
*.bmp
|
||||
*.gif
|
||||
*.webp
|
@@ -0,0 +1,9 @@
|
||||
# -*- coding:utf8 -*-
|
||||
import os
|
||||
|
||||
|
||||
# 生成路径列表文件
|
||||
os.system("dir /b/s/p/w *.jpg > neg.txt")
|
||||
|
||||
|
||||
os.system("pause")
|
26
vinniesniper-54816/task1/_lab/007-test/negdata.1/_PNG2JPG.py
Normal file
26
vinniesniper-54816/task1/_lab/007-test/negdata.1/_PNG2JPG.py
Normal 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)
|
@@ -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")
|
27
vinniesniper-54816/task1/_lab/007-test/negdata.1/_ReName.py
Normal file
27
vinniesniper-54816/task1/_lab/007-test/negdata.1/_ReName.py
Normal 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")
|
@@ -0,0 +1,8 @@
|
||||
# -*- coding:utf8 -*-
|
||||
import os
|
||||
|
||||
|
||||
os.system("copy .\\neg.txt ..\\")
|
||||
|
||||
|
||||
os.system("pause")
|
Reference in New Issue
Block a user