Verified Commit 6f4e1295 authored by Kiryuu Sakuya's avatar Kiryuu Sakuya 🎵
Browse files

Add exam.2

parent c9c5398f
import numpy as np
import cv2
import os
def dataAugmentation(BasePath = 'data/rightOutputs/train_224'):
fileNames = os.listdir(BasePath)
for fileName in fileNames:
file = os.path.join(BasePath,fileName)
namePrex = fileName.split('.')[0]
image=cv2.imread(file)
img_fliped_X = cv2.flip(image, 1)
writePath = os.path.join('data/flipUserOutputs', f'{namePrex}_flipx.png')
cv2.imwrite(writePath,img_fliped_X)
if __name__ == '__main__':
dataAugmentation()
\ No newline at end of file
import cv2
import os
def dataAugmentation(BasePath = 'data/rightOutputs/train_224'):
'''
只需写水平翻转,翻转后的文件的文件名命名规范为文件名末尾加上 _flipx
示例 原文件名 “图片1.png”,翻转后保存的文件命名为 “图片1__flipx.png”
文件保存在'data/flipUserOutputs'目录下
:param BasePath: 待处理的图片文件夹路径
:return:
'''
#********** Begin **********#
#********** End **********#
if __name__ == '__main__':
dataAugmentation()
\ No newline at end of file
import os
import filecmp
from dataAugmentationForUsers import dataAugmentation
from subprocess import *
dataAugmentation()
# 执行用户完成的脚本
# call('python step2/dataAugmentationForUsers.py')
correctTrainPath = 'data/flipRightOutputs'
userTrainPath = 'data/flipUserOutputs'
correctTrainFile = os.listdir(correctTrainPath)
# 比对全部水平翻转的图片是否与正确翻转的图片相同
try:
# 从用户的输出文件中抽取样本,只需要考虑用户输出的训练集
filelist = [flipimg for flipimg in correctTrainFile]
if filelist:
for imgUserTrainName in filelist:
# 获取文件名
imgUserTrainPath = os.path.join(userTrainPath, imgUserTrainName)
# 找到正确文件中的对应样本的路径
imgCorrectTrainPath = os.path.join(correctTrainPath, imgUserTrainName)
bool = filecmp.cmp(imgCorrectTrainPath, imgUserTrainPath)
if not bool :
print(imgCorrectTrainPath)
print(imgUserTrainPath)
print('未能通过本关测试!产生的图片不相同!',end='')
break
else:
print('恭喜你通过本关测试!',end='')
else:
print('未能通过本关测试!没有产生翻转文件',end='')
except:
print('未能通过本关测试!读取图片出错!',end='')
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment