From patchwork Tue May 12 00:03:06 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laurent Pinchart X-Patchwork-Id: 3762 Return-Path: Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id C332760E06 for ; Tue, 12 May 2020 02:03:36 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="V/4vdlED"; dkim-atps=neutral Received: from pendragon.bb.dnainternet.fi (81-175-216-236.bb.dnainternet.fi [81.175.216.236]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 2F8B633E; Tue, 12 May 2020 02:03:36 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1589241816; bh=7/qJinOFixS3KEwhlVNU115ZUmyJbfgzi5M4dr1t1vU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=V/4vdlEDy8K4D83omNP244/8q7ty64SmXYyZYwFsHWakyBYmg3sW/XcJlWfITnAGz 1ZrUlxrXMTeumBV2zmS/9KO2PJ7Mug8FmwfRwqYMYj4xXu0Akdn5jjUxhw8JrbGJpn CDA39KLHYX7fvxp/5NCwFOXms4gtB6MHlVIGbTsg= From: Laurent Pinchart To: libcamera-devel@lists.libcamera.org Date: Tue, 12 May 2020 03:03:06 +0300 Message-Id: <20200512000322.11753-9-laurent.pinchart@ideasonboard.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20200512000322.11753-1-laurent.pinchart@ideasonboard.com> References: <20200512000322.11753-1-laurent.pinchart@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH 08/24] utils: raspberrypi: ctt: Fix pycodestyle E225 X-BeenThere: libcamera-devel@lists.libcamera.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 12 May 2020 00:03:39 -0000 E225 missing whitespace around operator Signed-off-by: Laurent Pinchart --- utils/raspberrypi/ctt/ctt.py | 17 +++++++++-------- utils/raspberrypi/ctt/ctt_alsc.py | 12 ++++++------ utils/raspberrypi/ctt/ctt_awb.py | 14 +++++++------- utils/raspberrypi/ctt/ctt_ccm.py | 8 ++++---- utils/raspberrypi/ctt/ctt_macbeth_locator.py | 12 ++++++------ utils/raspberrypi/ctt/ctt_ransac.py | 4 ++-- 6 files changed, 34 insertions(+), 33 deletions(-) diff --git a/utils/raspberrypi/ctt/ctt.py b/utils/raspberrypi/ctt/ctt.py index 46cf92cd75a2..07230fe3f709 100755 --- a/utils/raspberrypi/ctt/ctt.py +++ b/utils/raspberrypi/ctt/ctt.py @@ -71,7 +71,7 @@ class Camera: self.path = '' self.imgs = [] 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.jf = jfile """ @@ -227,7 +227,7 @@ class Camera: cal_cb_list = self.json['rpi.alsc']['calibrations_Cb'] self.log += '\nALSC tables found successfully' 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('Performing CCM calibrations without ALSC correction...') 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 """ - 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 += 'performed without ALSC correction...' @@ -292,13 +292,13 @@ class Camera: cal_cb_list = self.json['rpi.alsc']['calibrations_Cb'] self.log += '\nALSC tables found successfully' 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('Performing AWB without ALSC tables') self.log += '\nWARNING: No ALSC tables found.\nAWB calibration ' self.log += 'performed without ALSC correction...' 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 += 'performed without ALSC correction...' """ @@ -502,9 +502,9 @@ class Camera: for key in disable: try: del self.json[key] - self.log += '\nDisabled: '+key + self.log += '\nDisabled: ' + key 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 """ @@ -685,7 +685,8 @@ class Camera: blacklevels = list(set([Img.blacklevel_16 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.blacklevel_16 = blacklevels[0] self.log += '\nName: {}'.format(camNames[0]) diff --git a/utils/raspberrypi/ctt/ctt_alsc.py b/utils/raspberrypi/ctt/ctt_alsc.py index a006f7ffa9c9..d6e1020f1ccc 100644 --- a/utils/raspberrypi/ctt/ctt_alsc.py +++ b/utils/raspberrypi/ctt/ctt_alsc.py @@ -61,10 +61,10 @@ def alsc_all(Cam, do_alsc_colour, plot): """ force numbers to be stored to 3dp.... :( """ - 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_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_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_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_r = np.round(t_r, 3) t_b = np.round(t_b, 3) 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 """ 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.95, 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 = list(np.round(lum_lut, 3)) """ diff --git a/utils/raspberrypi/ctt/ctt_awb.py b/utils/raspberrypi/ctt/ctt_awb.py index 297ba178b35f..3abafbf550b0 100644 --- a/utils/raspberrypi/ctt/ctt_awb.py +++ b/utils/raspberrypi/ctt/ctt_awb.py @@ -27,8 +27,8 @@ def awb(Cam, cal_cr_list, cal_cb_list, plot): """ normalise tables so min value is 1 """ - cr_tab= cr_tab/np.min(cr_tab) - cb_tab= cb_tab/np.min(cb_tab) + cr_tab = cr_tab/np.min(cr_tab) + cb_tab = cb_tab/np.min(cb_tab) colour_cals[cr['ct']] = [cr_tab, cb_tab] """ obtain data from greyscale macbeth patches @@ -183,10 +183,10 @@ def awb(Cam, cal_cr_list, cal_cb_list, plot): """ 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.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.95, b_fit-0.0001, b_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) + 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) r_fit = np.round(r_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 note that in python false = 0 and true = 1 """ - bad = i - (error_1=0.95, 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) ccm_tab[k] = list(np.round(tab, 5)) Cam.log += '\nMatrix calculated for colour temperature of {} K'.format(k) diff --git a/utils/raspberrypi/ctt/ctt_macbeth_locator.py b/utils/raspberrypi/ctt/ctt_macbeth_locator.py index 63dbc4a1f347..c3016f9a3c1d 100644 --- a/utils/raspberrypi/ctt/ctt_macbeth_locator.py +++ b/utils/raspberrypi/ctt/ctt_macbeth_locator.py @@ -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 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_h = 80 rc1 = (0, 0) @@ -328,7 +328,7 @@ def get_macbeth_chart(img, ref_data): """ src = img src, factor = reshape(src, 200) - original=src.copy() + original = src.copy() a = 125/np.average(src) src_norm = cv2.convertScaleAbs(src, alpha=a, beta=0) """ @@ -349,7 +349,7 @@ def get_macbeth_chart(img, ref_data): """ obtain image edges """ - sigma=2 + sigma = 2 src_bw = cv2.GaussianBlur(src_bw, (0, 0), sigma) t1, t2 = 50, 100 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] - if len(mac_mids_list)==1: + if len(mac_mids_list) == 1: """ 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 """ clus_list = [] - if clustering.n_clusters_ >1: + if clustering.n_clusters_ > 1: for i in range(clustering.labels_.max()+1): indices = [j for j, x in enumerate(clustering.labels_) if x == i] clus = [] @@ -535,7 +535,7 @@ def get_macbeth_chart(img, ref_data): keep only clusters with enough votes """ clus_len_max = clus_list[0][1] - clus_tol= 0.7 + clus_tol = 0.7 for i in range(len(clus_list)): if clus_list[i][1] < clus_len_max * clus_tol: clus_list = clus_list[:i] diff --git a/utils/raspberrypi/ctt/ctt_ransac.py b/utils/raspberrypi/ctt/ctt_ransac.py index a1f5e8c95ac1..392275445c14 100644 --- a/utils/raspberrypi/ctt/ctt_ransac.py +++ b/utils/raspberrypi/ctt/ctt_ransac.py @@ -42,8 +42,8 @@ def get_square_verts(c_err=0.05, scale=scale): for i in range(6): shift_i = np.array(((i*side, 0), (i*side, 0), (i*side, 0), (i*side, 0)), np.float32) - shift_bord =np.array(((i*s_bord, 0), (i*s_bord, 0), - (i*s_bord, 0), (i*s_bord, 0)), np.float32) + shift_bord = np.array(((i*s_bord, 0), (i*s_bord, 0), + (i*s_bord, 0), (i*s_bord, 0)), np.float32) square_i = square_0 + shift_i + shift_bord for j in range(4): shift_j = np.array(((0, j*side), (0, j*side),