-
Notifications
You must be signed in to change notification settings - Fork 0
/
preprocess_spot.py
79 lines (55 loc) · 2.15 KB
/
preprocess_spot.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
import matplotlib.pyplot as plt
from matplotlib.pyplot import imread,imshow
import matplotlib.image as mpimg
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 numpy as np
# from google.colab import files
url = "https://api.dropboxapi.com/2/files/list_folder"
#************assign new directory with new_spot_idx in dropbox and upload image to this directory*************
new_spot_idx = 2 #update it
payload = f"{{\"path\": \"/Apps/IP Webcam/{new_spot_idx}\"}}"
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 = set()
for dic in response['entries']:
photos.add(dic['name'])
photos = sorted(list(photos))
url = "https://content.dropboxapi.com/2/files/download"
headers = {
'authorization': "Bearer ICLv-EbdL4AAAAAAAAAKAk5IlZiYC5Utddov30v9c0-C_0lrtMY0Y9iZFmsfmK8J",
'dropbox-api-arg': f"{{\"path\": \"/Apps/IP Webcam/{new_spot_idx}/{photos[-1]}\"}}",
'cache-control': "no-cache",
'postman-token': "07aafc5e-9960-4da2-e328-66f0aa434802"
}
response = requests.request("POST", url, headers=headers, stream = True)
IMAGE_DIR = 'preprocess_spot_image/new_dropbox_image.JPEG'
with open(IMAGE_DIR, 'wb') as f:
shutil.copyfileobj(response.raw, f)
im = plt.imread(IMAGE_DIR)
# imshow(im)
im = Image.fromarray(im)
im = im.resize((500, 400))
print(photos)
im.save(IMAGE_DIR)
imshow(im)
#################### download this image using ########################################################
# files.download(IMAGE_DIR)
######## now put downloaded/saved image from preprocess_image drectory to BBox-Label-Tool-master/Images/001 ###########
######## now update information in database for the registered parking spot ##############################