-
Notifications
You must be signed in to change notification settings - Fork 0
/
simgleCam.py
64 lines (52 loc) · 1.67 KB
/
simgleCam.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
import os
import urllib
import time
import sched
from PIL import Image
import numpy as np
dataset=[]
def downImg(url, path):
try:
urllib.request.urlretrieve(url=url, filename=path)
im = Image.open(path)
(x, y) = im.size
##reshape image
x_s = 40
y_s = 30
out = im.resize((x_s, y_s), Image.ANTIALIAS)
im2 = np.array(out)
## fix the channels of images
if (len(im2.shape) < 3):
imx = np.ndarray([im2.shape[0], im2.shape[1], 3])
for x in range(im2.shape[0]):
for y in range(im2.shape[1]):
imx[x][y][0] = im2[x][y]
imx[x][y][1] = im2[x][y]
imx[x][y][2] = im2[x][y]
else:
imx = im2
dataset.append(imx)
except Exception as e:
print(e)
return dataset
if not os.path.exists('singleCamImg'):
os.makedirs('singleCamImg')
exampleurl = 'http://207.251.86.238/cctv202.jpg'
outpath = 'singleCamImg/'
timewait = 600 ## take image per 20 minutes
def download():
schedule = sched.scheduler(time.time, time.sleep)
i=0
while(1):
# path = outpath + time.strftime("%Y%m%d-%H-%M-%S.jpg", time.localtime(time.time()))
path = outpath +"%d.jpg"%i
print(path)
schedule.enter(timewait, 0, downImg, (exampleurl, path))
schedule.run()
i+=1
if(i%10==0):
np.save('./nightnpy/single_img_x.npy' , dataset)
arr = np.load('./nightnpy/single_img_x.npy' , allow_pickle=True)
print(arr.shape)
if __name__ == "__main__":
download()