utils: raspberrypi: ctt: Fix pycodestyle E225

E225 missing whitespace around operator

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
Reviewed-by: David Plowman <david.plowman@raspberrypi.com>
This commit is contained in:
Laurent Pinchart 2020-05-02 03:32:00 +03:00
parent 23f9f46c8a
commit 641c6ebe9b
6 changed files with 34 additions and 33 deletions

View file

@ -71,7 +71,7 @@ class Camera:
self.path = '' self.path = ''
self.imgs = [] self.imgs = []
self.imgs_alsc = [] self.imgs_alsc = []
self.log = 'Log created : '+ time.asctime(time.localtime(time.time())) self.log = 'Log created : ' + time.asctime(time.localtime(time.time()))
self.log_separator = '\n'+'-'*70+'\n' self.log_separator = '\n'+'-'*70+'\n'
self.jf = jfile self.jf = jfile
""" """
@ -227,7 +227,7 @@ class Camera:
cal_cb_list = self.json['rpi.alsc']['calibrations_Cb'] cal_cb_list = self.json['rpi.alsc']['calibrations_Cb']
self.log += '\nALSC tables found successfully' self.log += '\nALSC tables found successfully'
except KeyError: except KeyError:
cal_cr_list, cal_cb_list=None, None cal_cr_list, cal_cb_list = None, None
print('WARNING! No ALSC tables found for CCM!') print('WARNING! No ALSC tables found for CCM!')
print('Performing CCM calibrations without ALSC correction...') print('Performing CCM calibrations without ALSC correction...')
self.log += '\nWARNING: No ALSC tables found.\nCCM calibration ' self.log += '\nWARNING: No ALSC tables found.\nCCM calibration '
@ -236,7 +236,7 @@ class Camera:
""" """
case where config options result in CCM done without ALSC colour tables case where config options result in CCM done without ALSC colour tables
""" """
cal_cr_list, cal_cb_list=None, None cal_cr_list, cal_cb_list = None, None
self.log += '\nWARNING: No ALSC tables found.\nCCM calibration ' self.log += '\nWARNING: No ALSC tables found.\nCCM calibration '
self.log += 'performed without ALSC correction...' self.log += 'performed without ALSC correction...'
@ -292,13 +292,13 @@ class Camera:
cal_cb_list = self.json['rpi.alsc']['calibrations_Cb'] cal_cb_list = self.json['rpi.alsc']['calibrations_Cb']
self.log += '\nALSC tables found successfully' self.log += '\nALSC tables found successfully'
except KeyError: except KeyError:
cal_cr_list, cal_cb_list=None, None cal_cr_list, cal_cb_list = None, None
print('ERROR, no ALSC calibrations found for AWB') print('ERROR, no ALSC calibrations found for AWB')
print('Performing AWB without ALSC tables') print('Performing AWB without ALSC tables')
self.log += '\nWARNING: No ALSC tables found.\nAWB calibration ' self.log += '\nWARNING: No ALSC tables found.\nAWB calibration '
self.log += 'performed without ALSC correction...' self.log += 'performed without ALSC correction...'
else: else:
cal_cr_list, cal_cb_list=None, None cal_cr_list, cal_cb_list = None, None
self.log += '\nWARNING: No ALSC tables found.\nAWB calibration ' self.log += '\nWARNING: No ALSC tables found.\nAWB calibration '
self.log += 'performed without ALSC correction...' self.log += 'performed without ALSC correction...'
""" """
@ -502,9 +502,9 @@ class Camera:
for key in disable: for key in disable:
try: try:
del self.json[key] del self.json[key]
self.log += '\nDisabled: '+key self.log += '\nDisabled: ' + key
except KeyError: except KeyError:
self.log += '\nERROR: '+key +' not found!' self.log += '\nERROR: ' + key + ' not found!'
""" """
writes the json dictionary to the raw json file then make pretty writes the json dictionary to the raw json file then make pretty
""" """
@ -685,7 +685,8 @@ class Camera:
blacklevels = list(set([Img.blacklevel_16 for Img in all_imgs])) blacklevels = list(set([Img.blacklevel_16 for Img in all_imgs]))
sizes = list(set([(Img.w, Img.h) for Img in all_imgs])) sizes = list(set([(Img.w, Img.h) for Img in all_imgs]))
if len(camNames)==1 and len(patterns)==1 and len(sigbitss)==1 and len(blacklevels) ==1 and len(sizes)== 1: if len(camNames) == 1 and len(patterns) == 1 and len(sigbitss) == 1 and \
len(blacklevels) == 1 and len(sizes) == 1:
self.grey = (patterns[0] == 128) self.grey = (patterns[0] == 128)
self.blacklevel_16 = blacklevels[0] self.blacklevel_16 = blacklevels[0]
self.log += '\nName: {}'.format(camNames[0]) self.log += '\nName: {}'.format(camNames[0])

View file

