update,
This commit is contained in:
44
vinniesniper-54816/task1/_lab/003-crawler-mountain/import_img.py
Executable file
44
vinniesniper-54816/task1/_lab/003-crawler-mountain/import_img.py
Executable file
@@ -0,0 +1,44 @@
|
||||
import glob
|
||||
import os
|
||||
import shutil
|
||||
import cv2
|
||||
|
||||
def merge_images(input_folder, output_folder):
|
||||
if not os.path.exists(output_folder):
|
||||
os.mkdir(output_folder)
|
||||
|
||||
count = 0
|
||||
for root, _, filenames in os.walk(input_folder):
|
||||
for fn in filenames:
|
||||
try:
|
||||
img = cv2.imread(os.path.join(root, fn))
|
||||
if img is None:
|
||||
os.remove(os.path.join(root, fn))
|
||||
continue
|
||||
|
||||
if fn.endswith('.jpg'):
|
||||
count += 1
|
||||
shutil.copy(os.path.join(root, fn), os.path.join(output_folder, 'c_{:010d}.jpg'.format(count)))
|
||||
|
||||
except Exception as e:
|
||||
os.remove(os.path.join(root, fn))
|
||||
continue
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
||||
for f in glob.glob('output/*.jpg'):
|
||||
os.remove(f)
|
||||
|
||||
for f in glob.glob(os.path.join('/home/logic/test/data/1xx_Beach', 'c_*.jpg')):
|
||||
os.remove(f)
|
||||
|
||||
merge_images('p/beach', 'output')
|
||||
|
||||
for f in glob.glob('output/*.jpg'):
|
||||
shutil.copy(f, '/home/logic/test/data/1xx_Beach')
|
||||
|
||||
print('beach done')
|
||||
|
||||
print('done')
|
||||
|
Reference in New Issue
Block a user