-
Notifications
You must be signed in to change notification settings - Fork 2
/
disease_det_script.py
45 lines (37 loc) · 1.2 KB
/
disease_det_script.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
from sklearn.ensemble import RandomForestClassifier
import pickle
import time
import cv2
import urllib.request
import numpy as np
import requests
from dotenv import load_dotenv
import os
load_dotenv()
api_key = os.getenv("write_api_key")
loaded_model = None
with open('RF_Model_Trained.pkl', 'rb') as f:
loaded_model = pickle.load(f)
link_for_image = "Enter the url from the ESP32_Program for the camera image"
while(True):
rtimg = urllib.request.urlopen(link_for_image)
rtimgnp = np.array(bytearray(rtimg.read()),dtype=np.uint8)
rtimgFINAL = cv2.imdecode(rtimgnp,-1)
rtimgFINAL = cv2.cvtColor(rtimgFINAL, cv2.COLOR_BGR2GRAY)
resizeIMG = cv2.resize(rtimgFINAL,(224,224), interpolation = cv2.INTER_LINEAR)
flattened_img = resizeIMG.flatten()
predict_img = [flattened_img]
ans = loaded_model.predict(predict_img)
give = None
if ans[0] == "cordana":
give = 1
elif ans[0] == "pestalotiopsis":
give = 2
elif ans[0] == "sigatoka":
give = 3
else:
give = 4
print(give)
print(ans)
requests.get('https://api.thingspeak.com/update?api_key='+ api_key +'&field4='+str(give))
time.sleep(5)