-
Notifications
You must be signed in to change notification settings - Fork 6
/
updater.py
125 lines (100 loc) · 3.74 KB
/
updater.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
# import matplotlib.pyplot as plt
from scipy.misc import imread, imshow
import numpy as np
from PIL import Image
from keras.models import load_model
from keras.engine.topology import Layer, InputSpec
from custom import LocalResponseNormalization
import cv2
import os
from os.path import isfile, join, exists
import socket
import time
import sys
import shutil
import requests
import json
import pandas as pd
def updater(database):
print("updater_check")
if exists('add_database.csv'):
new_data = pd.read_pickle('add_database.csv')
new_data.coordinates = new_data.coordinates.apply(lambda s: json.loads(s))
new_data.available = new_data.available.apply(lambda s:json.loads(s))
database = database.append(new_data, ignore_index=True)
os.remove('add_database.csv')
database.to_pickle('database.csv',index=False)
# print(database)
print(database)
for index,row in database.iterrows():
spot_id = str(row['spot_id'])
url = "https://api.dropboxapi.com/2/files/list_folder"
payload = f"{{\"path\": \"/Apps/IP Webcam/{spot_id}\"}}"
headers = {
'authorization': "Bearer ICLv-EbdL4AAAAAAAAAKAk5IlZiYC5Utddov30v9c0-C_0lrtMY0Y9iZFmsfmK8J",
'content-type': "application/json",
'cache-control': "no-cache"
}
response = requests.request("POST", url, data=payload, headers=headers)
response = response.json()
photos = []
for dic in response['entries']:
photos.append(dic['name'])
photos = sorted(photos)
url = "https://content.dropboxapi.com/2/files/download"
headers = {
'authorization': "Bearer ICLv-EbdL4AAAAAAAAAKAk5IlZiYC5Utddov30v9c0-C_0lrtMY0Y9iZFmsfmK8J",
'dropbox-api-arg': f"{{\"path\": \"/Apps/IP Webcam/{spot_id}/{photos[-1]}\"}}",
'cache-control': "no-cache",
'postman-token': "07aafc5e-9960-4da2-e328-66f0aa434802"
}
response = requests.request("POST", url, headers=headers, stream = True)
IMAGE_DIR = 'images/dropbox_image.jpeg'
with open(IMAGE_DIR, 'wb') as f:
shutil.copyfileobj(response.raw, f)
MAGIC = "face600d"
counter = 0
server_host = "192.168.43.20"
server_port = 5000
total_time = 0
CHECKPOINT_DIR = 'test_model/weights/checkpoint-07-0.07.hdf5'
if not exists(IMAGE_DIR):
print('Image file missing... Exiting!!')
sys.exit(0)
if not exists(CHECKPOINT_DIR):
print('Checkpoint file missing... Exiting!!')
sys.exit(0)
#print('kuna')
model = load_model(CHECKPOINT_DIR, custom_objects={'LocalResponseNormalization': LocalResponseNormalization})
while True:
im = imread(IMAGE_DIR)
# imshow(im)
im = Image.fromarray(im)
im = im.resize((500, 400))
im = np.array(im)
images = []
for cord in row['coordinates']:
print(cord)
#print('*****************')
im_ = Image.fromarray(im[cord[1]:cord[3],cord[0]:cord[2]])
im_ = im_.resize((54, 32))
im_ = np.array(im_)
im_ = im_.transpose(1,0,2)
images.append(im_)
images = np.array(images)
predictions = model.predict(images, verbose=1)
# print(predictions)
predictions = np.hstack(predictions < 0.5).astype(int)
print(predictions)
predictions = 1 - predictions
database.at[index,'available'] = predictions
database.at[index,'slot_available'] = np.sum(predictions)
print(database)
# i = 0
# im_ = np.copy(im)
# for cord in row['coordinates']:
# im_ = cv2.rectangle(im_,(cord[0],cord[1]),(cord[2],cord[3]),(255*int(predictions[i]),255*int(1-predictions[i]),0),2)
# i += 1
# plt.imshow(im_)
break
return database