-
Notifications
You must be signed in to change notification settings - Fork 0
/
final.py
61 lines (47 loc) · 1.42 KB
/
final.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
# -*- coding: utf-8 -*-
"""
Created on Thu Mar 21 22:10:09 2019
@author: bzbri
"""
from PIL import Image
from PIL import ImageFilter
from PIL import ImageOps
from datetime import datetime
from keras.models import load_model
import requests
import json
import os
import cv2
import glob
send_url = "http://api.ipstack.com/check?access_key=ae5620e07d25c95d8baca860f7fdc0d6"
geo_req = requests.get(send_url)
geo_json = json.loads(geo_req.text)
latitude = geo_json['latitude']
longitude = geo_json['longitude']
time = datetime.now().strftime('%Y-%m-%d %H:%M:%S')
i = 0
j = 0
im_dir = r"images"
data_path = os.path.join(im_dir,'*g')
files = glob.glob(data_path)
model = load_model("model512PRE.h5")
for f in files:
i += 1
im = Image.open(f)
im = im.filter(ImageFilter.EDGE_ENHANCE)
im = ImageOps.autocontrast(im, cutoff=0, ignore=None)
im.save("temp"+str(i)+".png")
for n in range(i):
j += 1
img = cv2.imread("temp"+str(j)+".png",1)
img = cv2.resize(img,(64,64))
output = model.predict(img.reshape(-1,64,64,3))
if output[0][0]==1:
print("Hurricane:")
print("Latitude:",latitude)
print("Longitude:",longitude)
print("Time:",time)
cv2.imwrite("Hurricanes/Hurricane"+str(j)+".png",img)
elif output[0][1]==1:
print("Not a Hurricane")
os.remove("temp"+str(j)+".png")