-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathstep1.py
147 lines (111 loc) · 2.88 KB
/
step1.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
from vicks import binary_data as bd
from vicks import split_file as sf
import qrcode, os, cv2, shutil
from PIL import Image
import urllib.request
try:
os.mkdir('vicks/output')
except Exception as e:
pass
try:
os.mkdir('output')
except Exception as e:
pass
try:
os.mkdir("vicks/video")
except Exception as e:
pass
def txt2QR(i):
img = qrcode.QRCode(
version=2,
error_correction=qrcode.constants.ERROR_CORRECT_L,
box_size=100,
border=5,
)
file = f'vicks/output/{i}'
try:
os.mkdir(f"output/{folder}")
except Exception as e:
pass
try:
with open(file, 'r', encoding="utf-8") as f:
data = f.read()
except:
with open('input/' + i, 'rb') as f:
data = f.read()
# print(data)
try:
img.add_data(data)
img.make(fit=True)
image = img.make_image(fill_color="black", back_color="white")
photo = f"output/{folder}/{i.split('.')[0]}.jpg"
image.save(photo)
except Exception as e:
# print(e)
pass
def frame2video(path):
mean_height = 0
mean_width = 0
dirfiles = os.listdir(path)
dirfiles.sort(key=lambda f: int(f.split('.')[0]))
num_of_images = len(dirfiles)
print(f'\nNumber of Images = {num_of_images}')
for file in dirfiles:
im = Image.open(os.path.join(path, file))
width, height = im.size
mean_width += width
mean_height += height
mean_width = int(mean_width / num_of_images)
mean_height = int(mean_height / num_of_images)
video_name = f'video/{folder}.avi'
images = [
img for img in dirfiles
if img.endswith(".jpg") or
img.endswith(".jpeg") or
img.endswith("png")
]
frame = cv2.imread(os.path.join(path, images[0]))
height, width, layers = frame.shape
ospath = os.path.join('vicks', video_name)
video = cv2.VideoWriter(ospath, 0, 1, (width, height))
print()
for image in images:
print('Writing for ', image)
video.write(cv2.imread(os.path.join(path, image)))
bd.compress_zip(ospath)
# print(ospath)
# bd.framerate(ospath, ospath + '.mp4')
cv2.destroyAllWindows()
video.release()
if __name__=='__main__':
Image.MAX_IMAGE_PIXELS = 933120000
# filename = 'input/really_big_file.txt'
filename = input('Enter `URL` or file `name` from input folder : ')
try:
file = f"{os.path.basename(filename)}"
filepath = os.path.join('input', file)
urllib.request.urlretrieve(filename.replace(' ', '%20'), filepath)
except:
file = filename
out_directory = in_directory = 'input/'
inp_file = in_directory + file
folder = inp_file.split('/')[1]
bd.save_binary(in_directory, out_directory, file)
inp_file = in_directory + 'UNIQUE.txt'
try:
sf.split(inp_file)
dirFiles = os.listdir('vicks/output')
dirFiles.sort(key=lambda f: int(f.split('.')[0]))
for i in dirFiles[:]:
print(i)
try:
txt2QR(i)
except:
pass
frame2video(f"output/{folder}")
except Exception as e:
path = '1.jpg'
print(e)
txt2QR(path)
input('\n\tPress any key to delete splitter text folder')
shutil.rmtree('vicks/output')