@ -61,10 +61,10 @@ def alsc_all(Cam, do_alsc_colour, plot):
""" """
force numbers to be stored to 3dp.... :( force numbers to be stored to 3dp.... :(
""" """
t_r = np.where((100*t_r)%1<=0.05, t_r+0.001, t_r) t_r = np.where((100*t_r)%1 <= 0.05, t_r+0.001, t_r)
t_b = np.where((100*t_b)%1<=0.05, t_b+0.001, t_b) t_b = np.where((100*t_b)%1 <= 0.05, t_b+0.001, t_b)
t_r = np.where((100*t_r)%1>=0.95, t_r-0.001, t_r) t_r = np.where((100*t_r)%1 >= 0.95, t_r-0.001, t_r)
t_b = np.where((100*t_b)%1>=0.95, t_b-0.001, t_b) t_b = np.where((100*t_b)%1 >= 0.95, t_b-0.001, t_b)
t_r = np.round(t_r, 3) t_r = np.round(t_r, 3)
t_b = np.round(t_b, 3) t_b = np.round(t_b, 3)
r_corners = (t_r[0], t_r[15], t_r[-1], t_r[-16]) r_corners = (t_r[0], t_r[15], t_r[-1], t_r[-16])
@ -95,8 +95,8 @@ def alsc_all(Cam, do_alsc_colour, plot):
average all values for luminance shading and return one table for all temperatures average all values for luminance shading and return one table for all temperatures
""" """
lum_lut = np.mean(list_cg, axis=0) lum_lut = np.mean(list_cg, axis=0)
lum_lut = np.where((100*lum_lut)%1<=0.05, lum_lut+0.001, lum_lut) lum_lut = np.where((100*lum_lut)%1 <= 0.05, lum_lut+0.001, lum_lut)
lum_lut = np.where((100*lum_lut)%1>=0.95, lum_lut-0.001, lum_lut) lum_lut = np.where((100*lum_lut)%1 >= 0.95, lum_lut-0.001, lum_lut)
lum_lut = list(np.round(lum_lut, 3)) lum_lut = list(np.round(lum_lut, 3))
""" """

View file

@ -27,8 +27,8 @@ def awb(Cam, cal_cr_list, cal_cb_list, plot):
""" """
normalise tables so min value is 1 normalise tables so min value is 1
""" """
cr_tab= cr_tab/np.min(cr_tab) cr_tab = cr_tab/np.min(cr_tab)
cb_tab= cb_tab/np.min(cb_tab) cb_tab = cb_tab/np.min(cb_tab)
colour_cals[cr['ct']] = [cr_tab, cb_tab] colour_cals[cr['ct']] = [cr_tab, cb_tab]
""" """
obtain data from greyscale macbeth patches obtain data from greyscale macbeth patches
@ -183,10 +183,10 @@ def awb(Cam, cal_cr_list, cal_cb_list, plot):
""" """
round to 4dp round to 4dp
""" """
r_fit = np.where((1000*r_fit)%1<=0.05, r_fit+0.0001, r_fit) r_fit = np.where((1000*r_fit)%1 <= 0.05, r_fit+0.0001, r_fit)
r_fit = np.where((1000*r_fit)%1>=0.95, r_fit-0.0001, r_fit) r_fit = np.where((1000*r_fit)%1 >= 0.95, r_fit-0.0001, r_fit)
b_fit = np.where((1000*b_fit)%1<=0.05, b_fit+0.0001, b_fit) b_fit = np.where((1000*b_fit)%1 <= 0.05, b_fit+0.0001, b_fit)
b_fit = np.where((1000*b_fit)%1>=0.95, b_fit-0.0001, b_fit) b_fit = np.where((1000*b_fit)%1 >= 0.95, b_fit-0.0001, b_fit)
r_fit = np.round(r_fit, 4) r_fit = np.round(r_fit, 4)
b_fit = np.round(b_fit, 4) b_fit = np.round(b_fit, 4)
""" """
@ -215,7 +215,7 @@ def awb(Cam, cal_cr_list, cal_cb_list, plot):
find bad index find bad index
note that in python false = 0 and true = 1 note that in python false = 0 and true = 1
""" """
bad = i - (error_1<error_2) bad = i - (error_1 < error_2)
Cam.log += '\nPoint at {} K deleted as '.format(c_fit[bad]) Cam.log += '\nPoint at {} K deleted as '.format(c_fit[bad])
Cam.log += 'it is furthest from fit' Cam.log += 'it is furthest from fit'
""" """

View file

@ -74,8 +74,8 @@ def ccm(Cam, cal_cr_list, cal_cb_list):
""" """
normalise tables so min value is 1 normalise tables so min value is 1
""" """
cr_tab= cr_tab/np.min(cr_tab) cr_tab = cr_tab/np.min(cr_tab)
cb_tab= cb_tab/np.min(cb_tab) cb_tab = cb_tab/np.min(cb_tab)
colour_cals[cr['ct']] = [cr_tab, cb_tab] colour_cals[cr['ct']] = [cr_tab, cb_tab]
""" """
@ -135,8 +135,8 @@ def ccm(Cam, cal_cr_list, cal_cb_list):
""" """
for k, v in ccm_tab.items(): for k, v in ccm_tab.items():
tab = np.mean(v, axis=0) tab = np.mean(v, axis=0)
tab = np.where((10000*tab)%1<=0.05, tab+0.00001, tab) tab = np.where((10000*tab)%1 <= 0.05, tab+0.00001, tab)
tab = np.where((10000*tab)%1>=0.95, tab-0.00001, tab) tab = np.where((10000*tab)%1 >= 0.95, tab-0.00001, tab)
ccm_tab[k] = list(np.round(tab, 5)) ccm_tab[k] = list(np.round(tab, 5))
Cam.log += '\nMatrix calculated for colour temperature of {} K'.format(k) Cam.log += '\nMatrix calculated for colour temperature of {} K'.format(k)

View file

@ -40,7 +40,7 @@ def find_macbeth(Cam, img, mac_config=(0, 0)):
Reference macbeth chart is created that will be correlated with the located Reference macbeth chart is created that will be correlated with the located
macbeth chart guess to produce a confidence value for the match. macbeth chart guess to produce a confidence value for the match.
""" """
ref = cv2.imread(Cam.path +'ctt_ref.pgm', flags=cv2.IMREAD_GRAYSCALE) ref = cv2.imread(Cam.path + 'ctt_ref.pgm', flags=cv2.IMREAD_GRAYSCALE)
ref_w = 120 ref_w = 120
ref_h = 80 ref_h = 80
rc1 = (0, 0) rc1 = (0, 0)
@ -328,7 +328,7 @@ def get_macbeth_chart(img, ref_data):
""" """
src = img src = img
src, factor = reshape(src, 200) src, factor = reshape(src, 200)
original=src.copy() original = src.copy()
a = 125/np.average(src) a = 125/np.average(src)
src_norm = cv2.convertScaleAbs(src, alpha=a, beta=0) src_norm = cv2.convertScaleAbs(src, alpha=a, beta=0)
""" """
@ -349,7 +349,7 @@ def get_macbeth_chart(img, ref_data):
""" """
obtain image edges obtain image edges
""" """
sigma=2 sigma = 2
src_bw = cv2.GaussianBlur(src_bw, (0, 0), sigma) src_bw = cv2.GaussianBlur(src_bw, (0, 0), sigma)
t1, t2 = 50, 100 t1, t2 = 50, 100
edges = cv2.Canny(src_bw, t1, t2) edges = cv2.Canny(src_bw, t1, t2)
@ -490,7 +490,7 @@ def get_macbeth_chart(img, ref_data):
) )
mac_mids_list = [x[0] for x in mac_mids] mac_mids_list = [x[0] for x in mac_mids]
if len(mac_mids_list)==1: if len(mac_mids_list) == 1:
""" """
special case of only one valid centre found (probably not needed) special case of only one valid centre found (probably not needed)
""" """
@ -508,7 +508,7 @@ def get_macbeth_chart(img, ref_data):
create list of all clusters create list of all clusters
""" """
clus_list = [] clus_list = []
if clustering.n_clusters_ >1: if clustering.n_clusters_ > 1:
for i in range(clustering.labels_.max()+1): for i in range(clustering.labels_.max()+1):
indices = [j for j, x in enumerate(clustering.labels_) if x == i] indices = [j for j, x in enumerate(clustering.labels_) if x == i]
clus = [] clus = []
@ -535,7 +535,7 @@ def get_macbeth_chart(img, ref_data):
keep only clusters with enough votes keep only clusters with enough votes
""" """
clus_len_max = clus_list[0][1] clus_len_max = clus_list[0][1]
clus_tol= 0.7 clus_tol = 0.7
for i in range(len(clus_list)): for i in range(len(clus_list)):
if clus_list[i][1] < clus_len_max * clus_tol: if clus_list[i][1] < clus_len_max * clus_tol:
clus_list = clus_list[:i] clus_list = clus_list[:i]

View file

@ -42,7 +42,7 @@ def get_square_verts(c_err=0.05, scale=scale):
for i in range(6): for i in range(6):
shift_i = np.array(((i*side, 0), (i*side, 0), shift_i = np.array(((i*side, 0), (i*side, 0),
(i*side, 0), (i*side, 0)), np.float32) (i*side, 0), (i*side, 0)), np.float32)
shift_bord =np.array(((i*s_bord, 0), (i*s_bord, 0), shift_bord = np.array(((i*s_bord, 0), (i*s_bord, 0),
(i*s_bord, 0), (i*s_bord, 0)), np.float32) (i*s_bord, 0), (i*s_bord, 0)), np.float32)
square_i = square_0 + shift_i + shift_bord square_i = square_0 + shift_i + shift_bord
for j in range(4): for j in range(4):