Skip to content
This repository was archived by the owner on Jun 25, 2019. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 4 additions & 7 deletions rasp_app/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import time
import sqlite3 as lite
import scipy.signal as sps
from matplotlib.pylab import savefig
#from matplotlib.pylab import savefig
from PIL import Image
import datetime
from signal_processing import *
Expand Down Expand Up @@ -33,9 +33,6 @@ def data_taken():
TODO: return also machine learning prediction
"""

if( not os.path.isfile(HOME_PATH + '/white_cal.txt')):
return "NO,,White calibration is needed"

fruit = int(request.form.get('fruit'))
gps = request.form.get('gps')
if gps == None:
Expand Down Expand Up @@ -78,7 +75,7 @@ def take_data(fruit):
----------
- The confirmation HTML page
"""
if(not os.path.isfile(HOME_PATH + '/static/processed_white.jpg')):
if(not os.path.isfile(HOME_PATH + '/static/processed_white.png')):
get_white = 1
else:
get_white = 0
Expand Down Expand Up @@ -349,8 +346,8 @@ def calibrate_white_done():
os.system("mkdir " + HOME_PATH + '/configuration')
if(not os.path.isdir(HOME_PATH + '/temp_data')):
os.system("mkdir " + HOME_PATH + '/temp_data')
if(os.path.isfile(HOME_PATH + '/static/processed_white.jpg')):
os.system("rm " + HOME_PATH + '/static/processed_white.jpg')
if(os.path.isfile(HOME_PATH + '/static/processed_white.png')):
os.system("rm " + HOME_PATH + '/static/processed_white.png')
if(not os.path.isfile(HOME_PATH + '/timestamp.txt')):
out_file = open(HOME_PATH + '/timestamp.txt',"w")
out_file.write(str(0))
Expand Down
35 changes: 22 additions & 13 deletions rasp_app/signal_processing.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

HOME_PATH = os.path.dirname(os.path.abspath(__file__))

#This function could be also be deleted since it isn't used
def mins(array,wl):
"""
This function receive as input the spectrum and the wavelenghts.
Expand Down Expand Up @@ -140,7 +141,7 @@ def save_plot(array, wl=[],controls=0):
return script, div


def get_image(new_photo = 0, white_calibration = 0):
def get_image(new_photo = False, white_calibration = False):
"""
This function receive as input some parameters as a tuple.
The return value is the image of the spectrum.
Expand All @@ -166,13 +167,15 @@ def get_image(new_photo = 0, white_calibration = 0):
im=Image.open(HOME_PATH + '/source.jpg')
im=im.rotate(param[4])
im = im.crop(box=param[:4])

#We need to save the spectra as PNG because the JPG compress them altering the data
if white_calibration:
im.save(HOME_PATH + '/static/processed_white.jpg')
im.save(HOME_PATH + '/static/processed_white.png')
else:
im.save(HOME_PATH + '/static/processed.jpg')
im.save(HOME_PATH + '/static/processed.png')

#Better not to resize, data is lost or altered too much
#maxsize = (1000, im.size[0])
#Better not to resize, data is lost or altered too much
#im = im.resize(maxsize, Image.ANTIALIAS)

#im.show()
Expand Down Expand Up @@ -207,7 +210,7 @@ def filter_white(baseline):
----------
:value 0: List of y elements of the spectrum
"""
im=Image.open(HOME_PATH + '/source.jpg')
im=Image.open(HOME_PATH + '/static/processed_white.png')
img_white = im.load()

param=get_params()
Expand All @@ -221,10 +224,11 @@ def filter_white(baseline):
r,g,b = img_white[col,row]
tot[col].append(r+g+b)

for i in range(tot):
baseline = max(tot[i]) / baseline[i]
filtered = []
for to,ba in zip(tot,baseline):
filtered.append(max(to) / ba)

return baseline
return filtered

def get_baseline(img_spectrum):
"""
Expand Down Expand Up @@ -298,13 +302,18 @@ def process_image(white_spectrum = 0):
img_spectrum = get_image(new_photo=1)

baseline = get_baseline(img_spectrum)
filtered = filter_white(baseline)
#filtered = filter_white(baseline)

filtered = baseline #Uncomment not to use white calibration and get only raw values

#plt.plot(black_line, color="blue")
#print(baseline)
#print()
#print(filtered)
almost_good = sps.savgol_filter(filtered, 51, 3)
#plt.plot(almost_good, color="red")
#savefig(HOME_PATH + '/aabbbccc.png', bbox_inches='tight')
wl = np.array(range(400,801))
idx = mins(almost_good,wl)
wl = np.array(range(400,651))

background_rem = remove_background(almost_good)

Expand Down Expand Up @@ -360,8 +369,8 @@ def normalize(array, wl):
param = get_spectrum_param()
diff_param = param[1] - param[0]

begin = param[0] - diff_param * 0.75
end = param[1] + diff_param * 2.25
begin = param[0] - diff_param * 0.327
end = param[1] + diff_param * 0.945

begin_px = int(begin*len(array)/1000)
end_px = int(end*len(array)/1000)
Expand Down
21 changes: 0 additions & 21 deletions rasp_app/static/materialize/LICENSE

This file was deleted.

65 changes: 0 additions & 65 deletions rasp_app/static/materialize/README.md

This file was deleted.

5 changes: 0 additions & 5 deletions rasp_app/static/materialize/bin/materialize.js

This file was deleted.

Loading