mirror of
https://github.com/oscar-davids/lpmsdemo.git
synced 2025-12-24 12:37:59 +08:00
107 lines
3.2 KiB
Plaintext
107 lines
3.2 KiB
Plaintext
|
|
if __name__ == '__main__':
|
|
dir_list = ["./ViolenceDataset/video/Violence/", "./ViolenceDataset/video/NonViolence/"]
|
|
dir_list_out = ["./ViolenceDataset/image/Violence/", "./ViolenceDataset/image/NonViolence/"]
|
|
for k, src in enumerate(dir_list):
|
|
video_list = os.listdir(src)
|
|
i = 1
|
|
for video in video_list:
|
|
video = dir_list[k] + video
|
|
vidcap = cv.VideoCapture(video)
|
|
|
|
#first read
|
|
success, image = vidcap.read()
|
|
count = 0
|
|
base = os.path.basename(video)
|
|
vname = os.path.splitext(base)[0]
|
|
|
|
prev_gray = cv.cvtColor(image, cv.COLOR_BGR2GRAY)
|
|
savepath = ""
|
|
|
|
while success:
|
|
count = count+1
|
|
|
|
success, image = vidcap.read()
|
|
if (success == False):
|
|
break
|
|
|
|
gray = cv.cvtColor(image, cv.COLOR_BGR2GRAY)
|
|
|
|
(score, diff) = compare_ssim(prev_gray, gray, full=True)
|
|
diff = (diff * 255).astype("uint8")
|
|
|
|
if (score < 0.85):
|
|
savepath = dir_list_out[k] + vname + "frame%05d.jpg" % count
|
|
cv.imwrite(savepath, image) # save frame as JPEG file
|
|
|
|
prev_gray = gray
|
|
count += 1
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
def main():
|
|
parser = argparse.ArgumentParser(description='image splite to train and validate for training ')
|
|
parser.add_argument('--infolder', type=str, help='image folder path ')
|
|
parser.add_argument('--classname', type=str, help='splite class name')
|
|
parser.add_argument('--step', type=int, help='step for loop')
|
|
parser.add_argument('--maxsample', type=int, help='max train data count')
|
|
|
|
args = parser.parse_args()
|
|
|
|
infolder = args.infolder
|
|
classname = args.classname
|
|
step = args.step
|
|
maxval = args.maxsample
|
|
|
|
|
|
traindir = "train/" + classname + "/"
|
|
validationdir = "validation/" + classname + "/"
|
|
|
|
try:
|
|
os.makedirs(traindir)
|
|
except OSError as e:
|
|
if e.errno != errno.EEXIST:
|
|
raise
|
|
try:
|
|
os.makedirs(validationdir)
|
|
except OSError as e:
|
|
if e.errno != errno.EEXIST:
|
|
raise
|
|
|
|
fileset = [file for file in glob.glob(infolder + "**/*.jpg", recursive=True)]
|
|
|
|
count = len(fileset)
|
|
i = 0
|
|
k = 0
|
|
for file in fileset:
|
|
if i % step == 0:
|
|
print(file)
|
|
fname = os.path.basename(file)
|
|
if k % 10 == 0: #test
|
|
destination_file = validationdir + fname
|
|
else:#train
|
|
destination_file = traindir + fname
|
|
|
|
try:
|
|
srcimg = cv2.imread(file)
|
|
dstimg = cv2.resize(srcimg, (224, 224), interpolation=cv2.INTER_CUBIC)
|
|
cv2.imwrite(destination_file, dstimg)
|
|
#copyfile(file, destination_file)
|
|
|
|
except:
|
|
pass
|
|
|
|
k = k + 1
|
|
|
|
if k >= maxval:
|
|
break
|
|
|
|
i = i + 1
|
|
progress(i, count, status='processing')
|
|
|
|
|
|
print("\nTask Completed")
|
|
|
|
|
|
if __name__== "__main__":
|
|
main()
|