From patchwork Tue May 12 00:02:59 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laurent Pinchart X-Patchwork-Id: 3755 Return-Path: Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 2C94260DF6 for ; Tue, 12 May 2020 02:03:33 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="Lpa/jcuf"; 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 63CAF11F3; Tue, 12 May 2020 02:03:32 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1589241812; bh=khQXwZhN7meBr+tHjIMKWGlF2A7d6PVCJ4BhbFHpZaI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Lpa/jcufHpL6xVM2i+gr+k3UeM+KQ9WnLJM1Va2Jx5UJmQxVmp5yXA/12CddjDyJQ G76rzNYjJY+0HRKKWzHFr46Hub928orxwmxWKS1pBJ6ClTEWd7qnGqXT77QWKb038V 7Ml1nUpJdtZjL4kb0R6WvhVl8XCDo6JqpFRl/eIk= From: Laurent Pinchart To: libcamera-devel@lists.libcamera.org Date: Tue, 12 May 2020 03:02:59 +0300 Message-Id: <20200512000322.11753-2-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 01/24] utils: raspberrypi: ctt: Fix pycodestyle E231 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:34 -0000 E231 missing whitespace after ',' E231 missing whitespace after ':' Signed-off-by: Laurent Pinchart --- utils/raspberrypi/ctt/ctt.py | 136 +++++------ utils/raspberrypi/ctt/ctt_alsc.py | 144 +++++------ utils/raspberrypi/ctt/ctt_awb.py | 118 ++++----- utils/raspberrypi/ctt/ctt_ccm.py | 52 ++-- utils/raspberrypi/ctt/ctt_geq.py | 48 ++-- utils/raspberrypi/ctt/ctt_image_load.py | 116 ++++----- utils/raspberrypi/ctt/ctt_lux.py | 16 +- utils/raspberrypi/ctt/ctt_macbeth_locator.py | 240 +++++++++---------- utils/raspberrypi/ctt/ctt_noise.py | 26 +- utils/raspberrypi/ctt/ctt_ransac.py | 52 ++-- utils/raspberrypi/ctt/ctt_tools.py | 38 +-- 11 files changed, 493 insertions(+), 493 deletions(-) diff --git a/utils/raspberrypi/ctt/ctt.py b/utils/raspberrypi/ctt/ctt.py index 5fe22e14f596..3674d3107966 100755 --- a/utils/raspberrypi/ctt/ctt.py +++ b/utils/raspberrypi/ctt/ctt.py @@ -41,15 +41,15 @@ def get_col_lux(string): """ Extract colour and lux values from filename """ - col = re.search('([0-9]+)[kK](\.(jpg|jpeg|brcm|dng)|_.*\.(jpg|jpeg|brcm|dng))$',string) - lux = re.search('([0-9]+)[lL](\.(jpg|jpeg|brcm|dng)|_.*\.(jpg|jpeg|brcm|dng))$',string) + col = re.search('([0-9]+)[kK](\.(jpg|jpeg|brcm|dng)|_.*\.(jpg|jpeg|brcm|dng))$', string) + lux = re.search('([0-9]+)[lL](\.(jpg|jpeg|brcm|dng)|_.*\.(jpg|jpeg|brcm|dng))$', string) try: col = col.group(1) except AttributeError: """ Catch error if images labelled incorrectly and pass reasonable defaults """ - return None,None + return None, None try: lux = lux.group(1) except AttributeError: @@ -57,15 +57,15 @@ def get_col_lux(string): Catch error if images labelled incorrectly and pass reasonable defaults Still returns colour if that has been found. """ - return col,None - return int( col ),int( lux ) + return col, None + return int( col ), int( lux ) """ Camera object that is the backbone of the tuning tool. Input is the desired path of the output json. """ class Camera: - def __init__(self,jfile): + def __init__(self, jfile): self.path = os.path.dirname(os.path.expanduser(__file__)) + '/' if self.path == '/': self.path = '' @@ -96,9 +96,9 @@ class Camera: }, "rpi.awb": { "priors" : [ - {"lux": 0,"prior":[ 2000, 1.0, 3000, 0.0, 13000, 0.0]}, - {"lux": 800,"prior":[ 2000, 0.0, 6000, 2.0, 13000, 2.0]}, - {"lux": 1500,"prior":[ 2000, 0.0, 4000, 1.0, 6000, 6.0, 6500, 7.0, 7000, 1.0, 13000, 1.0]} + {"lux": 0, "prior": [ 2000, 1.0, 3000, 0.0, 13000, 0.0]}, + {"lux": 800, "prior": [ 2000, 0.0, 6000, 2.0, 13000, 2.0]}, + {"lux": 1500, "prior": [ 2000, 0.0, 4000, 1.0, 6000, 6.0, 6500, 7.0, 7000, 1.0, 13000, 1.0]} ], "modes" : { "auto" : { "lo" : 2500, "hi" : 8000 }, @@ -189,7 +189,7 @@ class Camera: }, "rpi.ccm": { }, - "rpi.sharpen":{ + "rpi.sharpen": { } } @@ -198,7 +198,7 @@ class Camera: Perform colour correction calibrations by comparing macbeth patch colours to standard macbeth chart colours. """ - def ccm_cal(self,do_alsc_colour): + def ccm_cal(self, do_alsc_colour): if 'rpi.ccm' in self.disable: return 1 print('\nStarting CCM calibration') @@ -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...' @@ -244,7 +244,7 @@ class Camera: Do CCM calibration """ try: - ccms = ccm(self,cal_cr_list,cal_cb_list) + ccms = ccm(self, cal_cr_list, cal_cb_list) except ArithmeticError: print('ERROR: Matrix is singular!\nTake new pictures and try again...') self.log += '\nERROR: Singular matrix encountered during fit!' @@ -262,7 +262,7 @@ class Camera: various colour temperatures, as well as providing a maximum 'wiggle room' distance from this curve (transverse_neg/pos). """ - def awb_cal(self,greyworld,do_alsc_colour): + def awb_cal(self, greyworld, do_alsc_colour): if 'rpi.awb' in self.disable: return 1 print('\nStarting AWB calibration') @@ -292,21 +292,21 @@ 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...' """ call calibration function """ plot = "rpi.awb" in self.plot - awb_out = awb(self,cal_cr_list,cal_cb_list,plot) - ct_curve,transverse_neg,transverse_pos = awb_out + awb_out = awb(self, cal_cr_list, cal_cb_list, plot) + ct_curve, transverse_neg, transverse_pos = awb_out """ write output to json """ @@ -323,7 +323,7 @@ class Camera: colour channel seperately, and then partially corrects for vignetting. The extent of the correction depends on the 'luminance_strength' parameter. """ - def alsc_cal(self,luminance_strength,do_alsc_colour): + def alsc_cal(self, luminance_strength, do_alsc_colour): if 'rpi.alsc' in self.disable: return 1 print('\nStarting ALSC calibration') @@ -346,8 +346,8 @@ class Camera: call calibration function """ plot = "rpi.alsc" in self.plot - alsc_out = alsc_all(self,do_alsc_colour,plot) - cal_cr_list,cal_cb_list,luminance_lut,av_corn = alsc_out + alsc_out = alsc_all(self, do_alsc_colour, plot) + cal_cr_list, cal_cb_list, luminance_lut, av_corn = alsc_out """ write ouput to json and finish if not do_alsc_colour """ @@ -392,12 +392,12 @@ class Camera: """ obtain worst-case scenario residual sigmas """ - sigma_r,sigma_b = get_sigma(self,cal_cr_list,cal_cb_list) + sigma_r, sigma_b = get_sigma(self, cal_cr_list, cal_cb_list) """ write output to json """ - self.json['rpi.alsc']['sigma'] = np.round(sigma_r,5) - self.json['rpi.alsc']['sigma_Cb'] = np.round(sigma_b,5) + self.json['rpi.alsc']['sigma'] = np.round(sigma_r, 5) + self.json['rpi.alsc']['sigma_Cb'] = np.round(sigma_b, 5) self.log += '\nCalibrated sigmas written to json file' print('Finished ALSC calibrations') @@ -417,7 +417,7 @@ class Camera: perform calibration """ plot = 'rpi.geq' in self.plot - slope,offset = geq_fit(self,plot) + slope, offset = geq_fit(self, plot) """ write output to json """ @@ -441,7 +441,7 @@ class Camera: image with lux level closest to 1000 is chosen. """ luxes = [Img.lux for Img in self.imgs] - argmax = luxes.index(min(luxes, key=lambda l:abs(1000-l))) + argmax = luxes.index(min(luxes, key=lambda l: abs(1000-l))) Img = self.imgs[argmax] self.log += '\nLux found closest to 1000: {} lx'.format(Img.lux) self.log += '\nImage used: ' + Img.name @@ -450,7 +450,7 @@ class Camera: """ do calibration """ - lux_out,shutter_speed,gain = lux(self,Img) + lux_out, shutter_speed, gain = lux(self, Img) """ write output to json """ @@ -474,28 +474,28 @@ class Camera: run calibration on all images and sort by slope. """ plot = "rpi.noise" in self.plot - noise_out = sorted([noise(self,Img,plot) for Img in self.imgs], key = lambda x:x[0]) + noise_out = sorted([noise(self, Img, plot) for Img in self.imgs], key = lambda x: x[0]) self.log += '\nFinished processing images' """ take the average of the interquartile """ l = len(noise_out) - noise_out = np.mean(noise_out[l//4:1+3*l//4],axis=0) + noise_out = np.mean(noise_out[l//4:1+3*l//4], axis=0) self.log += '\nAverage noise profile: constant = {} '.format(int(noise_out[1])) self.log += 'slope = {:.3f}'.format(noise_out[0]) """ write to json """ self.json['rpi.noise']['reference_constant'] = int(noise_out[1]) - self.json['rpi.noise']['reference_slope'] = round(noise_out[0],3) + self.json['rpi.noise']['reference_slope'] = round(noise_out[0], 3) self.log += '\nNOISE calibrations written to json' print('Finished NOISE calibrations') """ Removes json entries that are turned off """ - def json_remove(self,disable): - self.log_new_sec('Disabling Options',cal=False) + def json_remove(self, disable): + self.log_new_sec('Disabling Options', cal=False) if len(self.disable) == 0: self.log += '\nNothing disabled!' return 1 @@ -512,16 +512,16 @@ class Camera: """ Write json dictionary to file """ - jstring = json.dumps(self.json,sort_keys=False) + jstring = json.dumps(self.json, sort_keys=False) """ make it pretty :) """ - pretty_print_json(jstring,self.jf) + pretty_print_json(jstring, self.jf) """ add a new section to the log file """ - def log_new_sec(self,section,cal=True): + def log_new_sec(self, section, cal=True): self.log += '\n'+self.log_separator self.log += section if cal: @@ -531,8 +531,8 @@ class Camera: """ write script arguments to log file """ - def log_user_input(self,json_output,directory,config,log_output): - self.log_new_sec('User Arguments',cal=False) + def log_user_input(self, json_output, directory, config, log_output): + self.log_new_sec('User Arguments', cal=False) self.log += '\nJson file output: ' + json_output self.log += '\nCalibration images directory: ' + directory if config == None: @@ -555,19 +555,19 @@ class Camera: """ write log file """ - def write_log(self,filename): + def write_log(self, filename): if filename == None: filename = 'ctt_log.txt' self.log += '\n' + self.log_separator - with open(filename,'w') as logfile: + with open(filename, 'w') as logfile: logfile.write(self.log) """ Add all images from directory, pass into relevant list of images and extrace lux and temperature values. """ - def add_imgs(self,directory,mac_config,blacklevel=-1): - self.log_new_sec('Image Loading',cal=False) + def add_imgs(self, directory, mac_config, blacklevel=-1): + self.log_new_sec('Image Loading', cal=False) img_suc_msg = 'Image loaded successfully!' print('\n\nLoading images from '+directory) self.log += '\nDirectory: ' + directory @@ -588,12 +588,12 @@ class Camera: """ obtain colour and lux value """ - col,lux = get_col_lux(filename) + col, lux = get_col_lux(filename) """ Check if image is an alsc calibration image """ if 'alsc' in filename: - Img = load_image(self,address,mac=False) + Img = load_image(self, address, mac=False) self.log += '\nIdentified as an ALSC image' """ check if imagae data has been successfully unpacked @@ -633,7 +633,7 @@ class Camera: self.log += '\nWARNING: Error reading lux value' self.log += '\nImage discarded!' continue - Img = load_image(self,address,mac_config) + Img = load_image(self, address, mac_config) """ check that image data has been successfuly unpacked """ @@ -645,7 +645,7 @@ class Camera: """ if successful, append to list and continue to next image """ - Img.col,Img.lux = col,lux + Img.col, Img.lux = col, lux Img.name = filename self.log += '\nColour temperature: {} K'.format(col) self.log += '\nLux value: {} lx'.format(lux) @@ -683,7 +683,7 @@ class Camera: patterns = list(set([Img.pattern for Img in all_imgs])) sigbitss = list(set([Img.sigbits 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: self.grey = (patterns[0] == 128) @@ -694,14 +694,14 @@ class Camera: self.log += '\nGreyscale camera identified' self.log += '\nSignificant bits: {}'.format(sigbitss[0]) self.log += '\nBlacklevel: {}'.format(blacklevels[0]) - self.log += '\nImage size: w = {} h = {}'.format(sizes[0][0],sizes[0][1]) + self.log += '\nImage size: w = {} h = {}'.format(sizes[0][0], sizes[0][1]) return 1 else: print('\nERROR: Images from different cameras') self.log += '\nERROR: Images are from different cameras' return 0 -def run_ctt(json_output,directory,config,log_output): +def run_ctt(json_output, directory, config, log_output): """ check input files are jsons """ @@ -717,7 +717,7 @@ def run_ctt(json_output,directory,config,log_output): read configurations """ try: - with open(config,'r') as config_json: + with open(config, 'r') as config_json: configs = json.load(config_json) except FileNotFoundError: configs = {} @@ -731,18 +731,18 @@ def run_ctt(json_output,directory,config,log_output): """ load configurations from config file, if not given then set default """ - disable = get_config(configs,"disable",[],'list') - plot = get_config(configs,"plot",[],'list') - awb_d = get_config(configs,"awb",{},'dict') - greyworld = get_config(awb_d,"greyworld",0,'bool') - alsc_d = get_config(configs,"alsc",{},'dict') - do_alsc_colour = get_config(alsc_d,"do_alsc_colour",1,'bool') - luminance_strength = get_config(alsc_d,"luminance_strength",0.5,'num') - blacklevel = get_config(configs,"blacklevel",-1,'num') - macbeth_d = get_config(configs,"macbeth",{},'dict') - mac_small = get_config(macbeth_d,"small",0,'bool') - mac_show = get_config(macbeth_d,"show",0,'bool') - mac_config = (mac_small,mac_show) + disable = get_config(configs, "disable", [], 'list') + plot = get_config(configs, "plot", [], 'list') + awb_d = get_config(configs, "awb", {}, 'dict') + greyworld = get_config(awb_d, "greyworld", 0, 'bool') + alsc_d = get_config(configs, "alsc", {}, 'dict') + do_alsc_colour = get_config(alsc_d, "do_alsc_colour", 1, 'bool') + luminance_strength = get_config(alsc_d, "luminance_strength", 0.5, 'num') + blacklevel = get_config(configs, "blacklevel", -1, 'num') + macbeth_d = get_config(configs, "macbeth", {}, 'dict') + mac_small = get_config(macbeth_d, "small", 0, 'bool') + mac_show = get_config(macbeth_d, "show", 0, 'bool') + mac_config = (mac_small, mac_show) if blacklevel < -1 or blacklevel >= 2**16: print('\nInvalid blacklevel, defaulted to 64') @@ -762,10 +762,10 @@ def run_ctt(json_output,directory,config,log_output): """ try: Cam = Camera(json_output) - Cam.log_user_input(json_output,directory,config,log_output) + Cam.log_user_input(json_output, directory, config, log_output) Cam.disable = disable Cam.plot = plot - Cam.add_imgs(directory,mac_config,blacklevel) + Cam.add_imgs(directory, mac_config, blacklevel) except FileNotFoundError: raise ArgError('\n\nError: Input image directory not found!') @@ -781,11 +781,11 @@ def run_ctt(json_output,directory,config,log_output): Cam.json['rpi.black_level']['black_level'] = Cam.blacklevel_16 Cam.json_remove(disable) print('\nSTARTING CALIBRATIONS') - Cam.alsc_cal(luminance_strength,do_alsc_colour) + Cam.alsc_cal(luminance_strength, do_alsc_colour) Cam.geq_cal() Cam.lux_cal() Cam.noise_cal() - Cam.awb_cal(greyworld,do_alsc_colour) + Cam.awb_cal(greyworld, do_alsc_colour) Cam.ccm_cal(do_alsc_colour) print('\nFINISHED CALIBRATIONS') Cam.write_json() @@ -819,5 +819,5 @@ if __name__ == '__main__': """ parse input arguments """ - json_output,directory,config,log_output = parse_input() - run_ctt(json_output,directory,config,log_output) + json_output, directory, config, log_output = parse_input() + run_ctt(json_output, directory, config, log_output) diff --git a/utils/raspberrypi/ctt/ctt_alsc.py b/utils/raspberrypi/ctt/ctt_alsc.py index fe1cff6588fa..cd99495f6bef 100644 --- a/utils/raspberrypi/ctt/ctt_alsc.py +++ b/utils/raspberrypi/ctt/ctt_alsc.py @@ -12,7 +12,7 @@ from mpl_toolkits.mplot3d import Axes3D """ preform alsc calibration on a set of images """ -def alsc_all(Cam,do_alsc_colour,plot): +def alsc_all(Cam, do_alsc_colour, plot): imgs_alsc = Cam.imgs_alsc """ create list of colour temperatures and associated calibration tables @@ -22,16 +22,16 @@ def alsc_all(Cam,do_alsc_colour,plot): list_cb = [] list_cg = [] for Img in imgs_alsc: - col,cr,cb,cg,size = alsc(Cam,Img,do_alsc_colour,plot) + col, cr, cb, cg, size = alsc(Cam, Img, do_alsc_colour, plot) list_col.append(col) list_cr.append(cr) list_cb.append(cb) list_cg.append(cg) Cam.log += '\n' Cam.log += '\nFinished processing images' - w,h,dx,dy = size - Cam.log += '\nChannel dimensions: w = {} h = {}'.format(int(w),int(h)) - Cam.log += '\n16x12 grid rectangle size: w = {} h = {}'.format(dx,dy) + w, h, dx, dy = size + Cam.log += '\nChannel dimensions: w = {} h = {}'.format(int(w), int(h)) + Cam.log += '\n16x12 grid rectangle size: w = {} h = {}'.format(dx, dy) """ convert to numpy array for data manipulation @@ -56,66 +56,66 @@ def alsc_all(Cam,do_alsc_colour,plot): """ indices = np.where(list_col == ct) ct = int(ct) - t_r = np.mean(list_cr[indices],axis=0) - t_b = np.mean(list_cb[indices],axis=0) + t_r = np.mean(list_cr[indices], axis=0) + t_b = np.mean(list_cb[indices], axis=0) """ 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.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]) - b_corners = (t_b[0],t_b[15],t_b[-1],t_b[-16]) + 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]) + b_corners = (t_b[0], t_b[15], t_b[-1], t_b[-16]) r_cen = t_r[5*16+7]+t_r[5*16+8]+t_r[6*16+7]+t_r[6*16+8] - r_cen = round(r_cen/4,3) + r_cen = round(r_cen/4, 3) b_cen = t_b[5*16+7]+t_b[5*16+8]+t_b[6*16+7]+t_b[6*16+8] - b_cen = round(b_cen/4,3) + b_cen = round(b_cen/4, 3) Cam.log += '\nRed table corners: {}'.format(r_corners) Cam.log += '\nRed table centre: {}'.format(r_cen) Cam.log += '\nBlue table corners: {}'.format(b_corners) Cam.log += '\nBlue table centre: {}'.format(b_cen) cr_dict = { - 'ct':ct, - 'table':list(t_r) + 'ct': ct, + 'table': list(t_r) } cb_dict = { - 'ct':ct, - 'table':list(t_b) + 'ct': ct, + 'table': list(t_b) } cal_cr_list.append(cr_dict) cal_cb_list.append(cb_dict) Cam.log += '\n' else: - cal_cr_list,cal_cb_list = None,None + cal_cr_list, cal_cb_list = None, None """ 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 = list(np.round(lum_lut,3)) + 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 = list(np.round(lum_lut, 3)) """ calculate average corner for lsc gain calculation further on """ - corners = (lum_lut[0],lum_lut[15],lum_lut[-1],lum_lut[-16]) + corners = (lum_lut[0], lum_lut[15], lum_lut[-1], lum_lut[-16]) Cam.log += '\nLuminance table corners: {}'.format(corners) l_cen = lum_lut[5*16+7]+lum_lut[5*16+8]+lum_lut[6*16+7]+lum_lut[6*16+8] - l_cen = round(l_cen/4,3) + l_cen = round(l_cen/4, 3) Cam.log += '\nLuminance table centre: {}'.format(l_cen) av_corn = np.sum(corners)/4 - return cal_cr_list,cal_cb_list,lum_lut,av_corn + return cal_cr_list, cal_cb_list, lum_lut, av_corn """ calculate g/r and g/b for 32x32 points arranged in a grid for a single image """ -def alsc(Cam,Img,do_alsc_colour,plot=False): +def alsc(Cam, Img, do_alsc_colour, plot=False): Cam.log += '\nProcessing image: ' + Img.name """ get channel in correct order @@ -126,31 +126,31 @@ def alsc(Cam,Img,do_alsc_colour,plot=False): -(-(w-1)//32) is a ceiling division. w-1 is to deal robustly with the case where w is a multiple of 32. """ - w,h = Img.w/2,Img.h/2 - dx,dy = int(-(-(w-1)//16)),int(-(-(h-1)//12)) + w, h = Img.w/2, Img.h/2 + dx, dy = int(-(-(w-1)//16)), int(-(-(h-1)//12)) """ average the green channels into one """ - av_ch_g = np.mean((channels[1:2]),axis = 0) + av_ch_g = np.mean((channels[1:2]), axis = 0) if do_alsc_colour: """ obtain 16x12 grid of intensities for each channel and subtract black level """ - g = get_16x12_grid(av_ch_g,dx,dy) - Img.blacklevel_16 - r = get_16x12_grid(channels[0],dx,dy) - Img.blacklevel_16 - b = get_16x12_grid(channels[3],dx,dy) - Img.blacklevel_16 + g = get_16x12_grid(av_ch_g, dx, dy) - Img.blacklevel_16 + r = get_16x12_grid(channels[0], dx, dy) - Img.blacklevel_16 + b = get_16x12_grid(channels[3], dx, dy) - Img.blacklevel_16 """ calculate ratios as 32 bit in order to be supported by medianBlur function """ - cr = np.reshape(g/r,(12,16)).astype('float32') - cb = np.reshape(g/b,(12,16)).astype('float32') - cg = np.reshape(1/g,(12,16)).astype('float32') + cr = np.reshape(g/r, (12, 16)).astype('float32') + cb = np.reshape(g/b, (12, 16)).astype('float32') + cg = np.reshape(1/g, (12, 16)).astype('float32') """ median blur to remove peaks and save as float 64 """ - cr = cv2.medianBlur(cr,3).astype('float64') - cb = cv2.medianBlur(cb,3).astype('float64') - cg = cv2.medianBlur(cg,3).astype('float64') + cr = cv2.medianBlur(cr, 3).astype('float64') + cb = cv2.medianBlur(cb, 3).astype('float64') + cg = cv2.medianBlur(cg, 3).astype('float64') cg = cg/np.min(cg) """ @@ -158,49 +158,49 @@ def alsc(Cam,Img,do_alsc_colour,plot=False): for sanity check """ if plot: - hf = plt.figure(figsize=(8,8)) + hf = plt.figure(figsize=(8, 8)) ha = hf.add_subplot(311, projection='3d') """ note Y is plotted as -Y so plot has same axes as image """ - X,Y = np.meshgrid(range(16),range(12)) - ha.plot_surface(X,-Y,cr,cmap=cm.coolwarm,linewidth=0) + X, Y = np.meshgrid(range(16), range(12)) + ha.plot_surface(X, -Y, cr, cmap=cm.coolwarm, linewidth=0) ha.set_title('ALSC Plot\nImg: {}\n\ncr'.format(Img.str)) hb = hf.add_subplot(312, projection='3d') - hb.plot_surface(X,-Y,cb,cmap=cm.coolwarm,linewidth=0) + hb.plot_surface(X, -Y, cb, cmap=cm.coolwarm, linewidth=0) hb.set_title('cb') hc = hf.add_subplot(313, projection='3d') - hc.plot_surface(X,-Y,cg,cmap=cm.coolwarm,linewidth=0) + hc.plot_surface(X, -Y, cg, cmap=cm.coolwarm, linewidth=0) hc.set_title('g') # print(Img.str) plt.show() - return Img.col,cr.flatten(),cb.flatten(),cg.flatten(),(w,h,dx,dy) + return Img.col, cr.flatten(), cb.flatten(), cg.flatten(), (w, h, dx, dy) else: """ only perform calculations for luminance shading """ - g = get_16x12_grid(av_ch_g,dx,dy) - Img.blacklevel_16 - cg = np.reshape(1/g,(12,16)).astype('float32') - cg = cv2.medianBlur(cg,3).astype('float64') + g = get_16x12_grid(av_ch_g, dx, dy) - Img.blacklevel_16 + cg = np.reshape(1/g, (12, 16)).astype('float32') + cg = cv2.medianBlur(cg, 3).astype('float64') cg = cg/np.min(cg) if plot: - hf = plt.figure(figssize=(8,8)) - ha = hf.add_subplot(1,1,1,projection='3d') - X,Y = np.meashgrid(range(16),range(12)) - ha.plot_surface(X,-Y,cg,cmap=cm.coolwarm,linewidth=0) + hf = plt.figure(figssize=(8, 8)) + ha = hf.add_subplot(1, 1, 1, projection='3d') + X, Y = np.meashgrid(range(16), range(12)) + ha.plot_surface(X, -Y, cg, cmap=cm.coolwarm, linewidth=0) ha.set_title('ALSC Plot (Luminance only!)\nImg: {}\n\ncg').format(Img.str) plt.show() - return Img.col,None,None,cg.flatten(),(w,h,dx,dy) + return Img.col, None, None, cg.flatten(), (w, h, dx, dy) """ Compresses channel down to a 16x12 grid """ -def get_16x12_grid(chan,dx,dy): +def get_16x12_grid(chan, dx, dy): grid = [] """ since left and bottom border will not necessarily have rectangles of @@ -208,11 +208,11 @@ def get_16x12_grid(chan,dx,dy): """ for i in range(11): for j in range(15): - grid.append(np.mean(chan[dy*i:dy*(1+i),dx*j:dx*(1+j)])) - grid.append(np.mean(chan[dy*i:dy*(1+i),15*dx:])) + grid.append(np.mean(chan[dy*i:dy*(1+i), dx*j:dx*(1+j)])) + grid.append(np.mean(chan[dy*i:dy*(1+i), 15*dx:])) for j in range(15): - grid.append(np.mean(chan[11*dy:,dx*j:dx*(1+j)])) - grid.append(np.mean(chan[11*dy:,15*dx:])) + grid.append(np.mean(chan[11*dy:, dx*j:dx*(1+j)])) + grid.append(np.mean(chan[11*dy:, 15*dx:])) """ return as np.array, ready for further manipulation """ @@ -221,7 +221,7 @@ def get_16x12_grid(chan,dx,dy): """ obtains sigmas for red and blue, effectively a measure of the 'error' """ -def get_sigma(Cam,cal_cr_list,cal_cb_list): +def get_sigma(Cam, cal_cr_list, cal_cb_list): Cam.log += '\nCalculating sigmas' """ provided colour alsc tables were generated for two different colour @@ -239,9 +239,9 @@ def get_sigma(Cam,cal_cr_list,cal_cb_list): sigma_rs = [] sigma_bs = [] for i in range(len(cts)-1): - sigma_rs.append(calc_sigma(cal_cr_list[i]['table'],cal_cr_list[i+1]['table'])) - sigma_bs.append(calc_sigma(cal_cb_list[i]['table'],cal_cb_list[i+1]['table'])) - Cam.log += '\nColour temperature interval {} - {} K'.format(cts[i],cts[i+1]) + sigma_rs.append(calc_sigma(cal_cr_list[i]['table'], cal_cr_list[i+1]['table'])) + sigma_bs.append(calc_sigma(cal_cb_list[i]['table'], cal_cb_list[i+1]['table'])) + Cam.log += '\nColour temperature interval {} - {} K'.format(cts[i], cts[i+1]) Cam.log += '\nSigma red: {}'.format(sigma_rs[-1]) Cam.log += '\nSigma blue: {}'.format(sigma_bs[-1]) @@ -254,19 +254,19 @@ def get_sigma(Cam,cal_cr_list,cal_cb_list): Cam.log += '\nMaximum sigmas: Red = {} Blue = {}'.format(sigma_r, sigma_b) - # print(sigma_rs,sigma_bs) - # print(sigma_r,sigma_b) - return sigma_r,sigma_b + # print(sigma_rs, sigma_bs) + # print(sigma_r, sigma_b) + return sigma_r, sigma_b """ calculate sigma from two adjacent gain tables """ -def calc_sigma(g1,g2): +def calc_sigma(g1, g2): """ reshape into 16x12 matrix """ - g1 = np.reshape(g1,(12,16)) - g2 = np.reshape(g2,(12,16)) + g1 = np.reshape(g1, (12, 16)) + g2 = np.reshape(g2, (12, 16)) """ apply gains to gain table """ @@ -294,4 +294,4 @@ def calc_sigma(g1,g2): return mean difference """ mean_diff = np.mean(diffs) - return(np.round(mean_diff,5)) + return(np.round(mean_diff, 5)) diff --git a/utils/raspberrypi/ctt/ctt_awb.py b/utils/raspberrypi/ctt/ctt_awb.py index d31306129a0c..9a92033bf2db 100644 --- a/utils/raspberrypi/ctt/ctt_awb.py +++ b/utils/raspberrypi/ctt/ctt_awb.py @@ -12,7 +12,7 @@ from scipy.optimize import fmin """ obtain piecewise linear approximation for colour curve """ -def awb(Cam,cal_cr_list,cal_cb_list,plot): +def awb(Cam, cal_cr_list, cal_cb_list, plot): imgs = Cam.imgs """ condense alsc calibration tables into one dictionary @@ -21,7 +21,7 @@ def awb(Cam,cal_cr_list,cal_cb_list,plot): colour_cals = None else: colour_cals = {} - for cr,cb in zip(cal_cr_list,cal_cb_list): + for cr, cb in zip(cal_cr_list, cal_cb_list): cr_tab = cr['table'] cb_tab = cb['table'] """ @@ -29,7 +29,7 @@ def awb(Cam,cal_cr_list,cal_cb_list,plot): """ cr_tab= cr_tab/np.min(cr_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 """ @@ -42,17 +42,17 @@ def awb(Cam,cal_cr_list,cal_cb_list,plot): Note: if alsc is disabled then colour_cals will be set to None and the function will just return the greyscale patches """ - r_patchs,b_patchs,g_patchs = get_alsc_patches(Img,colour_cals) + r_patchs, b_patchs, g_patchs = get_alsc_patches(Img, colour_cals) """ - calculate ratio of r,b to g + calculate ratio of r, b to g """ r_g = np.mean(r_patchs/g_patchs) b_g = np.mean(b_patchs/g_patchs) - Cam.log += '\n r : {:.4f} b : {:.4f}'.format(r_g,b_g) + Cam.log += '\n r : {:.4f} b : {:.4f}'.format(r_g, b_g) """ The curve tends to be better behaved in so-called hatspace. - R,B,G represent the individual channels. The colour curve is plotted in - r,b space, where: + R, B, G represent the individual channels. The colour curve is plotted in + r, b space, where: r = R/G b = B/G This will be referred to as dehatspace... (sorry) @@ -71,18 +71,18 @@ def awb(Cam,cal_cr_list,cal_cb_list,plot): """ r_g_hat = r_g/(1+r_g+b_g) b_g_hat = b_g/(1+r_g+b_g) - Cam.log += '\n r_hat : {:.4f} b_hat : {:.4f}'.format(r_g_hat,b_g_hat) - rbs_hat.append((r_g_hat,b_g_hat,Img.col)) - rb_raw.append((r_g,b_g)) + Cam.log += '\n r_hat : {:.4f} b_hat : {:.4f}'.format(r_g_hat, b_g_hat) + rbs_hat.append((r_g_hat, b_g_hat, Img.col)) + rb_raw.append((r_g, b_g)) Cam.log += '\n' Cam.log += '\nFinished processing images' """ sort all lits simultaneously by r_hat """ - rbs_zip = list(zip(rbs_hat,rb_raw)) - rbs_zip.sort(key=lambda x:x[0][0]) - rbs_hat,rb_raw = list(zip(*rbs_zip)) + rbs_zip = list(zip(rbs_hat, rb_raw)) + rbs_zip.sort(key=lambda x: x[0][0]) + rbs_hat, rb_raw = list(zip(*rbs_zip)) """ unzip tuples ready for processing """ @@ -91,7 +91,7 @@ def awb(Cam,cal_cr_list,cal_cb_list,plot): """ fit quadratic fit to r_g hat and b_g_hat """ - a,b,c = np.polyfit(rbs_hat[0],rbs_hat[1],2) + a, b, c = np.polyfit(rbs_hat[0], rbs_hat[1], 2) Cam.log += '\nFit quadratic curve in hatspace' """ the algorithm now approximates the shortest distance from each point to the @@ -113,11 +113,11 @@ def awb(Cam,cal_cr_list,cal_cb_list,plot): def f(x): return a*x**2 + b*x + c """ - iterate over points (R,B are x and y coordinates of points) and calculate + iterate over points (R, B are x and y coordinates of points) and calculate distance to line in dehatspace """ dists = [] - for i, (R,B) in enumerate(zip(rbs_hat[0],rbs_hat[1])): + for i, (R, B) in enumerate(zip(rbs_hat[0], rbs_hat[1])): """ define function to minimise as square distance between datapoint and point on curve. Squaring is monotonic so minimising radius squared is @@ -129,7 +129,7 @@ def awb(Cam,cal_cr_list,cal_cb_list,plot): """ perform optimisation with scipy.optmisie.fmin """ - x_hat = fmin(f_min,R,disp=0)[0] + x_hat = fmin(f_min, R, disp=0)[0] y_hat = f(x_hat) """ dehat @@ -179,16 +179,16 @@ def awb(Cam,cal_cr_list,cal_cb_list,plot): """ r_fit = r_hat_fit/(1-r_hat_fit-b_hat_fit) b_fit = b_hat_fit/(1-r_hat_fit-b_hat_fit) - c_fit = np.round(rbs_hat[2],0) + c_fit = np.round(rbs_hat[2], 0) """ 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.round(r_fit,4) - b_fit = np.round(b_fit,4) + 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) """ The following code ensures that colour temperature decreases with increasing r/g @@ -200,8 +200,8 @@ def awb(Cam,cal_cr_list,cal_cb_list,plot): while i > 0 : if c_fit[i] > c_fit[i-1]: Cam.log += '\nColour temperature increase found\n' - Cam.log += '{} K at r = {} to '.format(c_fit[i-1],r_fit[i-1]) - Cam.log += '{} K at r = {}'.format(c_fit[i],r_fit[i]) + Cam.log += '{} K at r = {} to '.format(c_fit[i-1], r_fit[i-1]) + Cam.log += '{} K at r = {}'.format(c_fit[i], r_fit[i]) """ if colour temperature increases then discard point furthest from the transformed fit (dehatspace) @@ -209,8 +209,8 @@ def awb(Cam,cal_cr_list,cal_cb_list,plot): error_1 = abs(dists[i-1]) error_2 = abs(dists[i]) Cam.log += '\nDistances from fit:\n' - Cam.log += '{} K : {:.5f} , '.format(c_fit[i],error_1) - Cam.log += '{} K : {:.5f}'.format(c_fit[i-1],error_2) + Cam.log += '{} K : {:.5f} , '.format(c_fit[i], error_1) + Cam.log += '{} K : {:.5f}'.format(c_fit[i-1], error_2) """ find bad index note that in python false = 0 and true = 1 @@ -221,9 +221,9 @@ def awb(Cam,cal_cr_list,cal_cb_list,plot): """ delete bad point """ - r_fit = np.delete(r_fit,bad) - b_fit = np.delete(b_fit,bad) - c_fit = np.delete(c_fit,bad).astype(np.uint16) + r_fit = np.delete(r_fit, bad) + b_fit = np.delete(b_fit, bad) + c_fit = np.delete(c_fit, bad).astype(np.uint16) """ note that if a point has been discarded then the length has decreased by one, meaning that decreasing the index by one will reassess the kept @@ -235,7 +235,7 @@ def awb(Cam,cal_cr_list,cal_cb_list,plot): """ return formatted ct curve, ordered by increasing colour temperature """ - ct_curve = list(np.array(list(zip(b_fit,r_fit,c_fit))).flatten())[::-1] + ct_curve = list(np.array(list(zip(b_fit, r_fit, c_fit))).flatten())[::-1] Cam.log += '\nFinal CT curve:' for i in range(len(ct_curve)//3): j = 3*i @@ -247,15 +247,15 @@ def awb(Cam,cal_cr_list,cal_cb_list,plot): plotting code for debug """ if plot: - x = np.linspace(np.min(rbs_hat[0]),np.max(rbs_hat[0]),100) + x = np.linspace(np.min(rbs_hat[0]), np.max(rbs_hat[0]), 100) y = a*x**2 + b*x + c - plt.subplot(2,1,1) + plt.subplot(2, 1, 1) plt.title('hatspace') - plt.plot(rbs_hat[0],rbs_hat[1],ls='--',color='blue') - plt.plot(x,y,color='green',ls='-') - plt.scatter(rbs_hat[0],rbs_hat[1],color='red') + plt.plot(rbs_hat[0], rbs_hat[1], ls='--', color='blue') + plt.plot(x, y, color='green', ls='-') + plt.scatter(rbs_hat[0], rbs_hat[1], color='red') for i, ct in enumerate(rbs_hat[2]): - plt.annotate(str(ct),(rbs_hat[0][i],rbs_hat[1][i])) + plt.annotate(str(ct), (rbs_hat[0][i], rbs_hat[1][i])) plt.xlabel('$\hat{r}$') plt.ylabel('$\hat{b}$') """ @@ -265,13 +265,13 @@ def awb(Cam,cal_cr_list,cal_cb_list,plot): # ax = plt.gca() # ax.set_aspect('equal') plt.grid() - plt.subplot(2,1,2) + plt.subplot(2, 1, 2) plt.title('dehatspace - indoors?') - plt.plot(r_fit,b_fit,color='blue') - plt.scatter(rb_raw[0],rb_raw[1],color='green') - plt.scatter(r_fit,b_fit,color='red') - for i,ct in enumerate(c_fit): - plt.annotate(str(ct),(r_fit[i],b_fit[i])) + plt.plot(r_fit, b_fit, color='blue') + plt.scatter(rb_raw[0], rb_raw[1], color='green') + plt.scatter(r_fit, b_fit, color='red') + for i, ct in enumerate(c_fit): + plt.annotate(str(ct), (r_fit[i], b_fit[i])) plt.xlabel('$r$') plt.ylabel('$b$') """ @@ -286,15 +286,15 @@ def awb(Cam,cal_cr_list,cal_cb_list,plot): """ end of plotting code """ - return(ct_curve,np.round(transverse_pos,5),np.round(transverse_neg,5)) + return(ct_curve, np.round(transverse_pos, 5), np.round(transverse_neg, 5)) """ obtain greyscale patches and perform alsc colour correction """ -def get_alsc_patches(Img,colour_cals,grey=True): +def get_alsc_patches(Img, colour_cals, grey=True): """ get patch centre coordinates, image colour and the actual - patches for each channel,remembering to subtract blacklevel + patches for each channel, remembering to subtract blacklevel If grey then only greyscale patches considered """ if grey: @@ -316,12 +316,12 @@ def get_alsc_patches(Img,colour_cals,grey=True): g_patchs = (patches[1]+patches[2])/2 - Img.blacklevel_16 if colour_cals == None: - return r_patchs,b_patchs,g_patchs + return r_patchs, b_patchs, g_patchs """ find where image colour fits in alsc colour calibration tables """ cts = list(colour_cals.keys()) - pos = bisect_left(cts,col) + pos = bisect_left(cts, col) """ if img colour is below minimum or above maximum alsc calibration colour, simply pick extreme closest to img colour @@ -343,32 +343,32 @@ def get_alsc_patches(Img,colour_cals,grey=True): bef_tabs = np.array(colour_cals[bef]) aft_tabs = np.array(colour_cals[aft]) col_tabs = (bef_tabs*db + aft_tabs*da)/(da+db) - col_tabs = np.reshape(col_tabs,(2,12,16)) + col_tabs = np.reshape(col_tabs, (2, 12, 16)) """ - calculate dx,dy used to calculate alsc table + calculate dx, dy used to calculate alsc table """ - w,h = Img.w/2,Img.h/2 - dx,dy = int(-(-(w-1)//16)),int(-(-(h-1)//12)) + w, h = Img.w/2, Img.h/2 + dx, dy = int(-(-(w-1)//16)), int(-(-(h-1)//12)) """ make list of pairs of gains for each patch by selecting the correct value in alsc colour calibration table """ patch_gains = [] for cen in cen_coords: - x,y = cen[0]//dx, cen[1]//dy + x, y = cen[0]//dx, cen[1]//dy # We could probably do with some better spatial interpolation here? - col_gains = (col_tabs[0][y][x],col_tabs[1][y][x]) + col_gains = (col_tabs[0][y][x], col_tabs[1][y][x]) patch_gains.append(col_gains) """ multiply the r and b channels in each patch by the respective gain, finally performing the alsc colour correction """ - for i,gains in enumerate(patch_gains): + for i, gains in enumerate(patch_gains): r_patchs[i] = r_patchs[i] * gains[0] b_patchs[i] = b_patchs[i] * gains[1] """ - return greyscale patches, g channel and correct r,b channels + return greyscale patches, g channel and correct r, b channels """ - return r_patchs,b_patchs,g_patchs + return r_patchs, b_patchs, g_patchs diff --git a/utils/raspberrypi/ctt/ctt_ccm.py b/utils/raspberrypi/ctt/ctt_ccm.py index 8200a27f07a6..1771fc43327d 100644 --- a/utils/raspberrypi/ctt/ctt_ccm.py +++ b/utils/raspberrypi/ctt/ctt_ccm.py @@ -19,7 +19,7 @@ def degamma(x): """ FInds colour correction matrices for list of images """ -def ccm(Cam,cal_cr_list,cal_cb_list): +def ccm(Cam, cal_cr_list, cal_cb_list): imgs = Cam.imgs """ standard macbeth chart colour values @@ -32,7 +32,7 @@ def ccm(Cam,cal_cr_list,cal_cb_list): [130, 128, 176], # blue flower [92, 190, 172], # bluish green [224, 124, 47], # orange - [68, 91,170], # purplish blue + [68, 91, 170], # purplish blue [198, 82, 97], # moderate red [94, 58, 106], # purple [159, 189, 63], # yellow green @@ -58,7 +58,7 @@ def ccm(Cam,cal_cr_list,cal_cb_list): """ reorder reference values to match how patches are ordered """ - m_srgb = np.array([m_srgb[i::6] for i in range(6)]).reshape((24,3)) + m_srgb = np.array([m_srgb[i::6] for i in range(6)]).reshape((24, 3)) """ reformat alsc correction tables or set colour_cals to None if alsc is @@ -68,7 +68,7 @@ def ccm(Cam,cal_cr_list,cal_cb_list): colour_cals = None else: colour_cals = {} - for cr,cb in zip(cal_cr_list,cal_cb_list): + for cr, cb in zip(cal_cr_list, cal_cb_list): cr_tab = cr['table'] cb_tab = cb['table'] """ @@ -76,7 +76,7 @@ def ccm(Cam,cal_cr_list,cal_cb_list): """ cr_tab= cr_tab/np.min(cr_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] """ for each image, perform awb and alsc corrections. @@ -91,14 +91,14 @@ def ccm(Cam,cal_cr_list,cal_cb_list): Note: if alsc is disabled then colour_cals will be set to None and no the function will simply return the macbeth patches """ - r,b,g = get_alsc_patches(Img,colour_cals,grey=False) + r, b, g = get_alsc_patches(Img, colour_cals, grey=False) """ do awb Note: awb is done by measuring the macbeth chart in the image, rather than from the awb calibration. This is done so the awb will be perfect and the ccm matrices will be more accurate. """ - r_greys,b_greys,g_greys = r[3::4],b[3::4],g[3::4] + r_greys, b_greys, g_greys = r[3::4], b[3::4], g[3::4] r_g = np.mean(r_greys/g_greys) b_g = np.mean(b_greys/g_greys) r = r / r_g @@ -108,16 +108,16 @@ def ccm(Cam,cal_cr_list,cal_cb_list): normalise brightness wrt reference macbeth colours and then average each channel for each patch """ - gain = np.mean(m_srgb)/np.mean((r,g,b)) + gain = np.mean(m_srgb)/np.mean((r, g, b)) Cam.log += '\nGain with respect to standard colours: {:.3f}'.format(gain) - r = np.mean(gain*r,axis=1) - b = np.mean(gain*b,axis=1) - g = np.mean(gain*g,axis=1) + r = np.mean(gain*r, axis=1) + b = np.mean(gain*b, axis=1) + g = np.mean(gain*g, axis=1) """ calculate ccm matrix """ - ccm = do_ccm(r,g,b,m_srgb) + ccm = do_ccm(r, g, b, m_srgb) """ if a ccm has already been calculated for that temperature then don't @@ -133,18 +133,18 @@ def ccm(Cam,cal_cr_list,cal_cb_list): """ average any ccms that share a colour temperature """ - for k,v in ccm_tab.items(): - 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.95,tab-0.00001,tab) - ccm_tab[k] = list(np.round(tab,5)) + for k, v in ccm_tab.items(): + 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.95, tab-0.00001, tab) + ccm_tab[k] = list(np.round(tab, 5)) Cam.log += '\nMatrix calculated for colour temperature of {} K'.format(k) """ return all ccms with respective colour temperature in the correct format, sorted by their colour temperature """ - sorted_ccms = sorted(ccm_tab.items(),key=lambda kv: kv[0]) + sorted_ccms = sorted(ccm_tab.items(), key=lambda kv: kv[0]) ccms = [] for i in sorted_ccms: ccms.append({ @@ -161,19 +161,19 @@ calculation. Should you want to fit them in another space (e.g. LAB) we wish you the best of luck and send us the code when you are done! :-) """ -def do_ccm(r,g,b,m_srgb): +def do_ccm(r, g, b, m_srgb): rb = r-b gb = g-b rb_2s = (rb*rb) rb_gbs = (rb*gb) gb_2s = (gb*gb) - r_rbs = ( rb * (m_srgb[...,0] - b) ) - r_gbs = ( gb * (m_srgb[...,0] - b) ) - g_rbs = ( rb * (m_srgb[...,1] - b) ) - g_gbs = ( gb * (m_srgb[...,1] - b) ) - b_rbs = ( rb * (m_srgb[...,2] - b) ) - b_gbs = ( gb * (m_srgb[...,2] - b) ) + r_rbs = ( rb * (m_srgb[..., 0] - b) ) + r_gbs = ( gb * (m_srgb[..., 0] - b) ) + g_rbs = ( rb * (m_srgb[..., 1] - b) ) + g_gbs = ( gb * (m_srgb[..., 1] - b) ) + b_rbs = ( rb * (m_srgb[..., 2] - b) ) + b_gbs = ( gb * (m_srgb[..., 2] - b) ) """ Obtain least squares fit @@ -216,6 +216,6 @@ def do_ccm(r,g,b,m_srgb): """ format ccm """ - ccm = [r_a,r_b,r_c,g_a,g_b,g_c,b_a,b_b,b_c] + ccm = [r_a, r_b, r_c, g_a, g_b, g_c, b_a, b_b, b_c] return ccm diff --git a/utils/raspberrypi/ctt/ctt_geq.py b/utils/raspberrypi/ctt/ctt_geq.py index dd798f4a6864..f8395e437fe6 100644 --- a/utils/raspberrypi/ctt/ctt_geq.py +++ b/utils/raspberrypi/ctt/ctt_geq.py @@ -13,25 +13,25 @@ Uses green differences in macbeth patches to fit green equalisation threshold model. Ideally, all macbeth chart centres would fall below the threshold as these should be corrected by geq. """ -def geq_fit(Cam,plot): +def geq_fit(Cam, plot): imgs = Cam.imgs """ green equalisation to mitigate mazing. Fits geq model by looking at difference between greens in macbeth patches """ - geqs = np.array([ geq(Cam,Img)*Img.againQ8_norm for Img in imgs ]) + geqs = np.array([ geq(Cam, Img)*Img.againQ8_norm for Img in imgs ]) Cam.log += '\nProcessed all images' - geqs = geqs.reshape((-1,2)) + geqs = geqs.reshape((-1, 2)) """ data is sorted by green difference and top half is selected since higher green difference data define the decision boundary. """ - geqs = np.array(sorted(geqs,key = lambda r:np.abs((r[1]-r[0])/r[0]))) + geqs = np.array(sorted(geqs, key = lambda r: np.abs((r[1]-r[0])/r[0]))) length = len(geqs) - g0 = geqs[length//2:,0] - g1 = geqs[length//2:,1] + g0 = geqs[length//2:, 0] + g1 = geqs[length//2:, 1] gdiff = np.abs(g0-g1) """ find linear fit by minimising asymmetric least square errors @@ -40,7 +40,7 @@ def geq_fit(Cam,plot): threshold, hence the upper bound approach """ def f(params): - m,c = params + m, c = params a = gdiff - (m*g0+c) """ asymmetric square error returns: @@ -49,29 +49,29 @@ def geq_fit(Cam,plot): """ return(np.sum(a**2+0.95*np.abs(a)*a)) - initial_guess = [0.01,500] + initial_guess = [0.01, 500] """ Nelder-Mead is usually not the most desirable optimisation method but has been chosen here due to its robustness to undifferentiability (is that a word?) """ - result = optimize.minimize(f,initial_guess,method='Nelder-Mead') + result = optimize.minimize(f, initial_guess, method='Nelder-Mead') """ need to check if the fit worked correectly """ if result.success: - slope,offset = result.x + slope, offset = result.x Cam.log += '\nFit result: slope = {:.5f} '.format(slope) Cam.log += 'offset = {}'.format(int(offset)) """ optional plotting code """ if plot: - x = np.linspace(max(g0)*1.1,100) + x = np.linspace(max(g0)*1.1, 100) y = slope*x + offset plt.title('GEQ Asymmetric \'Upper Bound\' Fit') - plt.plot(x,y,color='red',ls='--',label='fit') - plt.scatter(g0,gdiff,color='b',label='data') + plt.plot(x, y, color='red', ls='--', label='fit') + plt.scatter(g0, gdiff, color='b', label='data') plt.ylabel('Difference in green channels') plt.xlabel('Green value') @@ -103,7 +103,7 @@ def geq_fit(Cam,plot): """ if plot: y2 = slope*x + offset - plt.plot(x,y2,color='green',ls='--',label='scaled fit') + plt.plot(x, y2, color='green', ls='--', label='scaled fit') plt.grid() plt.legend() plt.show() @@ -122,19 +122,19 @@ def geq_fit(Cam,plot): print(result.message) Cam.log += '\nWARNING: Asymmetric least squares fit failed! ' Cam.log += 'Standard fit used could possibly lead to worse results' - fit = np.polyfit(gdiff,g0,1) - offset,slope = -fit[1]/fit[0],1/fit[0] + fit = np.polyfit(gdiff, g0, 1) + offset, slope = -fit[1]/fit[0], 1/fit[0] Cam.log += '\nFit result: slope = {:.5f} '.format(slope) Cam.log += 'offset = {}'.format(int(offset)) """ optional plotting code """ if plot: - x = np.linspace(max(g0)*1.1,100) + x = np.linspace(max(g0)*1.1, 100) y = slope*x + offset plt.title('GEQ Linear Fit') - plt.plot(x,y,color='red',ls='--',label='fit') - plt.scatter(g0,gdiff,color='b',label='data') + plt.plot(x, y, color='red', ls='--', label='fit') + plt.scatter(g0, gdiff, color='b', label='data') plt.ylabel('Difference in green channels') plt.xlabel('Green value') """ @@ -158,22 +158,22 @@ def geq_fit(Cam,plot): """ if plot: y2 = slope*x + offset - plt.plot(x,y2,color='green',ls='--',label='scaled fit') + plt.plot(x, y2, color='green', ls='--', label='scaled fit') plt.legend() plt.grid() plt.show() - return round(slope,5),int(offset) + return round(slope, 5), int(offset) """" Return green channels of macbeth patches -returns g0,g1 where +returns g0, g1 where > g0 is green next to red > g1 is green next to blue """ -def geq(Cam,Img): +def geq(Cam, Img): Cam.log += '\nProcessing image {}'.format(Img.name) patches = [Img.patches[i] for i in Img.order][1:3] - g_patches = np.array([(np.mean(patches[0][i]),np.mean(patches[1][i])) for i in range(24)]) + g_patches = np.array([(np.mean(patches[0][i]), np.mean(patches[1][i])) for i in range(24)]) Cam.log += '\n' return(g_patches) diff --git a/utils/raspberrypi/ctt/ctt_image_load.py b/utils/raspberrypi/ctt/ctt_image_load.py index dd7adb1653aa..7d097118c16c 100644 --- a/utils/raspberrypi/ctt/ctt_image_load.py +++ b/utils/raspberrypi/ctt/ctt_image_load.py @@ -18,7 +18,7 @@ Once image is extracted from data, it finds 24 16x16 patches for each channel, centred at the macbeth chart squares """ class Image: - def __init__(self,buf): + def __init__(self, buf): self.buf = buf self.patches = None self.saturated = False @@ -45,11 +45,11 @@ class Image: Channel order depending on bayer pattern """ bayer_case = { - 0 : (0,1,2,3), #red - 1 : (2,0,3,1), #green next to red - 2 : (3,2,1,0), #green next to blue - 3 : (1,0,3,2), #blue - 128 : (0,1,2,3) #arbitrary order for greyscale casw + 0 : (0, 1, 2, 3), #red + 1 : (2, 0, 3, 1), #green next to red + 2 : (3, 2, 1, 0), #green next to blue + 3 : (1, 0, 3, 2), #blue + 128 : (0, 1, 2, 3) #arbitrary order for greyscale casw } self.order = bayer_case[self.pattern] @@ -87,7 +87,7 @@ class Image: """ get image from raw scanline data """ - def get_image(self,raw): + def get_image(self, raw): self.dptr = [] """ check if data is 10 or 12 bits @@ -100,31 +100,31 @@ class Image: """ stack scan lines into matrix """ - raw = np.array(raw).reshape(-1,lin_len).astype(np.int64)[:self.h,...] + raw = np.array(raw).reshape(-1, lin_len).astype(np.int64)[:self.h, ...] """ separate 5 bits in each package, stopping when w is satisfied """ - ba0 = raw[...,0:5*((self.w+3)>>2):5] - ba1 = raw[...,1:5*((self.w+3)>>2):5] - ba2 = raw[...,2:5*((self.w+3)>>2):5] - ba3 = raw[...,3:5*((self.w+3)>>2):5] - ba4 = raw[...,4:5*((self.w+3)>>2):5] + ba0 = raw[..., 0:5*((self.w+3)>>2):5] + ba1 = raw[..., 1:5*((self.w+3)>>2):5] + ba2 = raw[..., 2:5*((self.w+3)>>2):5] + ba3 = raw[..., 3:5*((self.w+3)>>2):5] + ba4 = raw[..., 4:5*((self.w+3)>>2):5] """ assemble 10 bit numbers """ - ch0 = np.left_shift((np.left_shift(ba0,2) + (ba4%4)),6) - ch1 = np.left_shift((np.left_shift(ba1,2) + (np.right_shift(ba4,2)%4)),6) - ch2 = np.left_shift((np.left_shift(ba2,2) + (np.right_shift(ba4,4)%4)),6) - ch3 = np.left_shift((np.left_shift(ba3,2) + (np.right_shift(ba4,6)%4)),6) + ch0 = np.left_shift((np.left_shift(ba0, 2) + (ba4%4)), 6) + ch1 = np.left_shift((np.left_shift(ba1, 2) + (np.right_shift(ba4, 2)%4)), 6) + ch2 = np.left_shift((np.left_shift(ba2, 2) + (np.right_shift(ba4, 4)%4)), 6) + ch3 = np.left_shift((np.left_shift(ba3, 2) + (np.right_shift(ba4, 6)%4)), 6) """ interleave bits """ - mat = np.empty((self.h,self.w),dtype=ch0.dtype) + mat = np.empty((self.h, self.w), dtype=ch0.dtype) - mat[...,0::4] = ch0 - mat[...,1::4] = ch1 - mat[...,2::4] = ch2 - mat[...,3::4] = ch3 + mat[..., 0::4] = ch0 + mat[..., 1::4] = ch1 + mat[..., 2::4] = ch2 + mat[..., 3::4] = ch3 """ There is som eleaking memory somewhere in the code. This code here @@ -132,25 +132,25 @@ class Image: reasonable numbers of images, however this is techincally just a workaround. (sorry) """ - ba0,ba1,ba2,ba3,ba4 = None,None,None,None,None - del ba0,ba1,ba2,ba3,ba4 - ch0,ch1,ch2,ch3 = None,None,None,None - del ch0,ch1,ch2,ch3 + ba0, ba1, ba2, ba3, ba4 = None, None, None, None, None + del ba0, ba1, ba2, ba3, ba4 + ch0, ch1, ch2, ch3 = None, None, None, None + del ch0, ch1, ch2, ch3 """ same as before but 12 bit case """ elif self.sigbits == 12: lin_len = ((((((self.w+self.pad+1)>>1)) * 3)+31)>>5) * 32 - raw = np.array(raw).reshape(-1,lin_len).astype(np.int64)[:self.h,...] - ba0 = raw[...,0:3*((self.w+1)>>1):3] - ba1 = raw[...,1:3*((self.w+1)>>1):3] - ba2 = raw[...,2:3*((self.w+1)>>1):3] - ch0 = np.left_shift((np.left_shift(ba0,4) + ba2%16),4) - ch1 = np.left_shift((np.left_shift(ba1,4) + (np.right_shift(ba2,4))%16),4) - mat = np.empty((self.h,self.w),dtype=ch0.dtype) - mat[...,0::2] = ch0 - mat[...,1::2] = ch1 + raw = np.array(raw).reshape(-1, lin_len).astype(np.int64)[:self.h, ...] + ba0 = raw[..., 0:3*((self.w+1)>>1):3] + ba1 = raw[..., 1:3*((self.w+1)>>1):3] + ba2 = raw[..., 2:3*((self.w+1)>>1):3] + ch0 = np.left_shift((np.left_shift(ba0, 4) + ba2%16), 4) + ch1 = np.left_shift((np.left_shift(ba1, 4) + (np.right_shift(ba2, 4))%16), 4) + mat = np.empty((self.h, self.w), dtype=ch0.dtype) + mat[..., 0::2] = ch0 + mat[..., 1::2] = ch1 else: """ @@ -162,21 +162,21 @@ class Image: """ separate bayer channels """ - c0 = mat[0::2,0::2] - c1 = mat[0::2,1::2] - c2 = mat[1::2,0::2] - c3 = mat[1::2,1::2] - self.channels = [c0,c1,c2,c3] + c0 = mat[0::2, 0::2] + c1 = mat[0::2, 1::2] + c2 = mat[1::2, 0::2] + c3 = mat[1::2, 1::2] + self.channels = [c0, c1, c2, c3] return 1 """ obtain 16x16 patch centred at macbeth square centre for each channel """ - def get_patches(self,cen_coords,size=16): + def get_patches(self, cen_coords, size=16): """ obtain channel widths and heights """ - ch_w,ch_h = self.w,self.h + ch_w, ch_h = self.w, self.h cen_coords = list(np.array((cen_coords[0])).astype(np.int32)) self.cen_coords = cen_coords """ @@ -184,10 +184,10 @@ class Image: left to right. Some useful patch indices: white = 3 black = 23 - 'reds' = 9,10 - 'blues' = 2,5,8,20,22 - 'greens' = 6,12,17 - greyscale = 3,7,11,15,19,23 + 'reds' = 9, 10 + 'blues' = 2, 5, 8, 20, 22 + 'greens' = 6, 12, 17 + greyscale = 3, 7, 11, 15, 19, 23 """ all_patches = [] for ch in self.channels: @@ -199,7 +199,7 @@ class Image: Patch pixels are sorted by pixel brightness so spatial information is lost. ''' - patch = ch[cen[1]-7:cen[1]+9,cen[0]-7:cen[0]+9].flatten() + patch = ch[cen[1]-7:cen[1]+9, cen[0]-7:cen[0]+9].flatten() patch.sort() if patch[-5] == (2**self.sigbits-1)*2**(16-self.sigbits): self.saturated = True @@ -218,7 +218,7 @@ def brcm_load_image(Cam, im_str): """ create byte array """ - with open(im_str,'rb') as image: + with open(im_str, 'rb') as image: f = image.read() b = bytearray(f) """ @@ -249,7 +249,7 @@ def brcm_load_image(Cam, im_str): """ note index is divided by two to go from string to hex """ - indices = [m.start()//2 for m in re.finditer(match_str,b_str)] + indices = [m.start()//2 for m in re.finditer(match_str, b_str)] # print(indices) try: start = indices[0] + 3 @@ -325,10 +325,10 @@ def dng_load_image(Cam, im_str): raw_im = raw.imread(im_str) raw_data = raw_im.raw_image shift = 16 - Img.sigbits - c0 = np.left_shift(raw_data[0::2,0::2].astype(np.int64), shift) - c1 = np.left_shift(raw_data[0::2,1::2].astype(np.int64), shift) - c2 = np.left_shift(raw_data[1::2,0::2].astype(np.int64), shift) - c3 = np.left_shift(raw_data[1::2,1::2].astype(np.int64), shift) + c0 = np.left_shift(raw_data[0::2, 0::2].astype(np.int64), shift) + c1 = np.left_shift(raw_data[0::2, 1::2].astype(np.int64), shift) + c2 = np.left_shift(raw_data[1::2, 0::2].astype(np.int64), shift) + c3 = np.left_shift(raw_data[1::2, 1::2].astype(np.int64), shift) Img.channels = [c0, c1, c2, c3] except: @@ -347,7 +347,7 @@ check correct filetype mac boolean is true if image is expected to contain macbeth chart and false if not (alsc images don't have macbeth charts) ''' -def load_image(Cam,im_str,mac_config=None,show=False,mac=True,show_meta=False): +def load_image(Cam, im_str, mac_config=None, show=False, mac=True, show_meta=False): """ check image is correct filetype """ @@ -363,7 +363,7 @@ def load_image(Cam,im_str,mac_config=None,show=False,mac=True,show_meta=False): """ find macbeth centres, discarding images that are too dark or light """ - av_chan = (np.mean(np.array(Img.channels),axis=0)/(2**16)) + av_chan = (np.mean(np.array(Img.channels), axis=0)/(2**16)) av_val = np.mean(av_chan) # print(av_val) if av_val < Img.blacklevel_16/(2**16)+1/64: @@ -371,7 +371,7 @@ def load_image(Cam,im_str,mac_config=None,show=False,mac=True,show_meta=False): print('\nError: Image too dark!') Cam.log += '\nWARNING: Image too dark!' else: - macbeth = find_macbeth(Cam,av_chan,mac_config) + macbeth = find_macbeth(Cam, av_chan, mac_config) """ if no macbeth found return error @@ -405,8 +405,8 @@ def load_image(Cam,im_str,mac_config=None,show=False,mac=True,show_meta=False): """ if show and __name__ == '__main__': copy = sum(Img.channels)/2**18 - copy = np.reshape(copy,(Img.h//2,Img.w//2)).astype(np.float64) - copy,_ = reshape(copy,800) + copy = np.reshape(copy, (Img.h//2, Img.w//2)).astype(np.float64) + copy, _ = reshape(copy, 800) represent(copy) return Img diff --git a/utils/raspberrypi/ctt/ctt_lux.py b/utils/raspberrypi/ctt/ctt_lux.py index 8a16d346490f..55b2aa299ed3 100644 --- a/utils/raspberrypi/ctt/ctt_lux.py +++ b/utils/raspberrypi/ctt/ctt_lux.py @@ -8,7 +8,7 @@ from ctt_tools import * """ Find lux values from metadata and calculate Y """ -def lux(Cam,Img): +def lux(Cam, Img): shutter_speed = Img.exposure gain = Img.againQ8_norm aperture = 1 @@ -17,12 +17,12 @@ def lux(Cam,Img): Cam.log += '\nAperture = {}'.format(aperture) patches = [Img.patches[i] for i in Img.order] channels = [Img.channels[i] for i in Img.order] - return lux_calc(Cam,Img,patches,channels),shutter_speed,gain + return lux_calc(Cam, Img, patches, channels), shutter_speed, gain """ perform lux calibration on bayer channels """ -def lux_calc(Cam,Img,patches,channels): +def lux_calc(Cam, Img, patches, channels): """ find means color channels on grey patches """ @@ -30,14 +30,14 @@ def lux_calc(Cam,Img,patches,channels): ap_g = (np.mean(patches[1][3::4])+np.mean(patches[2][3::4]))/2 ap_b = np.mean(patches[3][3::4]) Cam.log += '\nAverage channel values on grey patches:' - Cam.log += '\nRed = {:.0f} Green = {:.0f} Blue = {:.0f}'.format(ap_r,ap_b,ap_g) - # print(ap_r,ap_g,ap_b) + Cam.log += '\nRed = {:.0f} Green = {:.0f} Blue = {:.0f}'.format(ap_r, ap_b, ap_g) + # print(ap_r, ap_g, ap_b) """ calculate channel gains """ gr = ap_g/ap_r gb = ap_g/ap_b - Cam.log += '\nChannel gains: Red = {:.3f} Blue = {:.3f}'.format(gr,gb) + Cam.log += '\nChannel gains: Red = {:.3f} Blue = {:.3f}'.format(gr, gb) """ find means color channels on image and scale by gain @@ -47,8 +47,8 @@ def lux_calc(Cam,Img,patches,channels): a_g = (np.mean(channels[1])+np.mean(channels[2]))/2 a_b = np.mean(channels[3])*gb Cam.log += '\nAverage channel values over entire image scaled by channel gains:' - Cam.log += '\nRed = {:.0f} Green = {:.0f} Blue = {:.0f}'.format(a_r,a_b,a_g) - # print(a_r,a_g,a_b) + Cam.log += '\nRed = {:.0f} Green = {:.0f} Blue = {:.0f}'.format(a_r, a_b, a_g) + # print(a_r, a_g, a_b) """ Calculate y with top row of yuv matrix """ diff --git a/utils/raspberrypi/ctt/ctt_macbeth_locator.py b/utils/raspberrypi/ctt/ctt_macbeth_locator.py index 583d5a692470..591459aa4cc5 100644 --- a/utils/raspberrypi/ctt/ctt_macbeth_locator.py +++ b/utils/raspberrypi/ctt/ctt_macbeth_locator.py @@ -19,15 +19,15 @@ the clustering algorithm. This catches these warnings so they don't flood the output to the console """ def fxn(): - warnings.warn("runtime",RuntimeWarning) + warnings.warn("runtime", RuntimeWarning) """ Define the success message """ success_msg = 'Macbeth chart located successfully' -def find_macbeth(Cam,img,mac_config=(0,0)): - small_chart,show = mac_config +def find_macbeth(Cam, img, mac_config=(0, 0)): + small_chart, show = mac_config print('Locating macbeth chart') Cam.log += '\nLocating macbeth chart' """ @@ -40,20 +40,20 @@ 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) - rc2 = (0,ref_h) - rc3 = (ref_w,ref_h) - rc4 = (ref_w,0) - ref_corns = np.array((rc1,rc2,rc3,rc4),np.float32) - ref_data = (ref,ref_w,ref_h,ref_corns) + rc1 = (0, 0) + rc2 = (0, ref_h) + rc3 = (ref_w, ref_h) + rc4 = (ref_w, 0) + ref_corns = np.array((rc1, rc2, rc3, rc4), np.float32) + ref_data = (ref, ref_w, ref_h, ref_corns) """ locate macbeth chart """ - cor,mac,coords,msg = get_macbeth_chart(img,ref_data) + cor, mac, coords, msg = get_macbeth_chart(img, ref_data) """ following bits of code tries to fix common problems with simple @@ -68,20 +68,20 @@ def find_macbeth(Cam,img,mac_config=(0,0)): """ if cor < 0.75: a = 2 - img_br = cv2.convertScaleAbs(img,alpha=a,beta=0) - cor_b,mac_b,coords_b,msg_b = get_macbeth_chart(img_br,ref_data) + img_br = cv2.convertScaleAbs(img, alpha=a, beta=0) + cor_b, mac_b, coords_b, msg_b = get_macbeth_chart(img_br, ref_data) if cor_b > cor: - cor,mac,coords,msg = cor_b,mac_b,coords_b,msg_b + cor, mac, coords, msg = cor_b, mac_b, coords_b, msg_b """ brighten image 4x """ if cor < 0.75: a = 4 - img_br = cv2.convertScaleAbs(img,alpha=a,beta=0) - cor_b,mac_b,coords_b,msg_b = get_macbeth_chart(img_br,ref_data) + img_br = cv2.convertScaleAbs(img, alpha=a, beta=0) + cor_b, mac_b, coords_b, msg_b = get_macbeth_chart(img_br, ref_data) if cor_b > cor: - cor,mac,coords,msg = cor_b,mac_b,coords_b,msg_b + cor, mac, coords, msg = cor_b, mac_b, coords_b, msg_b """ In case macbeth chart is too small, take a selection of the image and @@ -115,7 +115,7 @@ def find_macbeth(Cam,img,mac_config=(0,0)): get size of image """ shape = list(img.shape[:2]) - w,h = shape + w, h = shape """ set dimensions of the subselection and the step along each axis between selections @@ -129,9 +129,9 @@ def find_macbeth(Cam,img,mac_config=(0,0)): """ for i in range(3): for j in range(3): - w_s,h_s = i*w_inc,j*h_inc - img_sel = img[w_s:w_s+w_sel,h_s:h_s+h_sel] - cor_ij,mac_ij,coords_ij,msg_ij = get_macbeth_chart(img_sel,ref_data) + w_s, h_s = i*w_inc, j*h_inc + img_sel = img[w_s:w_s+w_sel, h_s:h_s+h_sel] + cor_ij, mac_ij, coords_ij, msg_ij = get_macbeth_chart(img_sel, ref_data) """ if the correlation is better than the best then record the scale and current subselection at which macbeth chart was @@ -139,9 +139,9 @@ def find_macbeth(Cam,img,mac_config=(0,0)): """ if cor_ij > cor: cor = cor_ij - mac,coords,msg = mac_ij,coords_ij,msg_ij - ii,jj = i,j - w_best,h_best = w_inc,h_inc + mac, coords, msg = mac_ij, coords_ij, msg_ij + ii, jj = i, j + w_best, h_best = w_inc, h_inc d_best = 1 @@ -151,21 +151,21 @@ def find_macbeth(Cam,img,mac_config=(0,0)): if cor < 0.75: imgs = [] shape = list(img.shape[:2]) - w,h = shape + w, h = shape w_sel = int(w/2) h_sel = int(h/2) w_inc = int(w/8) h_inc = int(h/8) for i in range(5): for j in range(5): - w_s,h_s = i*w_inc,j*h_inc - img_sel = img[w_s:w_s+w_sel,h_s:h_s+h_sel] - cor_ij,mac_ij,coords_ij,msg_ij = get_macbeth_chart(img_sel,ref_data) + w_s, h_s = i*w_inc, j*h_inc + img_sel = img[w_s:w_s+w_sel, h_s:h_s+h_sel] + cor_ij, mac_ij, coords_ij, msg_ij = get_macbeth_chart(img_sel, ref_data) if cor_ij > cor: cor = cor_ij - mac,coords,msg = mac_ij,coords_ij,msg_ij - ii,jj = i,j - w_best,h_best = w_inc,h_inc + mac, coords, msg = mac_ij, coords_ij, msg_ij + ii, jj = i, j + w_best, h_best = w_inc, h_inc d_best = 2 """ @@ -183,41 +183,41 @@ def find_macbeth(Cam,img,mac_config=(0,0)): if cor < 0.75 and d_best > 1 : imgs = [] shape = list(img.shape[:2]) - w,h = shape + w, h = shape w_sel = int(w/3) h_sel = int(h/3) w_inc = int(w/12) h_inc = int(h/12) for i in range(9): for j in range(9): - w_s,h_s = i*w_inc,j*h_inc - img_sel = img[w_s:w_s+w_sel,h_s:h_s+h_sel] - cor_ij,mac_ij,coords_ij,msg_ij = get_macbeth_chart(img_sel,ref_data) + w_s, h_s = i*w_inc, j*h_inc + img_sel = img[w_s:w_s+w_sel, h_s:h_s+h_sel] + cor_ij, mac_ij, coords_ij, msg_ij = get_macbeth_chart(img_sel, ref_data) if cor_ij > cor: cor = cor_ij - mac,coords,msg = mac_ij,coords_ij,msg_ij - ii,jj = i,j - w_best,h_best = w_inc,h_inc + mac, coords, msg = mac_ij, coords_ij, msg_ij + ii, jj = i, j + w_best, h_best = w_inc, h_inc d_best = 3 if cor < 0.75 and d_best > 2: imgs = [] shape = list(img.shape[:2]) - w,h = shape + w, h = shape w_sel = int(w/4) h_sel = int(h/4) w_inc = int(w/16) h_inc = int(h/16) for i in range(13): for j in range(13): - w_s,h_s = i*w_inc,j*h_inc - img_sel = img[w_s:w_s+w_sel,h_s:h_s+h_sel] - cor_ij,mac_ij,coords_ij,msg_ij = get_macbeth_chart(img_sel,ref_data) + w_s, h_s = i*w_inc, j*h_inc + img_sel = img[w_s:w_s+w_sel, h_s:h_s+h_sel] + cor_ij, mac_ij, coords_ij, msg_ij = get_macbeth_chart(img_sel, ref_data) if cor_ij > cor: cor = cor_ij - mac,coords,msg = mac_ij,coords_ij,msg_ij - ii,jj = i,j - w_best,h_best = w_inc,h_inc + mac, coords, msg = mac_ij, coords_ij, msg_ij + ii, jj = i, j + w_best, h_best = w_inc, h_inc """ Transform coordinates from subselection to original image @@ -241,7 +241,7 @@ def find_macbeth(Cam,img,mac_config=(0,0)): if msg == success_msg: coords_fit = coords Cam.log += '\nMacbeth chart vertices:\n' - Cam.log += '{}'.format(2*np.round(coords_fit[0][0]),0) + Cam.log += '{}'.format(2*np.round(coords_fit[0][0]), 0) """ if correlation is lower than 0.75 there may be a risk of macbeth chart corners not having been located properly. It might be worth running @@ -253,8 +253,8 @@ def find_macbeth(Cam,img,mac_config=(0,0)): if cor < 0.75: print('Caution: Low confidence guess!') Cam.log += 'WARNING: Low confidence guess!' - # cv2.imshow('MacBeth',mac) - # represent(mac,'MacBeth chart') + # cv2.imshow('MacBeth', mac) + # represent(mac, 'MacBeth chart') """ extract data from coords_fit and plot on original image @@ -269,7 +269,7 @@ def find_macbeth(Cam,img,mac_config=(0,0)): """ for vert in verts: p = tuple(np.round(vert).astype(np.int32)) - cv2.circle(copy,p,10,1,-1) + cv2.circle(copy, p, 10, 1, -1) """ draw circles at centres of squares """ @@ -281,17 +281,17 @@ def find_macbeth(Cam,img,mac_config=(0,0)): grey circle everywhere else. """ if i == 3: - cv2.circle(copy,p,8,0,-1) + cv2.circle(copy, p, 8, 0, -1) elif i == 23: - cv2.circle(copy,p,8,1,-1) + cv2.circle(copy, p, 8, 1, -1) else: - cv2.circle(copy,p,8,0.5,-1) - copy,_ = reshape(copy,400) + cv2.circle(copy, p, 8, 0.5, -1) + copy, _ = reshape(copy, 400) represent(copy) return(coords_fit) -def get_macbeth_chart(img,ref_data): +def get_macbeth_chart(img, ref_data): """ function returns coordinates of macbeth chart vertices and square centres, along with an error/success message for debugging purposes. Additionally, @@ -316,7 +316,7 @@ def get_macbeth_chart(img,ref_data): """ get reference macbeth chart data """ - (ref,ref_w,ref_h,ref_corns) = ref_data + (ref, ref_w, ref_h, ref_corns) = ref_data """ the code will raise and catch a MacbethError in case of a problem, trying @@ -327,10 +327,10 @@ def get_macbeth_chart(img,ref_data): obtain image, convert to grayscale and normalise """ src = img - src,factor = reshape(src,200) + src, factor = reshape(src, 200) original=src.copy() a = 125/np.average(src) - src_norm = cv2.convertScaleAbs(src,alpha=a,beta=0) + src_norm = cv2.convertScaleAbs(src, alpha=a, beta=0) """ This code checks if there are seperate colour channels. In the past the macbeth locator ran on jpgs and this makes it robust to different @@ -338,11 +338,11 @@ def get_macbeth_chart(img,ref_data): average bayer channel so coordinates must be doubled. This is best done in img_load.py in the get_patches method. The - coordinates and image width,height must be divided by two if the + coordinates and image width, height must be divided by two if the macbeth locator has been run on a demosaicked image. """ if len(src_norm.shape) == 3: - src_bw = cv2.cvtColor(src_norm,cv2.COLOR_BGR2GRAY) + src_bw = cv2.cvtColor(src_norm, cv2.COLOR_BGR2GRAY) else: src_bw = src_norm original_bw = src_bw.copy() @@ -350,20 +350,20 @@ def get_macbeth_chart(img,ref_data): obtain image edges """ sigma=2 - src_bw = cv2.GaussianBlur(src_bw,(0,0),sigma) - t1,t2 = 50,100 - edges = cv2.Canny(src_bw,t1,t2) + src_bw = cv2.GaussianBlur(src_bw, (0, 0), sigma) + t1, t2 = 50, 100 + edges = cv2.Canny(src_bw, t1, t2) """ dilate edges to prevent self-intersections in contours """ k_size = 2 - kernel = np.ones((k_size,k_size)) + kernel = np.ones((k_size, k_size)) its = 1 - edges = cv2.dilate(edges,kernel,iterations=its) + edges = cv2.dilate(edges, kernel, iterations=its) """ find Contours in image """ - conts,_ = cv2.findContours(edges, + conts, _ = cv2.findContours(edges, cv2.RETR_TREE, cv2.CHAIN_APPROX_NONE) if len(conts) == 0: @@ -380,11 +380,11 @@ def get_macbeth_chart(img,ref_data): epsilon = 0.07 conts_per = [] for i in range(len(conts)): - per = cv2.arcLength(conts[i],True) + per = cv2.arcLength(conts[i], True) poly = cv2.approxPolyDP(conts[i], - epsilon*per,True) + epsilon*per, True) if len(poly) == 4 and cv2.isContourConvex(poly): - conts_per.append((poly,per)) + conts_per.append((poly, per)) if len(conts_per) == 0: raise MacbethError( @@ -399,11 +399,11 @@ def get_macbeth_chart(img,ref_data): """ sort contours by perimeter and get perimeters within percent of median """ - conts_per = sorted(conts_per,key=lambda x:x[1]) + conts_per = sorted(conts_per, key=lambda x: x[1]) med_per = conts_per[int(len(conts_per)/2)][1] side = med_per/4 perc = 0.1 - med_low,med_high = med_per*(1-perc),med_per*(1+perc) + med_low, med_high = med_per*(1-perc), med_per*(1+perc) squares = [] for i in conts_per: if med_low <= i[1] and med_high >= i[1]: @@ -412,7 +412,7 @@ def get_macbeth_chart(img,ref_data): """ obtain coordinates of nomralised macbeth and squares """ - square_verts,mac_norm = get_square_verts(0.06) + square_verts, mac_norm = get_square_verts(0.06) """ for each square guess, find 24 possible macbeth chart centres """ @@ -432,11 +432,11 @@ def get_macbeth_chart(img,ref_data): """ reorder vertices to prevent 'hourglass shape' """ - square = sorted(square,key=lambda x:x[0]) - square_1 = sorted(square[:2],key=lambda x:x[1]) - square_2 = sorted(square[2:],key=lambda x:-x[1]) - square = np.array(np.concatenate((square_1,square_2)),np.float32) - square = np.reshape(square,(4,2)).astype(np.float32) + square = sorted(square, key=lambda x: x[0]) + square_1 = sorted(square[:2], key=lambda x: x[1]) + square_2 = sorted(square[2:], key=lambda x: -x[1]) + square = np.array(np.concatenate((square_1, square_2)), np.float32) + square = np.reshape(square, (4, 2)).astype(np.float32) squares[i] = square """ find 24 possible macbeth chart centres by trasnforming normalised @@ -444,8 +444,8 @@ def get_macbeth_chart(img,ref_data): """ for j in range(len(square_verts)): verts = square_verts[j] - p_mat = cv2.getPerspectiveTransform(verts,square) - mac_guess = cv2.perspectiveTransform(mac_norm,p_mat) + p_mat = cv2.getPerspectiveTransform(verts, square) + mac_guess = cv2.perspectiveTransform(mac_norm, p_mat) mac_guess = np.round(mac_guess).astype(np.int32) """ keep only if candidate macbeth is within image border @@ -465,7 +465,7 @@ def get_macbeth_chart(img,ref_data): if in_border: mac_mid = np.mean(mac_guess, axis=1) - mac_mids.append([mac_mid,(i,j)]) + mac_mids.append([mac_mid, (i, j)]) if len(mac_mids) == 0: raise MacbethError( @@ -497,14 +497,14 @@ def get_macbeth_chart(img,ref_data): special case of only one valid centre found (probably not needed) """ clus_list = [] - clus_list.append([mac_mids,len(mac_mids)]) + clus_list.append([mac_mids, len(mac_mids)]) else: clustering.fit(mac_mids_list) # try: # clustering.fit(mac_mids_list) # except RuntimeWarning as error: - # return(0,None,None,error) + # return(0, None, None, error) """ create list of all clusters @@ -512,19 +512,19 @@ def get_macbeth_chart(img,ref_data): clus_list = [] 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] + indices = [j for j, x in enumerate(clustering.labels_) if x == i] clus = [] for index in indices: clus.append(mac_mids[index]) - clus_list.append([clus,len(clus)]) - clus_list.sort(key=lambda x:-x[1]) + clus_list.append([clus, len(clus)]) + clus_list.sort(key=lambda x: -x[1]) elif clustering.n_clusters_ == 1: """ special case of only one cluster found """ # print('only 1 cluster') - clus_list.append([mac_mids,len(mac_mids)]) + clus_list.append([mac_mids, len(mac_mids)]) else: raise MacbethError( '\nWARNING: No macebth chart found!' @@ -542,19 +542,19 @@ def get_macbeth_chart(img,ref_data): if clus_list[i][1] < clus_len_max * clus_tol: clus_list = clus_list[:i] break - cent = np.mean(clus_list[i][0],axis=0)[0] + cent = np.mean(clus_list[i][0], axis=0)[0] clus_list[i].append(cent) """ represent most popular cluster centroids """ # copy = original_bw.copy() - # copy = cv2.cvtColor(copy,cv2.COLOR_GRAY2RGB) - # copy = cv2.resize(copy,None,fx=2,fy=2) + # copy = cv2.cvtColor(copy, cv2.COLOR_GRAY2RGB) + # copy = cv2.resize(copy, None, fx=2, fy=2) # for clus in clus_list: # centroid = tuple(2*np.round(clus[2]).astype(np.int32)) - # cv2.circle(copy,centroid,7,(255,0,0),-1) - # cv2.circle(copy,centroid,2,(0,0,255),-1) + # cv2.circle(copy, centroid, 7, (255, 0, 0), -1) + # cv2.circle(copy, centroid, 2, (0, 0, 255), -1) # represent(copy) """ @@ -578,7 +578,7 @@ def get_macbeth_chart(img,ref_data): ref_cents = [] i_list = [p[1][0] for p in clus] for point in clus: - i,j = point[1] + i, j = point[1] """ remove any square that voted for two different points within the same cluster. This causes the same point in the image to be @@ -591,7 +591,7 @@ def get_macbeth_chart(img,ref_data): """ if i_list.count(i) == 1: square = squares_raw[i] - sq_cent = np.mean(square,axis=0) + sq_cent = np.mean(square, axis=0) ref_cent = reference[j] sq_cents.append(sq_cent) ref_cents.append(ref_cent) @@ -614,7 +614,7 @@ def get_macbeth_chart(img,ref_data): """ find best fit transform from normalised centres to image """ - h_mat,mask = cv2.findHomography(ref_cents,sq_cents) + h_mat, mask = cv2.findHomography(ref_cents, sq_cents) if 'None' in str(type(h_mat)): raise MacbethError( '\nERROR\n' @@ -623,8 +623,8 @@ def get_macbeth_chart(img,ref_data): """ transform normalised corners and centres into image space """ - mac_fit = cv2.perspectiveTransform(mac_norm,h_mat) - mac_cen_fit = cv2.perspectiveTransform(np.array([reference]),h_mat) + mac_fit = cv2.perspectiveTransform(mac_norm, h_mat) + mac_cen_fit = cv2.perspectiveTransform(np.array([reference]), h_mat) """ transform located corners into reference space """ @@ -633,18 +633,18 @@ def get_macbeth_chart(img,ref_data): np.array([ref_corns]) ) map_to_ref = cv2.warpPerspective( - original_bw,ref_mat, - (ref_w,ref_h) + original_bw, ref_mat, + (ref_w, ref_h) ) """ normalise brigthness """ a = 125/np.average(map_to_ref) - map_to_ref = cv2.convertScaleAbs(map_to_ref,alpha=a,beta=0) + map_to_ref = cv2.convertScaleAbs(map_to_ref, alpha=a, beta=0) """ find correlation with bw reference macbeth """ - cor = correlate(map_to_ref,ref) + cor = correlate(map_to_ref, ref) """ keep only if best correlation """ @@ -660,21 +660,21 @@ def get_macbeth_chart(img,ref_data): upside-down """ mac_fit_inv = np.array( - ([[mac_fit[0][2],mac_fit[0][3], - mac_fit[0][0],mac_fit[0][1]]]) + ([[mac_fit[0][2], mac_fit[0][3], + mac_fit[0][0], mac_fit[0][1]]]) ) - mac_cen_fit_inv = np.flip(mac_cen_fit,axis=1) + mac_cen_fit_inv = np.flip(mac_cen_fit, axis=1) ref_mat = cv2.getPerspectiveTransform( mac_fit_inv, np.array([ref_corns]) ) map_to_ref = cv2.warpPerspective( - original_bw,ref_mat, - (ref_w,ref_h) + original_bw, ref_mat, + (ref_w, ref_h) ) a = 125/np.average(map_to_ref) - map_to_ref = cv2.convertScaleAbs(map_to_ref,alpha=a,beta=0) - cor = correlate(map_to_ref,ref) + map_to_ref = cv2.convertScaleAbs(map_to_ref, alpha=a, beta=0) + cor = correlate(map_to_ref, ref) if cor > max_cor: max_cor = cor best_map = map_to_ref @@ -704,45 +704,45 @@ def get_macbeth_chart(img,ref_data): draw macbeth corners and centres on image """ copy = original.copy() - copy = cv2.resize(original,None,fx=2,fy=2) - # print('correlation = {}'.format(round(max_cor,2))) + copy = cv2.resize(original, None, fx=2, fy=2) + # print('correlation = {}'.format(round(max_cor, 2))) for point in best_fit[0]: - point = np.array(point,np.float32) + point = np.array(point, np.float32) point = tuple(2*np.round(point).astype(np.int32)) - cv2.circle(copy,point,4,(255,0,0),-1) + cv2.circle(copy, point, 4, (255, 0, 0), -1) for point in best_cen_fit[0]: - point = np.array(point,np.float32) + point = np.array(point, np.float32) point = tuple(2*np.round(point).astype(np.int32)) - cv2.circle(copy,point,4,(0,0,255),-1) + cv2.circle(copy, point, 4, (0, 0, 255), -1) copy = copy.copy() - cv2.circle(copy,point,4,(0,0,255),-1) + cv2.circle(copy, point, 4, (0, 0, 255), -1) """ represent coloured macbeth in reference space """ best_map_col = cv2.warpPerspective( - original,best_ref_mat,(ref_w,ref_h) + original, best_ref_mat, (ref_w, ref_h) ) best_map_col = cv2.resize( - best_map_col,None,fx=4,fy=4 + best_map_col, None, fx=4, fy=4 ) a = 125/np.average(best_map_col) best_map_col_norm = cv2.convertScaleAbs( - best_map_col,alpha=a,beta=0 + best_map_col, alpha=a, beta=0 ) - # cv2.imshow('Macbeth',best_map_col) + # cv2.imshow('Macbeth', best_map_col) # represent(copy) """ rescale coordinates to original image size """ - fit_coords = (best_fit/factor,best_cen_fit/factor) + fit_coords = (best_fit/factor, best_cen_fit/factor) - return(max_cor,best_map_col_norm,fit_coords,success_msg) + return(max_cor, best_map_col_norm, fit_coords, success_msg) """ catch macbeth errors and continue with code """ except MacbethError as error: - return(0,None,None,error) + return(0, None, None, error) diff --git a/utils/raspberrypi/ctt/ctt_noise.py b/utils/raspberrypi/ctt/ctt_noise.py index b84cf0ca9eb4..f258bc6d458c 100644 --- a/utils/raspberrypi/ctt/ctt_noise.py +++ b/utils/raspberrypi/ctt/ctt_noise.py @@ -12,7 +12,7 @@ Find noise standard deviation and fit to model: noise std = a + b*sqrt(pixel mean) """ -def noise(Cam,Img,plot): +def noise(Cam, Img, plot): Cam.log += '\nProcessing image: {}'.format(Img.name) stds = [] means = [] @@ -36,14 +36,14 @@ def noise(Cam,Img,plot): """ stds = np.array(stds) means = np.array(means) - means = np.clip(np.array(means),0,None) + means = np.clip(np.array(means), 0, None) sq_means = np.sqrt(means) """ least squares fit model """ - fit = np.polyfit(sq_means,stds,1) + fit = np.polyfit(sq_means, stds, 1) Cam.log += '\nBlack level = {}'.format(Img.blacklevel_16) Cam.log += '\nNoise profile: offset = {}'.format(int(fit[1])) Cam.log += ' slope = {:.3f}'.format(fit[0]) @@ -59,8 +59,8 @@ def noise(Cam,Img,plot): fit_score_norm = fit_score - fit_std anom_ind = np.where(fit_score_norm > 1) fit_score_norm.sort() - sq_means_clean = np.delete(sq_means,anom_ind) - stds_clean = np.delete(stds,anom_ind) + sq_means_clean = np.delete(sq_means, anom_ind) + stds_clean = np.delete(stds, anom_ind) removed = len(stds) - len(stds_clean) if removed != 0: Cam.log += '\nIdentified and removed {} anomalies.'.format(removed) @@ -68,7 +68,7 @@ def noise(Cam,Img,plot): """ recalculate fit with outliers removed """ - fit = np.polyfit(sq_means_clean,stds_clean,1) + fit = np.polyfit(sq_means_clean, stds_clean, 1) Cam.log += '\nNoise profile: offset = {}'.format(int(fit[1])) Cam.log += ' slope = {:.3f}'.format(fit[0]) @@ -81,7 +81,7 @@ def noise(Cam,Img,plot): corrected = 1 ones = np.ones(len(means)) y_data = stds/sq_means - fit2 = np.polyfit(ones,y_data,0) + fit2 = np.polyfit(ones, y_data, 0) Cam.log += '\nOffset below zero. Fit recalculated with zero offset' Cam.log += '\nNoise profile: offset = 0' Cam.log += ' slope = {:.3f}'.format(fit2[0]) @@ -94,13 +94,13 @@ def noise(Cam,Img,plot): if plot: x = np.arange(sq_means.max()//0.88) fit_plot = x*fit[0] + fit[1] - plt.scatter(sq_means,stds,label='data',color='blue') - plt.scatter(sq_means[anom_ind],stds[anom_ind],color='orange',label='anomalies') - plt.plot(x,fit_plot,label='fit',color='red',ls=':') + plt.scatter(sq_means, stds, label='data', color='blue') + plt.scatter(sq_means[anom_ind], stds[anom_ind], color='orange', label='anomalies') + plt.plot(x, fit_plot, label='fit', color='red', ls=':') if fit[1] < 0: fit_plot_2 = x*fit2[0] - plt.plot(x,fit_plot_2,label='fit 0 intercept',color='green',ls='--') - plt.plot(0,0) + plt.plot(x, fit_plot_2, label='fit 0 intercept', color='green', ls='--') + plt.plot(0, 0) plt.title('Noise Plot\nImg: {}'.format(Img.str)) plt.legend(loc = 'upper left') plt.xlabel('Sqrt Pixel Value') @@ -116,7 +116,7 @@ def noise(Cam,Img,plot): """ Cam.log += '\n' if corrected: - fit = [fit2[0],0] + fit = [fit2[0], 0] return fit else: diff --git a/utils/raspberrypi/ctt/ctt_ransac.py b/utils/raspberrypi/ctt/ctt_ransac.py index e7c571372e61..62d5cde826aa 100644 --- a/utils/raspberrypi/ctt/ctt_ransac.py +++ b/utils/raspberrypi/ctt/ctt_ransac.py @@ -11,59 +11,59 @@ scale = 2 """ constructs normalised macbeth chart corners for ransac algorithm """ -def get_square_verts(c_err = 0.05,scale = scale): +def get_square_verts(c_err = 0.05, scale = scale): """ define macbeth chart corners """ - b_bord_x,b_bord_y = scale*8.5,scale*13 + b_bord_x, b_bord_y = scale*8.5, scale*13 s_bord = 6*scale side = 41*scale x_max = side*6 + 5*s_bord + 2*b_bord_x y_max = side*4 + 3*s_bord + 2*b_bord_y - c1 = (0,0) - c2 = (0,y_max) - c3 = (x_max,y_max) - c4 = (x_max,0) - mac_norm = np.array((c1,c2,c3,c4),np.float32) + c1 = (0, 0) + c2 = (0, y_max) + c3 = (x_max, y_max) + c4 = (x_max, 0) + mac_norm = np.array((c1, c2, c3, c4), np.float32) mac_norm = np.array([ mac_norm ]) square_verts = [] - square_0 = np.array(((0,0),(0,side), - (side,side),(side,0)),np.float32) - offset_0 = np.array((b_bord_x,b_bord_y),np.float32) + square_0 = np.array(((0, 0), (0, side), + (side, side), (side, 0)), np.float32) + offset_0 = np.array((b_bord_x, b_bord_y), np.float32) c_off = side * c_err - offset_cont = np.array(((c_off,c_off),(c_off,-c_off), - (-c_off,-c_off),(-c_off,c_off)),np.float32) + offset_cont = np.array(((c_off, c_off), (c_off, -c_off), + (-c_off, -c_off), (-c_off, c_off)), np.float32) square_0 += offset_0 square_0 += offset_cont """ define macbeth square corners """ 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_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) square_i = square_0 + shift_i + shift_bord for j in range(4): - shift_j = np.array(((0,j*side),(0,j*side), - (0,j*side),(0,j*side)),np.float32) - shift_bord = np.array(((0,j*s_bord), - (0,j*s_bord),(0,j*s_bord), - (0,j*s_bord)),np.float32) + shift_j = np.array(((0, j*side), (0, j*side), + (0, j*side), (0, j*side)), np.float32) + shift_bord = np.array(((0, j*s_bord), + (0, j*s_bord), (0, j*s_bord), + (0, j*s_bord)), np.float32) square_j = square_i + shift_j + shift_bord square_verts.append(square_j) # print('square_verts') # print(square_verts) - return np.array(square_verts,np.float32),mac_norm + return np.array(square_verts, np.float32), mac_norm -def get_square_centres(c_err = 0.05,scale=scale): +def get_square_centres(c_err = 0.05, scale=scale): """ define macbeth square centres """ - verts,mac_norm = get_square_verts(c_err,scale=scale) + verts, mac_norm = get_square_verts(c_err, scale=scale) - centres = np.mean(verts,axis = 1) + centres = np.mean(verts, axis = 1) # print('centres') # print(centres) - return np.array(centres,np.float32) + return np.array(centres, np.float32) diff --git a/utils/raspberrypi/ctt/ctt_tools.py b/utils/raspberrypi/ctt/ctt_tools.py index 5a5cf54db6e2..67e882a24c37 100644 --- a/utils/raspberrypi/ctt/ctt_tools.py +++ b/utils/raspberrypi/ctt/ctt_tools.py @@ -26,7 +26,7 @@ readability in the main files. obtain config values, unless it doesnt exist, in which case pick default Furthermore, it can check if the input is the correct type """ -def get_config(dictt,key,default,ttype): +def get_config(dictt, key, default, ttype): try: val = dictt[key] if ttype == 'string': @@ -57,16 +57,16 @@ def parse_input(): raise ArgError('\n\nERROR! Enter value for each arguent passed.') params = arguments [0::2] vals = arguments [1::2] - args_dict = dict(zip(params,vals)) - json_output = get_config(args_dict,'-o',None,'string') - directory = get_config(args_dict,'-i',None,'string') - config = get_config(args_dict,'-c',None,'string') - log_path = get_config(args_dict,'-l',None,'string') + args_dict = dict(zip(params, vals)) + json_output = get_config(args_dict, '-o', None, 'string') + directory = get_config(args_dict, '-i', None, 'string') + config = get_config(args_dict, '-c', None, 'string') + log_path = get_config(args_dict, '-l', None, 'string') if directory == None: raise ArgError('\n\nERROR! No input directory given.') if json_output == None: raise ArgError('\n\nERROR! No output json given.') - return json_output,directory,config,log_path + return json_output, directory, config, log_path """ custom arg and macbeth error class """ @@ -78,10 +78,10 @@ class MacbethError(Exception): """ correlation function to quantify match """ -def correlate(im1,im2): +def correlate(im1, im2): f1 = im1.flatten() f2 = im2.flatten() - cor = np.corrcoef(f1,f2) + cor = np.corrcoef(f1, f2) return cor[0][1] """ @@ -97,13 +97,13 @@ def get_photos(directory='photos'): """ display image for debugging... read at your own risk... """ -def represent(img,name='image'): +def represent(img, name='image'): # if type(img) == tuple or type(img) == list: # for i in range(len(img)): # name = 'image {}'.format(i) - # cv2.imshow(name,img[i]) + # cv2.imshow(name, img[i]) # else: - # cv2.imshow(name,img) + # cv2.imshow(name, img) # cv2.waitKey(0) # cv2.destroyAllWindows() # return 0 @@ -112,11 +112,11 @@ def represent(img,name='image'): with their mouse to close the window.... therefore matplotlib is used.... (thanks a lot opencv) """ - grid = plt.GridSpec(22,1) - plt.subplot(grid[:19,0]) - plt.imshow(img,cmap='gray') + grid = plt.GridSpec(22, 1) + plt.subplot(grid[:19, 0]) + plt.imshow(img, cmap='gray') plt.axis('off') - plt.subplot(grid[21,0]) + plt.subplot(grid[21, 0]) plt.title('press \'q\' to continue') plt.axis('off') plt.show() @@ -124,7 +124,7 @@ def represent(img,name='image'): # f = plt.figure() # ax = f.add_subplot(211) # ax2 = f.add_subplot(122) - # ax.imshow(img,cmap='gray') + # ax.imshow(img, cmap='gray') # ax.axis('off') # ax2.set_figheight(2) # ax2.title('press \'q\' to continue') @@ -136,6 +136,6 @@ def represent(img,name='image'): reshape image to fixed width without distorting returns image and scale factor """ -def reshape(img,width): +def reshape(img, width): factor = width/img.shape[0] - return cv2.resize(img,None,fx=factor,fy=factor),factor + return cv2.resize(img, None, fx=factor, fy=factor), factor From patchwork Tue May 12 00:03:00 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laurent Pinchart X-Patchwork-Id: 3756 Return-Path: Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 9461E60DFD for ; Tue, 12 May 2020 02:03:33 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="nYNe/NJJ"; 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 1D92011F6; Tue, 12 May 2020 02:03:33 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1589241813; bh=z2brZA6ZwnjrQxMxTsbGpltZNyFexrlRm8iWN6SiJxE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=nYNe/NJJI2clXPPGJyqKC8Hsi1ZoqKquBwyPzUuaRadT2L2DblWNee/1UHuNGahyb fj5iEJiUtfWocZf5Qjju4LTXX1K7j+UUBMN2xAE+Ukjhfit7hF1fHVGO7rqlJr94S4 ZfoHYtp2nCMOyUZuK5uX26sKiJw9XAuXFk/Baml4= From: Laurent Pinchart To: libcamera-devel@lists.libcamera.org Date: Tue, 12 May 2020 03:03:00 +0300 Message-Id: <20200512000322.11753-3-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 02/24] utils: raspberrypi: ctt: Fix pycodestyle E201 and E202 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:34 -0000 E201 whitespace after '(' E201 whitespace after '{' E201 whitespace after '[' E202 whitespace before '}' E202 whitespace before ']' Signed-off-by: Laurent Pinchart --- utils/raspberrypi/ctt/ctt.py | 30 ++++++++++++++--------------- utils/raspberrypi/ctt/ctt_ccm.py | 12 ++++++------ utils/raspberrypi/ctt/ctt_geq.py | 2 +- utils/raspberrypi/ctt/ctt_ransac.py | 2 +- 4 files changed, 23 insertions(+), 23 deletions(-) diff --git a/utils/raspberrypi/ctt/ctt.py b/utils/raspberrypi/ctt/ctt.py index 3674d3107966..ba2dbd713e55 100755 --- a/utils/raspberrypi/ctt/ctt.py +++ b/utils/raspberrypi/ctt/ctt.py @@ -58,7 +58,7 @@ def get_col_lux(string): Still returns colour if that has been found. """ return col, None - return int( col ), int( lux ) + return int(col), int(lux) """ Camera object that is the backbone of the tuning tool. @@ -96,18 +96,18 @@ class Camera: }, "rpi.awb": { "priors" : [ - {"lux": 0, "prior": [ 2000, 1.0, 3000, 0.0, 13000, 0.0]}, - {"lux": 800, "prior": [ 2000, 0.0, 6000, 2.0, 13000, 2.0]}, - {"lux": 1500, "prior": [ 2000, 0.0, 4000, 1.0, 6000, 6.0, 6500, 7.0, 7000, 1.0, 13000, 1.0]} + {"lux": 0, "prior": [2000, 1.0, 3000, 0.0, 13000, 0.0]}, + {"lux": 800, "prior": [2000, 0.0, 6000, 2.0, 13000, 2.0]}, + {"lux": 1500, "prior": [2000, 0.0, 4000, 1.0, 6000, 6.0, 6500, 7.0, 7000, 1.0, 13000, 1.0]} ], "modes" : { - "auto" : { "lo" : 2500, "hi" : 8000 }, - "incandescent" : { "lo" : 2500, "hi" : 3000 }, - "tungsten" : { "lo" : 3000, "hi" : 3500 }, - "fluorescent" : { "lo" : 4000, "hi" : 4700 }, - "indoor" : { "lo" : 3000, "hi" : 5000 }, - "daylight" : { "lo" : 5500, "hi" : 6500 }, - "cloudy" : { "lo" : 7000, "hi" : 8600 } + "auto" : {"lo" : 2500, "hi" : 8000}, + "incandescent" : {"lo" : 2500, "hi" : 3000}, + "tungsten" : {"lo" : 3000, "hi" : 3500}, + "fluorescent" : {"lo" : 4000, "hi" : 4700}, + "indoor" : {"lo" : 3000, "hi" : 5000}, + "daylight" : {"lo" : 5500, "hi" : 6500}, + "cloudy" : {"lo" : 7000, "hi" : 8600} }, "bayes" : 1 }, @@ -129,8 +129,8 @@ class Camera: "gain" : [1.0, 2.0, 4.0, 6.0, 6.0] }, "sport": { - "shutter": [ 100, 5000, 10000, 20000, 120000 ], - "gain": [ 1.0, 2.0, 4.0, 6.0, 6.0 ] + "shutter": [100, 5000, 10000, 20000, 120000], + "gain": [1.0, 2.0, 4.0, 6.0, 6.0 ] } }, "constraint_modes" : { @@ -138,8 +138,8 @@ class Camera: {"bound" : "LOWER", "q_lo" : 0.98, "q_hi" : 1.0, "y_target" : [0, 0.5, 1000, 0.5]} ], "highlight": [ - { "bound": "LOWER", "q_lo": 0.98, "q_hi": 1.0, "y_target": [ 0, 0.5, 1000, 0.5 ] }, - { "bound": "UPPER", "q_lo": 0.98, "q_hi": 1.0, "y_target": [ 0, 0.8, 1000, 0.8 ] } + {"bound": "LOWER", "q_lo": 0.98, "q_hi": 1.0, "y_target": [0, 0.5, 1000, 0.5]}, + {"bound": "UPPER", "q_lo": 0.98, "q_hi": 1.0, "y_target": [0, 0.8, 1000, 0.8]} ] }, "y_target" : [0, 0.16, 1000, 0.165, 10000, 0.17] diff --git a/utils/raspberrypi/ctt/ctt_ccm.py b/utils/raspberrypi/ctt/ctt_ccm.py index 1771fc43327d..44fb81885368 100644 --- a/utils/raspberrypi/ctt/ctt_ccm.py +++ b/utils/raspberrypi/ctt/ctt_ccm.py @@ -168,12 +168,12 @@ def do_ccm(r, g, b, m_srgb): rb_gbs = (rb*gb) gb_2s = (gb*gb) - r_rbs = ( rb * (m_srgb[..., 0] - b) ) - r_gbs = ( gb * (m_srgb[..., 0] - b) ) - g_rbs = ( rb * (m_srgb[..., 1] - b) ) - g_gbs = ( gb * (m_srgb[..., 1] - b) ) - b_rbs = ( rb * (m_srgb[..., 2] - b) ) - b_gbs = ( gb * (m_srgb[..., 2] - b) ) + r_rbs = rb * (m_srgb[..., 0] - b) + r_gbs = gb * (m_srgb[..., 0] - b) + g_rbs = rb * (m_srgb[..., 1] - b) + g_gbs = gb * (m_srgb[..., 1] - b) + b_rbs = rb * (m_srgb[..., 2] - b) + b_gbs = gb * (m_srgb[..., 2] - b) """ Obtain least squares fit diff --git a/utils/raspberrypi/ctt/ctt_geq.py b/utils/raspberrypi/ctt/ctt_geq.py index f8395e437fe6..175986409edd 100644 --- a/utils/raspberrypi/ctt/ctt_geq.py +++ b/utils/raspberrypi/ctt/ctt_geq.py @@ -20,7 +20,7 @@ def geq_fit(Cam, plot): Fits geq model by looking at difference between greens in macbeth patches """ - geqs = np.array([ geq(Cam, Img)*Img.againQ8_norm for Img in imgs ]) + geqs = np.array([geq(Cam, Img)*Img.againQ8_norm for Img in imgs]) Cam.log += '\nProcessed all images' geqs = geqs.reshape((-1, 2)) """ diff --git a/utils/raspberrypi/ctt/ctt_ransac.py b/utils/raspberrypi/ctt/ctt_ransac.py index 62d5cde826aa..a15136254a9e 100644 --- a/utils/raspberrypi/ctt/ctt_ransac.py +++ b/utils/raspberrypi/ctt/ctt_ransac.py @@ -25,7 +25,7 @@ def get_square_verts(c_err = 0.05, scale = scale): c3 = (x_max, y_max) c4 = (x_max, 0) mac_norm = np.array((c1, c2, c3, c4), np.float32) - mac_norm = np.array([ mac_norm ]) + mac_norm = np.array([mac_norm]) square_verts = [] square_0 = np.array(((0, 0), (0, side), From patchwork Tue May 12 00:03:01 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laurent Pinchart X-Patchwork-Id: 3757 Return-Path: Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 1A57D603DD for ; Tue, 12 May 2020 02:03:34 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="KblTadHX"; 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 8979433E; Tue, 12 May 2020 02:03:33 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1589241813; bh=Kh4M/7iI1kfevDFdWopkc+JbYL9m2fnRhO1IBmSJfdY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=KblTadHXsBLdt09zN/PgmqGJmQI5IGN2WH+6pUA7OD+457nxyPyQlcEN4W7ycTeH8 nUdxxYeez68OH0z2XeGNP08DC6FnzNNC7lHPKg66gMvE4xzECchFCMKXhx1hu8u9Ju L9jd4BNuhYDng/NqfPqY2ebkRPVaY++TdvZzcgHI= From: Laurent Pinchart To: libcamera-devel@lists.libcamera.org Date: Tue, 12 May 2020 03:03:01 +0300 Message-Id: <20200512000322.11753-4-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 03/24] utils: raspberrypi: ctt: Fix pycodestyle E203 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:34 -0000 E203 whitespace before ':' Signed-off-by: Laurent Pinchart --- utils/raspberrypi/ctt/ctt.py | 70 +++++++++---------- utils/raspberrypi/ctt/ctt_awb.py | 2 +- utils/raspberrypi/ctt/ctt_ccm.py | 4 +- utils/raspberrypi/ctt/ctt_image_load.py | 10 +-- utils/raspberrypi/ctt/ctt_macbeth_locator.py | 2 +- .../raspberrypi/ctt/ctt_pretty_print_json.py | 2 +- 6 files changed, 45 insertions(+), 45 deletions(-) diff --git a/utils/raspberrypi/ctt/ctt.py b/utils/raspberrypi/ctt/ctt.py index ba2dbd713e55..97cadfe8ab82 100755 --- a/utils/raspberrypi/ctt/ctt.py +++ b/utils/raspberrypi/ctt/ctt.py @@ -78,78 +78,78 @@ class Camera: initial json dict populated by uncalibrated values """ self.json = { - "rpi.black_level" : { - "black_level" : 4096 + "rpi.black_level": { + "black_level": 4096 }, - "rpi.dpc" : { + "rpi.dpc": { }, - "rpi.lux" : { + "rpi.lux": { "reference_shutter_speed": 10000, "reference_gain": 1, "reference_aperture": 1.0 }, - "rpi.noise" : { + "rpi.noise": { }, - "rpi.geq" : { + "rpi.geq": { }, "rpi.sdn": { }, "rpi.awb": { - "priors" : [ + "priors": [ {"lux": 0, "prior": [2000, 1.0, 3000, 0.0, 13000, 0.0]}, {"lux": 800, "prior": [2000, 0.0, 6000, 2.0, 13000, 2.0]}, {"lux": 1500, "prior": [2000, 0.0, 4000, 1.0, 6000, 6.0, 6500, 7.0, 7000, 1.0, 13000, 1.0]} ], - "modes" : { - "auto" : {"lo" : 2500, "hi" : 8000}, - "incandescent" : {"lo" : 2500, "hi" : 3000}, - "tungsten" : {"lo" : 3000, "hi" : 3500}, - "fluorescent" : {"lo" : 4000, "hi" : 4700}, - "indoor" : {"lo" : 3000, "hi" : 5000}, - "daylight" : {"lo" : 5500, "hi" : 6500}, - "cloudy" : {"lo" : 7000, "hi" : 8600} + "modes": { + "auto": {"lo": 2500, "hi": 8000}, + "incandescent": {"lo": 2500, "hi": 3000}, + "tungsten": {"lo": 3000, "hi": 3500}, + "fluorescent": {"lo": 4000, "hi": 4700}, + "indoor": {"lo": 3000, "hi": 5000}, + "daylight": {"lo": 5500, "hi": 6500}, + "cloudy": {"lo": 7000, "hi": 8600} }, - "bayes" : 1 + "bayes": 1 }, - "rpi.agc" : { - "metering_modes" : { - "centre-weighted" : { - "weights" : [3, 3, 3, 2, 2, 2, 2, 1, 1, 1, 1, 0, 0, 0, 0] + "rpi.agc": { + "metering_modes": { + "centre-weighted": { + "weights": [3, 3, 3, 2, 2, 2, 2, 1, 1, 1, 1, 0, 0, 0, 0] }, - "spot" : { - "weights" : [2, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0] + "spot": { + "weights": [2, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0] }, "matrix": { - "weights" : [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1] + "weights": [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1] } }, - "exposure_modes" : { - "normal" : { - "shutter" : [100, 10000, 30000, 60000, 120000], - "gain" : [1.0, 2.0, 4.0, 6.0, 6.0] + "exposure_modes": { + "normal": { + "shutter": [100, 10000, 30000, 60000, 120000], + "gain": [1.0, 2.0, 4.0, 6.0, 6.0] }, "sport": { "shutter": [100, 5000, 10000, 20000, 120000], "gain": [1.0, 2.0, 4.0, 6.0, 6.0 ] } }, - "constraint_modes" : { - "normal" : [ - {"bound" : "LOWER", "q_lo" : 0.98, "q_hi" : 1.0, "y_target" : [0, 0.5, 1000, 0.5]} + "constraint_modes": { + "normal": [ + {"bound": "LOWER", "q_lo": 0.98, "q_hi": 1.0, "y_target": [0, 0.5, 1000, 0.5]} ], "highlight": [ {"bound": "LOWER", "q_lo": 0.98, "q_hi": 1.0, "y_target": [0, 0.5, 1000, 0.5]}, {"bound": "UPPER", "q_lo": 0.98, "q_hi": 1.0, "y_target": [0, 0.8, 1000, 0.8]} ] }, - "y_target" : [0, 0.16, 1000, 0.165, 10000, 0.17] + "y_target": [0, 0.16, 1000, 0.165, 10000, 0.17] }, "rpi.alsc": { - 'omega' : 1.3, - 'n_iter' : 100, - 'luminance_strength' : 0.7, + 'omega': 1.3, + 'n_iter': 100, + 'luminance_strength': 0.7, }, - "rpi.contrast" : { + "rpi.contrast": { "ce_enable": 1, "gamma_curve": [ 0, 0, diff --git a/utils/raspberrypi/ctt/ctt_awb.py b/utils/raspberrypi/ctt/ctt_awb.py index 9a92033bf2db..297ba178b35f 100644 --- a/utils/raspberrypi/ctt/ctt_awb.py +++ b/utils/raspberrypi/ctt/ctt_awb.py @@ -197,7 +197,7 @@ def awb(Cam, cal_cr_list, cal_cb_list, plot): iterate backwards over list for easier indexing """ i = len(c_fit) - 1 - while i > 0 : + while i > 0: if c_fit[i] > c_fit[i-1]: Cam.log += '\nColour temperature increase found\n' Cam.log += '{} K at r = {} to '.format(c_fit[i-1], r_fit[i-1]) diff --git a/utils/raspberrypi/ctt/ctt_ccm.py b/utils/raspberrypi/ctt/ctt_ccm.py index 44fb81885368..769603b947c5 100644 --- a/utils/raspberrypi/ctt/ctt_ccm.py +++ b/utils/raspberrypi/ctt/ctt_ccm.py @@ -148,8 +148,8 @@ def ccm(Cam, cal_cr_list, cal_cb_list): ccms = [] for i in sorted_ccms: ccms.append({ - 'ct' : i[0], - 'ccm' : i[1] + 'ct': i[0], + 'ccm': i[1] }) return ccms diff --git a/utils/raspberrypi/ctt/ctt_image_load.py b/utils/raspberrypi/ctt/ctt_image_load.py index 7d097118c16c..035256e3fd0b 100644 --- a/utils/raspberrypi/ctt/ctt_image_load.py +++ b/utils/raspberrypi/ctt/ctt_image_load.py @@ -45,11 +45,11 @@ class Image: Channel order depending on bayer pattern """ bayer_case = { - 0 : (0, 1, 2, 3), #red - 1 : (2, 0, 3, 1), #green next to red - 2 : (3, 2, 1, 0), #green next to blue - 3 : (1, 0, 3, 2), #blue - 128 : (0, 1, 2, 3) #arbitrary order for greyscale casw + 0: (0, 1, 2, 3), #red + 1: (2, 0, 3, 1), #green next to red + 2: (3, 2, 1, 0), #green next to blue + 3: (1, 0, 3, 2), #blue + 128: (0, 1, 2, 3) #arbitrary order for greyscale casw } self.order = bayer_case[self.pattern] diff --git a/utils/raspberrypi/ctt/ctt_macbeth_locator.py b/utils/raspberrypi/ctt/ctt_macbeth_locator.py index 591459aa4cc5..949e3686bc15 100644 --- a/utils/raspberrypi/ctt/ctt_macbeth_locator.py +++ b/utils/raspberrypi/ctt/ctt_macbeth_locator.py @@ -180,7 +180,7 @@ def find_macbeth(Cam, img, mac_config=(0, 0)): if small_chart: - if cor < 0.75 and d_best > 1 : + if cor < 0.75 and d_best > 1: imgs = [] shape = list(img.shape[:2]) w, h = shape diff --git a/utils/raspberrypi/ctt/ctt_pretty_print_json.py b/utils/raspberrypi/ctt/ctt_pretty_print_json.py index 44a9311b5e76..63b042de58d4 100644 --- a/utils/raspberrypi/ctt/ctt_pretty_print_json.py +++ b/utils/raspberrypi/ctt/ctt_pretty_print_json.py @@ -61,7 +61,7 @@ def process_char(c, fout, state): state["skipnewline"] = (c == '[') def pretty_print_json(str_in, output_filename): - state = {"indent": 0, "inarray": [False], "arraycount": [], "skipnewline" : True} + state = {"indent": 0, "inarray": [False], "arraycount": [], "skipnewline": True} with open(output_filename, "w") as fout: process_file(str_in, fout, state) From patchwork Tue May 12 00:03:02 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laurent Pinchart X-Patchwork-Id: 3758 Return-Path: Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 76B5E60DF6 for ; Tue, 12 May 2020 02:03:34 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="pdzqcHM6"; 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 0323111F3; Tue, 12 May 2020 02:03:33 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1589241814; bh=FFvjFp3otmnWWGLnOYVefLRaRJuLfnFECpXr3/G3pTE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=pdzqcHM6SwyJPGHcMibr563AEurVBmrFNWc89dESGy2mRG/uHfv2qlIRDwUnyvMDA A6ffkLbbyiZaLsOIZhl48TNi7UsmfhMLjA0Rvp6bn3VTf2y1+8y06Llro95wSdoY/M 7RSAv21FEpkhPBu8kIFul7w2AzuC6+2dWvU0laHU= From: Laurent Pinchart To: libcamera-devel@lists.libcamera.org Date: Tue, 12 May 2020 03:03:02 +0300 Message-Id: <20200512000322.11753-5-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 04/24] utils: raspberrypi: ctt: Fix pycodestyle E241 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:34 -0000 E241 multiple spaces after ':' E241 multiple spaces after ',' Signed-off-by: Laurent Pinchart --- utils/raspberrypi/ctt/ctt.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/utils/raspberrypi/ctt/ctt.py b/utils/raspberrypi/ctt/ctt.py index 97cadfe8ab82..743ee3bca448 100755 --- a/utils/raspberrypi/ctt/ctt.py +++ b/utils/raspberrypi/ctt/ctt.py @@ -126,11 +126,11 @@ class Camera: "exposure_modes": { "normal": { "shutter": [100, 10000, 30000, 60000, 120000], - "gain": [1.0, 2.0, 4.0, 6.0, 6.0] + "gain": [1.0, 2.0, 4.0, 6.0, 6.0] }, "sport": { "shutter": [100, 5000, 10000, 20000, 120000], - "gain": [1.0, 2.0, 4.0, 6.0, 6.0 ] + "gain": [1.0, 2.0, 4.0, 6.0, 6.0] } }, "constraint_modes": { From patchwork Tue May 12 00:03:03 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laurent Pinchart X-Patchwork-Id: 3759 Return-Path: Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id E4C8F60DF6 for ; Tue, 12 May 2020 02:03:34 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="lA//dv+M"; 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 6B1D6120C; Tue, 12 May 2020 02:03:34 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1589241814; bh=aMEuWOdei/4lCDx/nzZsAHnizpF6JXxW55swJYKX6QM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=lA//dv+MME9aE29ARRDlE0ns/8JGgUb/jILkeA2+bDgvXpKUJL9gh61LJ6OutJwNy 931PmYSAdju5ygSThdgWJFl8ILUdv1R6aNdwAZbFmtozdjDwD+JeIaaXcUOUcgBzSv 0mspycng/7KrU2cLc4rXDqP2ioic9D5WJileNe3Q= From: Laurent Pinchart To: libcamera-devel@lists.libcamera.org Date: Tue, 12 May 2020 03:03:03 +0300 Message-Id: <20200512000322.11753-6-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 05/24] utils: raspberrypi: ctt: Fix pycodestyle E211 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:35 -0000 E211 whitespace before '[' Signed-off-by: Laurent Pinchart --- utils/raspberrypi/ctt/ctt_tools.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/utils/raspberrypi/ctt/ctt_tools.py b/utils/raspberrypi/ctt/ctt_tools.py index 67e882a24c37..f00f2bbc8299 100644 --- a/utils/raspberrypi/ctt/ctt_tools.py +++ b/utils/raspberrypi/ctt/ctt_tools.py @@ -55,8 +55,8 @@ def parse_input(): arguments = sys.argv[1:] if len(arguments)%2 != 0: raise ArgError('\n\nERROR! Enter value for each arguent passed.') - params = arguments [0::2] - vals = arguments [1::2] + params = arguments[0::2] + vals = arguments[1::2] args_dict = dict(zip(params, vals)) json_output = get_config(args_dict, '-o', None, 'string') directory = get_config(args_dict, '-i', None, 'string') From patchwork Tue May 12 00:03:04 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laurent Pinchart X-Patchwork-Id: 3760 Return-Path: Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 64B5560DFE for ; Tue, 12 May 2020 02:03:35 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="V0r9IGbo"; 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 D1A6133E; Tue, 12 May 2020 02:03:34 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1589241815; bh=GwNfAeCxzceUjHYmDgv3fDdlQ4dd9EblNIbci8FerZ4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=V0r9IGbo1bZqRoxE2fpNLzDnz/sO7yxNSm1uR16UHN17Yfoi4z4KOLSZkfhIGzEo/ 6drvR+AL3YTDRqY3723xuL6mVNABDN+EgK/PDfZve9IizAewYQBV4fTK7iPOuS5oLn cpITvXMvXhcpbsiIJnVP/TSVoGiiAqv9s4DIkiW8= From: Laurent Pinchart To: libcamera-devel@lists.libcamera.org Date: Tue, 12 May 2020 03:03:04 +0300 Message-Id: <20200512000322.11753-7-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 06/24] utils: raspberrypi: ctt: Fix pycodestyle E251 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:35 -0000 E251 unexpected spaces around keyword / parameter equals Signed-off-by: Laurent Pinchart --- utils/raspberrypi/ctt/ctt.py | 2 +- utils/raspberrypi/ctt/ctt_alsc.py | 2 +- utils/raspberrypi/ctt/ctt_geq.py | 2 +- utils/raspberrypi/ctt/ctt_macbeth_locator.py | 4 ++-- utils/raspberrypi/ctt/ctt_noise.py | 2 +- utils/raspberrypi/ctt/ctt_ransac.py | 6 +++--- 6 files changed, 9 insertions(+), 9 deletions(-) diff --git a/utils/raspberrypi/ctt/ctt.py b/utils/raspberrypi/ctt/ctt.py index 743ee3bca448..46cf92cd75a2 100755 --- a/utils/raspberrypi/ctt/ctt.py +++ b/utils/raspberrypi/ctt/ctt.py @@ -474,7 +474,7 @@ class Camera: run calibration on all images and sort by slope. """ plot = "rpi.noise" in self.plot - noise_out = sorted([noise(self, Img, plot) for Img in self.imgs], key = lambda x: x[0]) + noise_out = sorted([noise(self, Img, plot) for Img in self.imgs], key=lambda x: x[0]) self.log += '\nFinished processing images' """ take the average of the interquartile diff --git a/utils/raspberrypi/ctt/ctt_alsc.py b/utils/raspberrypi/ctt/ctt_alsc.py index cd99495f6bef..a006f7ffa9c9 100644 --- a/utils/raspberrypi/ctt/ctt_alsc.py +++ b/utils/raspberrypi/ctt/ctt_alsc.py @@ -131,7 +131,7 @@ def alsc(Cam, Img, do_alsc_colour, plot=False): """ average the green channels into one """ - av_ch_g = np.mean((channels[1:2]), axis = 0) + av_ch_g = np.mean((channels[1:2]), axis=0) if do_alsc_colour: """ obtain 16x12 grid of intensities for each channel and subtract black level diff --git a/utils/raspberrypi/ctt/ctt_geq.py b/utils/raspberrypi/ctt/ctt_geq.py index 175986409edd..1ffa4e91b1b7 100644 --- a/utils/raspberrypi/ctt/ctt_geq.py +++ b/utils/raspberrypi/ctt/ctt_geq.py @@ -27,7 +27,7 @@ def geq_fit(Cam, plot): data is sorted by green difference and top half is selected since higher green difference data define the decision boundary. """ - geqs = np.array(sorted(geqs, key = lambda r: np.abs((r[1]-r[0])/r[0]))) + geqs = np.array(sorted(geqs, key=lambda r: np.abs((r[1]-r[0])/r[0]))) length = len(geqs) g0 = geqs[length//2:, 0] diff --git a/utils/raspberrypi/ctt/ctt_macbeth_locator.py b/utils/raspberrypi/ctt/ctt_macbeth_locator.py index 949e3686bc15..55ab4fdbc17d 100644 --- a/utils/raspberrypi/ctt/ctt_macbeth_locator.py +++ b/utils/raspberrypi/ctt/ctt_macbeth_locator.py @@ -487,8 +487,8 @@ def get_macbeth_chart(img, ref_data): """ clustering = cluster.AgglomerativeClustering( n_clusters=None, - compute_full_tree = True, - distance_threshold = side*2 + compute_full_tree=True, + distance_threshold=side*2 ) mac_mids_list = [x[0] for x in mac_mids] diff --git a/utils/raspberrypi/ctt/ctt_noise.py b/utils/raspberrypi/ctt/ctt_noise.py index f258bc6d458c..2d021e550f85 100644 --- a/utils/raspberrypi/ctt/ctt_noise.py +++ b/utils/raspberrypi/ctt/ctt_noise.py @@ -102,7 +102,7 @@ def noise(Cam, Img, plot): plt.plot(x, fit_plot_2, label='fit 0 intercept', color='green', ls='--') plt.plot(0, 0) plt.title('Noise Plot\nImg: {}'.format(Img.str)) - plt.legend(loc = 'upper left') + plt.legend(loc='upper left') plt.xlabel('Sqrt Pixel Value') plt.ylabel('Noise Standard Deviation') plt.grid() diff --git a/utils/raspberrypi/ctt/ctt_ransac.py b/utils/raspberrypi/ctt/ctt_ransac.py index a15136254a9e..f7a722e0f73e 100644 --- a/utils/raspberrypi/ctt/ctt_ransac.py +++ b/utils/raspberrypi/ctt/ctt_ransac.py @@ -11,7 +11,7 @@ scale = 2 """ constructs normalised macbeth chart corners for ransac algorithm """ -def get_square_verts(c_err = 0.05, scale = scale): +def get_square_verts(c_err=0.05, scale=scale): """ define macbeth chart corners """ @@ -57,13 +57,13 @@ def get_square_verts(c_err = 0.05, scale = scale): # print(square_verts) return np.array(square_verts, np.float32), mac_norm -def get_square_centres(c_err = 0.05, scale=scale): +def get_square_centres(c_err=0.05, scale=scale): """ define macbeth square centres """ verts, mac_norm = get_square_verts(c_err, scale=scale) - centres = np.mean(verts, axis = 1) + centres = np.mean(verts, axis=1) # print('centres') # print(centres) return np.array(centres, np.float32) From patchwork Tue May 12 00:03:05 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laurent Pinchart X-Patchwork-Id: 3761 Return-Path: Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 4346A60E0B 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="aqQgAac1"; 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 4F52711F3; Tue, 12 May 2020 02:03:35 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1589241815; bh=9kszIlv6hGVElr0z1u3vpJASMnkd+qi1tKYUZU1G+Kk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=aqQgAac1mmURK4r4/k0Jr8crx+eZ/6mSCkZtMjCv3Z9DzcNHuJ2ej2XZYxUdryN+j /WmyFyOps0bF0TlmW/deDPVygPuG2/HLL45mm9PS0uo5w9PHDmy8UtHdyLFuzuw47J vvknNXSWGGhUsPEgzYQs10G3tQeI1XYSbvW/WZms= From: Laurent Pinchart To: libcamera-devel@lists.libcamera.org Date: Tue, 12 May 2020 03:03:05 +0300 Message-Id: <20200512000322.11753-8-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 07/24] utils: raspberrypi: ctt: Fix pycodestyle E128 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 E128 continuation line under-indented for visual indent Signed-off-by: Laurent Pinchart --- utils/raspberrypi/ctt/ctt_macbeth_locator.py | 8 +++----- utils/raspberrypi/ctt/ctt_ransac.py | 14 +++++++------- 2 files changed, 10 insertions(+), 12 deletions(-) diff --git a/utils/raspberrypi/ctt/ctt_macbeth_locator.py b/utils/raspberrypi/ctt/ctt_macbeth_locator.py index 55ab4fdbc17d..63dbc4a1f347 100644 --- a/utils/raspberrypi/ctt/ctt_macbeth_locator.py +++ b/utils/raspberrypi/ctt/ctt_macbeth_locator.py @@ -363,9 +363,8 @@ def get_macbeth_chart(img, ref_data): """ find Contours in image """ - conts, _ = cv2.findContours(edges, - cv2.RETR_TREE, - cv2.CHAIN_APPROX_NONE) + conts, _ = cv2.findContours(edges, cv2.RETR_TREE, + cv2.CHAIN_APPROX_NONE) if len(conts) == 0: raise MacbethError( '\nWARNING: No macbeth chart found!' @@ -381,8 +380,7 @@ def get_macbeth_chart(img, ref_data): conts_per = [] for i in range(len(conts)): per = cv2.arcLength(conts[i], True) - poly = cv2.approxPolyDP(conts[i], - epsilon*per, True) + poly = cv2.approxPolyDP(conts[i], epsilon*per, True) if len(poly) == 4 and cv2.isContourConvex(poly): conts_per.append((poly, per)) diff --git a/utils/raspberrypi/ctt/ctt_ransac.py b/utils/raspberrypi/ctt/ctt_ransac.py index f7a722e0f73e..a1f5e8c95ac1 100644 --- a/utils/raspberrypi/ctt/ctt_ransac.py +++ b/utils/raspberrypi/ctt/ctt_ransac.py @@ -29,11 +29,11 @@ def get_square_verts(c_err=0.05, scale=scale): square_verts = [] square_0 = np.array(((0, 0), (0, side), - (side, side), (side, 0)), np.float32) + (side, side), (side, 0)), np.float32) offset_0 = np.array((b_bord_x, b_bord_y), np.float32) c_off = side * c_err offset_cont = np.array(((c_off, c_off), (c_off, -c_off), - (-c_off, -c_off), (-c_off, c_off)), np.float32) + (-c_off, -c_off), (-c_off, c_off)), np.float32) square_0 += offset_0 square_0 += offset_cont """ @@ -41,16 +41,16 @@ 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) + (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) + (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), - (0, j*side), (0, j*side)), np.float32) + (0, j*side), (0, j*side)), np.float32) shift_bord = np.array(((0, j*s_bord), - (0, j*s_bord), (0, j*s_bord), - (0, j*s_bord)), np.float32) + (0, j*s_bord), (0, j*s_bord), + (0, j*s_bord)), np.float32) square_j = square_i + shift_j + shift_bord square_verts.append(square_j) # print('square_verts') 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), From patchwork Tue May 12 00:03:07 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laurent Pinchart X-Patchwork-Id: 3763 Return-Path: Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 49AB060DFD for ; Tue, 12 May 2020 02:03:37 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="bmOpZ7l7"; 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 CC37511F3; 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=1589241817; bh=4sMYn1cJBGuuSh8FWbz9/sstOgpWR4dBKg1PDOeKqV8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=bmOpZ7l7K/tyb4gCGXHPwl3e25o5q5KYGBw4TtFSBLg88o9uBcF1sV0LgP24vJuIn fKSPZ1ikWK7gvBTwzZt/srypvddjVYSx4kqk+p3GyFWKBrmpcmOlc5cJrqsSfJsUot gjzQpqE62jXICkaVmE6iDt3zJYWr52tPc2QQ0aKE= From: Laurent Pinchart To: libcamera-devel@lists.libcamera.org Date: Tue, 12 May 2020 03:03:07 +0300 Message-Id: <20200512000322.11753-10-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 09/24] utils: raspberrypi: ctt: Fix pycodestyle E228 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 E228 missing whitespace around modulo operator Signed-off-by: Laurent Pinchart --- utils/raspberrypi/ctt/ctt_alsc.py | 12 ++++++------ utils/raspberrypi/ctt/ctt_awb.py | 10 +++++----- utils/raspberrypi/ctt/ctt_ccm.py | 4 ++-- utils/raspberrypi/ctt/ctt_image_load.py | 12 ++++++------ utils/raspberrypi/ctt/ctt_tools.py | 2 +- 5 files changed, 20 insertions(+), 20 deletions(-) diff --git a/utils/raspberrypi/ctt/ctt_alsc.py b/utils/raspberrypi/ctt/ctt_alsc.py index d6e1020f1ccc..e768f8d648a1 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 3abafbf550b0..58ef8432fb86 100644 --- a/utils/raspberrypi/ctt/ctt_awb.py +++ b/utils/raspberrypi/ctt/ctt_awb.py @@ -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) """ @@ -326,7 +326,7 @@ def get_alsc_patches(Img, colour_cals, grey=True): if img colour is below minimum or above maximum alsc calibration colour, simply pick extreme closest to img colour """ - if pos%(len(cts)) == 0: + if pos % len(cts) == 0: """ this works because -0 = 0 = first and -1 = last index """ diff --git a/utils/raspberrypi/ctt/ctt_ccm.py b/utils/raspberrypi/ctt/ctt_ccm.py index 52fd9744332a..adc4d290ae7e 100644 --- a/utils/raspberrypi/ctt/ctt_ccm.py +++ b/utils/raspberrypi/ctt/ctt_ccm.py @@ -135,8 +135,8 @@ def ccm(Cam, cal_cr_list, cal_cb_list): """ for k, v in ccm_tab.items(): 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.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_image_load.py b/utils/raspberrypi/ctt/ctt_image_load.py index 035256e3fd0b..584e0f8ebaa5 100644 --- a/utils/raspberrypi/ctt/ctt_image_load.py +++ b/utils/raspberrypi/ctt/ctt_image_load.py @@ -112,10 +112,10 @@ class Image: """ assemble 10 bit numbers """ - ch0 = np.left_shift((np.left_shift(ba0, 2) + (ba4%4)), 6) - ch1 = np.left_shift((np.left_shift(ba1, 2) + (np.right_shift(ba4, 2)%4)), 6) - ch2 = np.left_shift((np.left_shift(ba2, 2) + (np.right_shift(ba4, 4)%4)), 6) - ch3 = np.left_shift((np.left_shift(ba3, 2) + (np.right_shift(ba4, 6)%4)), 6) + ch0 = np.left_shift((np.left_shift(ba0, 2) + (ba4 % 4)), 6) + ch1 = np.left_shift((np.left_shift(ba1, 2) + (np.right_shift(ba4, 2) % 4)), 6) + ch2 = np.left_shift((np.left_shift(ba2, 2) + (np.right_shift(ba4, 4) % 4)), 6) + ch3 = np.left_shift((np.left_shift(ba3, 2) + (np.right_shift(ba4, 6) % 4)), 6) """ interleave bits """ @@ -146,8 +146,8 @@ class Image: ba0 = raw[..., 0:3*((self.w+1)>>1):3] ba1 = raw[..., 1:3*((self.w+1)>>1):3] ba2 = raw[..., 2:3*((self.w+1)>>1):3] - ch0 = np.left_shift((np.left_shift(ba0, 4) + ba2%16), 4) - ch1 = np.left_shift((np.left_shift(ba1, 4) + (np.right_shift(ba2, 4))%16), 4) + ch0 = np.left_shift((np.left_shift(ba0, 4) + ba2 % 16), 4) + ch1 = np.left_shift((np.left_shift(ba1, 4) + (np.right_shift(ba2, 4)) % 16), 4) mat = np.empty((self.h, self.w), dtype=ch0.dtype) mat[..., 0::2] = ch0 mat[..., 1::2] = ch1 diff --git a/utils/raspberrypi/ctt/ctt_tools.py b/utils/raspberrypi/ctt/ctt_tools.py index f00f2bbc8299..e5871b60d6a2 100644 --- a/utils/raspberrypi/ctt/ctt_tools.py +++ b/utils/raspberrypi/ctt/ctt_tools.py @@ -53,7 +53,7 @@ argument parser """ def parse_input(): arguments = sys.argv[1:] - if len(arguments)%2 != 0: + if len(arguments) % 2 != 0: raise ArgError('\n\nERROR! Enter value for each arguent passed.') params = arguments[0::2] vals = arguments[1::2] From patchwork Tue May 12 00:03:08 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laurent Pinchart X-Patchwork-Id: 3764 Return-Path: Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id BB3C760E02 for ; Tue, 12 May 2020 02:03:37 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="tQZsHeRp"; 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 3EA5011F6; Tue, 12 May 2020 02:03:37 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1589241817; bh=XO4ctOb0RM4hvW/LScPpZUcwf3DJVM2j0VRFCCIyG74=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=tQZsHeRpb18hu5BXMsCD3NkWoRgWdhq4B6g4kMQ0/krJ4lbRS2XfJbILO+NDTayyY H5g+qkrKerYc+86alKrE0d6roLa6cMBTU1WUEH3AamnOim6V/Cf3dgcStxwe5DKZXK VLMFey0jLEzTj4W1OPGCnIawA/r2fGDakLkff2WA= From: Laurent Pinchart To: libcamera-devel@lists.libcamera.org Date: Tue, 12 May 2020 03:03:08 +0300 Message-Id: <20200512000322.11753-11-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 10/24] utils: raspberrypi: ctt: Fix pycodestyle E701 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 E701 multiple statements on one line (colon) Signed-off-by: Laurent Pinchart --- utils/raspberrypi/ctt/ctt_pretty_print_json.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/utils/raspberrypi/ctt/ctt_pretty_print_json.py b/utils/raspberrypi/ctt/ctt_pretty_print_json.py index 63b042de58d4..fac9e98ba9dd 100644 --- a/utils/raspberrypi/ctt/ctt_pretty_print_json.py +++ b/utils/raspberrypi/ctt/ctt_pretty_print_json.py @@ -17,7 +17,8 @@ def print_newline(fout, state): def process_char(c, fout, state): if c == '{': - if not state["skipnewline"]: print_newline(fout, state) + if not state["skipnewline"]: + print_newline(fout, state) fout.write(c) state["indent"] += 1 print_newline(fout, state) From patchwork Tue May 12 00:03:09 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laurent Pinchart X-Patchwork-Id: 3765 Return-Path: Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 337D760E17 for ; Tue, 12 May 2020 02:03:38 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="Ovsoo5wx"; 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 A6B3533E; Tue, 12 May 2020 02:03:37 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1589241817; bh=UIRyqIApbSZYzAzjBh2jBmdAR79VG0JLcD9zJTA12z8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Ovsoo5wxVgpm36Yrt/cfjeAxUteCXkS+LjoDrU0LIBj06IVaey48VpqDH+5rnZ6fF YY0+2IMq4IxzxtcgDyr0wqTHPx8lqmrbaKiDBrfcY10W4EBBTGU5DLV4aDjW1XOTH0 zWxXDg8JtyKaTG9yPsdjUvdY7lGbn5osuWEUFoVM= From: Laurent Pinchart To: libcamera-devel@lists.libcamera.org Date: Tue, 12 May 2020 03:03:09 +0300 Message-Id: <20200512000322.11753-12-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 11/24] utils: raspberrypi: ctt: Fix pycodestyle E303 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 E303 too many blank lines Signed-off-by: Laurent Pinchart --- utils/raspberrypi/ctt/ctt.py | 2 -- utils/raspberrypi/ctt/ctt_alsc.py | 1 - utils/raspberrypi/ctt/ctt_macbeth_locator.py | 3 --- utils/raspberrypi/ctt/ctt_noise.py | 1 - 4 files changed, 7 deletions(-) diff --git a/utils/raspberrypi/ctt/ctt.py b/utils/raspberrypi/ctt/ctt.py index 07230fe3f709..ff264176f040 100755 --- a/utils/raspberrypi/ctt/ctt.py +++ b/utils/raspberrypi/ctt/ctt.py @@ -193,7 +193,6 @@ class Camera: } } - """ Perform colour correction calibrations by comparing macbeth patch colours to standard macbeth chart colours. @@ -770,7 +769,6 @@ def run_ctt(json_output, directory, config, log_output): except FileNotFoundError: raise ArgError('\n\nError: Input image directory not found!') - """ preform calibrations as long as check_imgs returns True If alsc is activated then it must be done before awb and ccm since the alsc diff --git a/utils/raspberrypi/ctt/ctt_alsc.py b/utils/raspberrypi/ctt/ctt_alsc.py index e768f8d648a1..b697ed3e22b4 100644 --- a/utils/raspberrypi/ctt/ctt_alsc.py +++ b/utils/raspberrypi/ctt/ctt_alsc.py @@ -253,7 +253,6 @@ def get_sigma(Cam, cal_cr_list, cal_cb_list): sigma_b = max(sigma_bs) if sigma_bs else 0.005 Cam.log += '\nMaximum sigmas: Red = {} Blue = {}'.format(sigma_r, sigma_b) - # print(sigma_rs, sigma_bs) # print(sigma_r, sigma_b) return sigma_r, sigma_b diff --git a/utils/raspberrypi/ctt/ctt_macbeth_locator.py b/utils/raspberrypi/ctt/ctt_macbeth_locator.py index c3016f9a3c1d..94bbf580db84 100644 --- a/utils/raspberrypi/ctt/ctt_macbeth_locator.py +++ b/utils/raspberrypi/ctt/ctt_macbeth_locator.py @@ -144,7 +144,6 @@ def find_macbeth(Cam, img, mac_config=(0, 0)): w_best, h_best = w_inc, h_inc d_best = 1 - """ scale 2 """ @@ -697,7 +696,6 @@ def get_macbeth_chart(img, ref_data): Following code is mostly representation for debugging purposes """ - """ draw macbeth corners and centres on image """ @@ -731,7 +729,6 @@ def get_macbeth_chart(img, ref_data): # cv2.imshow('Macbeth', best_map_col) # represent(copy) - """ rescale coordinates to original image size """ diff --git a/utils/raspberrypi/ctt/ctt_noise.py b/utils/raspberrypi/ctt/ctt_noise.py index 2d021e550f85..ba57f1d1d2c5 100644 --- a/utils/raspberrypi/ctt/ctt_noise.py +++ b/utils/raspberrypi/ctt/ctt_noise.py @@ -39,7 +39,6 @@ def noise(Cam, Img, plot): means = np.clip(np.array(means), 0, None) sq_means = np.sqrt(means) - """ least squares fit model """ From patchwork Tue May 12 00:03:10 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laurent Pinchart X-Patchwork-Id: 3766 Return-Path: Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id B8F5E60DF6 for ; Tue, 12 May 2020 02:03:38 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="HrBn+EW4"; 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 2437D11F6; Tue, 12 May 2020 02:03:38 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1589241818; bh=FVM5Xhm/g4mBc9IPDickCIF/QzcEKxHtEs15XIGBGeQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=HrBn+EW4OAhqIbZACNsRaLbMDhwpfPPJLtkc53lVNn+wRX/HKiKirQ6agwVdOh6ON Q1UfRL3tlH/LriAi9Mqnjgju5jxcMTtz2bVIHc36Hol126pAj9LGdtuO3pTvh5oeFv /gb3I06s93/1KUQlpZbOdlhPo1B5apeQ95QJ1pxo= From: Laurent Pinchart To: libcamera-devel@lists.libcamera.org Date: Tue, 12 May 2020 03:03:10 +0300 Message-Id: <20200512000322.11753-13-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 12/24] utils: raspberrypi: ctt: Fix pycodestyle E261 and E262 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 E261 at least two spaces before inline comment E262 inline comment should start with '# ' Signed-off-by: Laurent Pinchart --- utils/raspberrypi/ctt/ctt_image_load.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/utils/raspberrypi/ctt/ctt_image_load.py b/utils/raspberrypi/ctt/ctt_image_load.py index 584e0f8ebaa5..38026c7a93c0 100644 --- a/utils/raspberrypi/ctt/ctt_image_load.py +++ b/utils/raspberrypi/ctt/ctt_image_load.py @@ -45,11 +45,11 @@ class Image: Channel order depending on bayer pattern """ bayer_case = { - 0: (0, 1, 2, 3), #red - 1: (2, 0, 3, 1), #green next to red - 2: (3, 2, 1, 0), #green next to blue - 3: (1, 0, 3, 2), #blue - 128: (0, 1, 2, 3) #arbitrary order for greyscale casw + 0: (0, 1, 2, 3), # red + 1: (2, 0, 3, 1), # green next to red + 2: (3, 2, 1, 0), # green next to blue + 3: (1, 0, 3, 2), # blue + 128: (0, 1, 2, 3) # arbitrary order for greyscale casw } self.order = bayer_case[self.pattern] From patchwork Tue May 12 00:03:11 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laurent Pinchart X-Patchwork-Id: 3767 Return-Path: Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 7307A60E17 for ; Tue, 12 May 2020 02:03:39 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="BscImK5E"; 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 AF85411F3; Tue, 12 May 2020 02:03:38 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1589241819; bh=iNMim9myxijZHhPjk+y9eE1edXo8CgJW7XlQwPZjajw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=BscImK5EZRhhc4voM5SCwyJ4Pdd/cAUrTIItTu42sMO90BZihhnLH2VMv+G5dhnsm V6+d9gtNlrDAiEaxved30VxOJ/bz1ps9EdCMMRbx2/B8jNFZY7Z7HafMOJaVqf/vSU 60diJ7HIVFx1AoI/CNLXJjJdneszFFmxlnPc+akw= From: Laurent Pinchart To: libcamera-devel@lists.libcamera.org Date: Tue, 12 May 2020 03:03:11 +0300 Message-Id: <20200512000322.11753-14-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 13/24] utils: raspberrypi: ctt: Fix pycodestyle W605 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:40 -0000 W605 invalid escape sequence '\.' Signed-off-by: Laurent Pinchart --- utils/raspberrypi/ctt/ctt.py | 4 ++-- utils/raspberrypi/ctt/ctt_awb.py | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/utils/raspberrypi/ctt/ctt.py b/utils/raspberrypi/ctt/ctt.py index ff264176f040..4d8d6addf415 100755 --- a/utils/raspberrypi/ctt/ctt.py +++ b/utils/raspberrypi/ctt/ctt.py @@ -41,8 +41,8 @@ def get_col_lux(string): """ Extract colour and lux values from filename """ - col = re.search('([0-9]+)[kK](\.(jpg|jpeg|brcm|dng)|_.*\.(jpg|jpeg|brcm|dng))$', string) - lux = re.search('([0-9]+)[lL](\.(jpg|jpeg|brcm|dng)|_.*\.(jpg|jpeg|brcm|dng))$', string) + col = re.search('([0-9]+)[kK](\\.(jpg|jpeg|brcm|dng)|_.*\\.(jpg|jpeg|brcm|dng))$', string) + lux = re.search('([0-9]+)[lL](\\.(jpg|jpeg|brcm|dng)|_.*\\.(jpg|jpeg|brcm|dng))$', string) try: col = col.group(1) except AttributeError: diff --git a/utils/raspberrypi/ctt/ctt_awb.py b/utils/raspberrypi/ctt/ctt_awb.py index 58ef8432fb86..e97d833d0e49 100644 --- a/utils/raspberrypi/ctt/ctt_awb.py +++ b/utils/raspberrypi/ctt/ctt_awb.py @@ -256,8 +256,8 @@ def awb(Cam, cal_cr_list, cal_cb_list, plot): plt.scatter(rbs_hat[0], rbs_hat[1], color='red') for i, ct in enumerate(rbs_hat[2]): plt.annotate(str(ct), (rbs_hat[0][i], rbs_hat[1][i])) - plt.xlabel('$\hat{r}$') - plt.ylabel('$\hat{b}$') + plt.xlabel('$\\hat{r}$') + plt.ylabel('$\\hat{b}$') """ optional set axes equal to shortest distance so line really does looks perpendicular and everybody is happy From patchwork Tue May 12 00:03:12 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laurent Pinchart X-Patchwork-Id: 3768 Return-Path: Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 8935360DF6 for ; Tue, 12 May 2020 02:03:40 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="Epmg2UCB"; 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 6C2DE33E; Tue, 12 May 2020 02:03:39 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1589241820; bh=FT3wRnF1P/D/yfxOKeNGRBK6YckDeXAEagCXEYy1ss0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Epmg2UCBIuRAaD3Uqh0QJDAQy49v0LUF1lnxp50uj2AinXkGDR51ZkgUR3MTw8jRx /8k0SCVIj/w9GC9LXDJmZ/j2+xhjYXmnt8+W4y/FpLRpCPpMCdVViMjY7koldlA1/h fmdd1VFTCI3PaLtY8qLHDyXsa7NVQ9/I7MXxQT8Y= From: Laurent Pinchart To: libcamera-devel@lists.libcamera.org Date: Tue, 12 May 2020 03:03:12 +0300 Message-Id: <20200512000322.11753-15-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 14/24] utils: raspberrypi: ctt: Fix pycodestyle E222 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:40 -0000 E222 multiple spaces after operator Signed-off-by: Laurent Pinchart --- utils/raspberrypi/ctt/ctt.py | 2 +- utils/raspberrypi/ctt/ctt_awb.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/utils/raspberrypi/ctt/ctt.py b/utils/raspberrypi/ctt/ctt.py index 4d8d6addf415..f4cf37a03611 100755 --- a/utils/raspberrypi/ctt/ctt.py +++ b/utils/raspberrypi/ctt/ctt.py @@ -739,7 +739,7 @@ def run_ctt(json_output, directory, config, log_output): do_alsc_colour = get_config(alsc_d, "do_alsc_colour", 1, 'bool') luminance_strength = get_config(alsc_d, "luminance_strength", 0.5, 'num') blacklevel = get_config(configs, "blacklevel", -1, 'num') - macbeth_d = get_config(configs, "macbeth", {}, 'dict') + macbeth_d = get_config(configs, "macbeth", {}, 'dict') mac_small = get_config(macbeth_d, "small", 0, 'bool') mac_show = get_config(macbeth_d, "show", 0, 'bool') mac_config = (mac_small, mac_show) diff --git a/utils/raspberrypi/ctt/ctt_awb.py b/utils/raspberrypi/ctt/ctt_awb.py index e97d833d0e49..9b30115f53f4 100644 --- a/utils/raspberrypi/ctt/ctt_awb.py +++ b/utils/raspberrypi/ctt/ctt_awb.py @@ -330,7 +330,7 @@ def get_alsc_patches(Img, colour_cals, grey=True): """ this works because -0 = 0 = first and -1 = last index """ - col_tabs = np.array(colour_cals[cts[-pos//len(cts)]]) + col_tabs = np.array(colour_cals[cts[-pos//len(cts)]]) """ else, perform linear interpolation between existing alsc colour calibration tables From patchwork Tue May 12 00:03:13 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laurent Pinchart X-Patchwork-Id: 3769 Return-Path: Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id C53F060DFF for ; Tue, 12 May 2020 02:03:41 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="DwfIzeZ9"; 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 8FC1911F3; Tue, 12 May 2020 02:03:40 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1589241821; bh=F/fY9K9F6nwFGE9kNSsCFFWxjlgTAsj6Aqo1FYCQKc4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=DwfIzeZ9Y0H+AbmK9YxSx9tN8z9GOr6h+I9X12panLVcbmcIezY/rUP12gwCpfzlp jV5eN4og3UnC/vUzeQQwAEguycGbZwqWzTzq6BIFImOS7AAavOwv6YNeUw/WrUYp3O yJDKOqxwPcjf6To4Jft9CV1uJPjaB7i7TZstk2DM= From: Laurent Pinchart To: libcamera-devel@lists.libcamera.org Date: Tue, 12 May 2020 03:03:13 +0300 Message-Id: <20200512000322.11753-16-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 15/24] utils: raspberrypi: ctt: Fix pycodestyle E711 and E712 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:42 -0000 E711 comparison to None should be 'if cond is None:' E711 comparison to None should be 'if cond is not None:' E712 comparison to False should be 'if cond is False:' or 'if not cond:' E712 comparison to True should be 'if cond is True:' or 'if cond:' Signed-off-by: Laurent Pinchart --- utils/raspberrypi/ctt/ctt.py | 18 +++++++++--------- utils/raspberrypi/ctt/ctt_awb.py | 4 ++-- utils/raspberrypi/ctt/ctt_ccm.py | 2 +- utils/raspberrypi/ctt/ctt_image_load.py | 4 ++-- utils/raspberrypi/ctt/ctt_macbeth_locator.py | 2 +- utils/raspberrypi/ctt/ctt_tools.py | 4 ++-- 6 files changed, 17 insertions(+), 17 deletions(-) diff --git a/utils/raspberrypi/ctt/ctt.py b/utils/raspberrypi/ctt/ctt.py index f4cf37a03611..6a17e7898730 100755 --- a/utils/raspberrypi/ctt/ctt.py +++ b/utils/raspberrypi/ctt/ctt.py @@ -534,17 +534,17 @@ class Camera: self.log_new_sec('User Arguments', cal=False) self.log += '\nJson file output: ' + json_output self.log += '\nCalibration images directory: ' + directory - if config == None: + if config is None: self.log += '\nNo configuration file input... using default options' - elif config == False: + elif config is False: self.log += '\nWARNING: Invalid configuration file path...' self.log += ' using default options' - elif config == True: + elif config is True: self.log += '\nWARNING: Invalid syntax in configuration file...' self.log += ' using default options' else: self.log += '\nConfiguration file: ' + config - if log_output == None: + if log_output is None: self.log += '\nNo log file path input... using default: ctt_log.txt' else: self.log += '\nLog file output: ' + log_output @@ -555,7 +555,7 @@ class Camera: write log file """ def write_log(self, filename): - if filename == None: + if filename is None: filename = 'ctt_log.txt' self.log += '\n' + self.log_separator with open(filename, 'w') as logfile: @@ -604,7 +604,7 @@ class Camera: """ check that image colour temperature has been successfuly obtained """ - elif col != None: + elif col is not None: """ if successful, append to list and continue to next image """ @@ -627,7 +627,7 @@ class Camera: if image isn't an alsc correction then it must have a lux and a colour temperature value to be useful """ - if lux == None: + if lux is None: print('DISCARDED') self.log += '\nWARNING: Error reading lux value' self.log += '\nImage discarded!' @@ -707,7 +707,7 @@ def run_ctt(json_output, directory, config, log_output): """ if json_output[-5:] != '.json': raise ArgError('\n\nError: Output must be a json file!') - if config != None: + if config is not None: """ check if config file is actually a json """ @@ -790,7 +790,7 @@ def run_ctt(json_output, directory, config, log_output): Cam.write_json() Cam.write_log(log_output) print('\nCalibrations written to: '+json_output) - if log_output == None: + if log_output is None: log_output = 'ctt_log.txt' print('Log file written to: '+log_output) pass diff --git a/utils/raspberrypi/ctt/ctt_awb.py b/utils/raspberrypi/ctt/ctt_awb.py index 9b30115f53f4..c269b67a12c0 100644 --- a/utils/raspberrypi/ctt/ctt_awb.py +++ b/utils/raspberrypi/ctt/ctt_awb.py @@ -17,7 +17,7 @@ def awb(Cam, cal_cr_list, cal_cb_list, plot): """ condense alsc calibration tables into one dictionary """ - if cal_cr_list == None: + if cal_cr_list is None: colour_cals = None else: colour_cals = {} @@ -315,7 +315,7 @@ def get_alsc_patches(Img, colour_cals, grey=True): b_patchs = patches[3] - Img.blacklevel_16 g_patchs = (patches[1]+patches[2])/2 - Img.blacklevel_16 - if colour_cals == None: + if colour_cals is None: return r_patchs, b_patchs, g_patchs """ find where image colour fits in alsc colour calibration tables diff --git a/utils/raspberrypi/ctt/ctt_ccm.py b/utils/raspberrypi/ctt/ctt_ccm.py index adc4d290ae7e..21be4d6fb1b1 100644 --- a/utils/raspberrypi/ctt/ctt_ccm.py +++ b/utils/raspberrypi/ctt/ctt_ccm.py @@ -64,7 +64,7 @@ def ccm(Cam, cal_cr_list, cal_cb_list): reformat alsc correction tables or set colour_cals to None if alsc is deactivated """ - if cal_cr_list == None: + if cal_cr_list is None: colour_cals = None else: colour_cals = {} diff --git a/utils/raspberrypi/ctt/ctt_image_load.py b/utils/raspberrypi/ctt/ctt_image_load.py index 38026c7a93c0..787307508ba5 100644 --- a/utils/raspberrypi/ctt/ctt_image_load.py +++ b/utils/raspberrypi/ctt/ctt_image_load.py @@ -232,7 +232,7 @@ def brcm_load_image(Cam, im_str): """ return error if problem reading file """ - if f == None: + if f is None: print('\nERROR:\nProblem reading file') Cam.log += '\nWARNING: Problem readin file' return 0 @@ -376,7 +376,7 @@ def load_image(Cam, im_str, mac_config=None, show=False, mac=True, show_meta=Fal """ if no macbeth found return error """ - if macbeth == None: + if macbeth is None: print('\nERROR: No macbeth chart found') return 0 mac_cen_coords = macbeth[1] diff --git a/utils/raspberrypi/ctt/ctt_macbeth_locator.py b/utils/raspberrypi/ctt/ctt_macbeth_locator.py index 94bbf580db84..05d1bd437001 100644 --- a/utils/raspberrypi/ctt/ctt_macbeth_locator.py +++ b/utils/raspberrypi/ctt/ctt_macbeth_locator.py @@ -258,7 +258,7 @@ def find_macbeth(Cam, img, mac_config=(0, 0)): """ extract data from coords_fit and plot on original image """ - if show and coords_fit != None: + if show and coords_fit is not None: copy = img.copy() verts = coords_fit[0][0] cents = coords_fit[1][0] diff --git a/utils/raspberrypi/ctt/ctt_tools.py b/utils/raspberrypi/ctt/ctt_tools.py index e5871b60d6a2..27080de08cec 100644 --- a/utils/raspberrypi/ctt/ctt_tools.py +++ b/utils/raspberrypi/ctt/ctt_tools.py @@ -62,9 +62,9 @@ def parse_input(): directory = get_config(args_dict, '-i', None, 'string') config = get_config(args_dict, '-c', None, 'string') log_path = get_config(args_dict, '-l', None, 'string') - if directory == None: + if directory is None: raise ArgError('\n\nERROR! No input directory given.') - if json_output == None: + if json_output is None: raise ArgError('\n\nERROR! No output json given.') return json_output, directory, config, log_path """ From patchwork Tue May 12 00:03:14 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laurent Pinchart X-Patchwork-Id: 3770 Return-Path: Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 2272760E18 for ; Tue, 12 May 2020 02:03:43 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="qURBMGEI"; 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 D7E32120C; Tue, 12 May 2020 02:03:41 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1589241822; bh=FNJG7m0U5/m8bg0Nw05fEmF9VdytDtpZS+X84tJ1zRI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=qURBMGEI6vmqOPmoQzeA4l/A4Lsb4/Z9yDcnjkqtfrXdpVzyG0rYStcy/lXwI73fo n6F1oJOhsmvpz83S4sKwHhdJstON/kn/BkV2dAHZ3BfRKAk5ro3RMwgsN/9fq1zeSK 46pSm/AUCprHEYFQKYkMqjfvUgdyM9JXSFplk/bc= From: Laurent Pinchart To: libcamera-devel@lists.libcamera.org Date: Tue, 12 May 2020 03:03:14 +0300 Message-Id: <20200512000322.11753-17-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 16/24] utils: raspberrypi: ctt: Fix pycodestyle E123 and E126 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:43 -0000 E123 closing bracket does not match indentation of opening bracket's line E126 continuation line over-indented for hanging indent Signed-off-by: Laurent Pinchart --- utils/raspberrypi/ctt/ctt.py | 2 +- utils/raspberrypi/ctt/ctt_ccm.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/utils/raspberrypi/ctt/ctt.py b/utils/raspberrypi/ctt/ctt.py index 6a17e7898730..3ebd10711d94 100755 --- a/utils/raspberrypi/ctt/ctt.py +++ b/utils/raspberrypi/ctt/ctt.py @@ -87,7 +87,7 @@ class Camera: "reference_shutter_speed": 10000, "reference_gain": 1, "reference_aperture": 1.0 - }, + }, "rpi.noise": { }, "rpi.geq": { diff --git a/utils/raspberrypi/ctt/ctt_ccm.py b/utils/raspberrypi/ctt/ctt_ccm.py index 21be4d6fb1b1..0a4eb57a8cdf 100644 --- a/utils/raspberrypi/ctt/ctt_ccm.py +++ b/utils/raspberrypi/ctt/ctt_ccm.py @@ -49,7 +49,7 @@ def ccm(Cam, cal_cr_list, cal_cb_list): [121, 121, 122], # neutral 5 [82, 84, 86], # neutral 3.5 [49, 49, 51] # black 2 - ]) + ]) """ convert reference colours from srgb to rgb From patchwork Tue May 12 00:03:15 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laurent Pinchart X-Patchwork-Id: 3771 Return-Path: Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 8DDC160E0D for ; Tue, 12 May 2020 02:03:44 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="j216xfzm"; 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 4AFAF11F3; Tue, 12 May 2020 02:03:43 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1589241824; bh=9b1kxGqyxYCby1+ouLFTZ+KDUTJkCzHi1pQKQamBn10=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=j216xfzmcSYbha11ayvyajvLjM8GAuwn5uA3etE9QKjL/4UVUrS6QhHAxOnxsgJOE eaqibOQa6q8dzBaYs55KiWeKAb8Ae1RkeHUeRaLq8uirFDvYABH+x/h93mdwfjH5KH ebvLHK7HHS5S/zODJCQM4bFG9JQ7nbe+AOxefiS0= From: Laurent Pinchart To: libcamera-devel@lists.libcamera.org Date: Tue, 12 May 2020 03:03:15 +0300 Message-Id: <20200512000322.11753-18-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 17/24] utils: raspberrypi: ctt: Fix pycodestyle E116 and E117 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:45 -0000 E116 unexpected indentation (comment) E117 over-indented (comment) Signed-off-by: Laurent Pinchart --- utils/raspberrypi/ctt/ctt_macbeth_locator.py | 26 ++++++++++---------- utils/raspberrypi/ctt/ctt_tools.py | 8 +++--- 2 files changed, 17 insertions(+), 17 deletions(-) diff --git a/utils/raspberrypi/ctt/ctt_macbeth_locator.py b/utils/raspberrypi/ctt/ctt_macbeth_locator.py index 05d1bd437001..4e666b0f1089 100644 --- a/utils/raspberrypi/ctt/ctt_macbeth_locator.py +++ b/utils/raspberrypi/ctt/ctt_macbeth_locator.py @@ -450,14 +450,14 @@ def get_macbeth_chart(img, ref_data): """ in_border = True # for p in mac_guess[0]: - # pptest = cv2.pointPolygonTest( - # img_con, - # tuple(p), - # False - # ) - # if pptest == -1: - # in_border = False - # break + # pptest = cv2.pointPolygonTest( + # img_con, + # tuple(p), + # False + # ) + # if pptest == -1: + # in_border = False + # break if in_border: mac_mid = np.mean(mac_guess, @@ -499,9 +499,9 @@ def get_macbeth_chart(img, ref_data): else: clustering.fit(mac_mids_list) # try: - # clustering.fit(mac_mids_list) + # clustering.fit(mac_mids_list) # except RuntimeWarning as error: - # return(0, None, None, error) + # return(0, None, None, error) """ create list of all clusters @@ -549,9 +549,9 @@ def get_macbeth_chart(img, ref_data): # copy = cv2.cvtColor(copy, cv2.COLOR_GRAY2RGB) # copy = cv2.resize(copy, None, fx=2, fy=2) # for clus in clus_list: - # centroid = tuple(2*np.round(clus[2]).astype(np.int32)) - # cv2.circle(copy, centroid, 7, (255, 0, 0), -1) - # cv2.circle(copy, centroid, 2, (0, 0, 255), -1) + # centroid = tuple(2*np.round(clus[2]).astype(np.int32)) + # cv2.circle(copy, centroid, 7, (255, 0, 0), -1) + # cv2.circle(copy, centroid, 2, (0, 0, 255), -1) # represent(copy) """ diff --git a/utils/raspberrypi/ctt/ctt_tools.py b/utils/raspberrypi/ctt/ctt_tools.py index 27080de08cec..f4b9baac5521 100644 --- a/utils/raspberrypi/ctt/ctt_tools.py +++ b/utils/raspberrypi/ctt/ctt_tools.py @@ -99,11 +99,11 @@ display image for debugging... read at your own risk... """ def represent(img, name='image'): # if type(img) == tuple or type(img) == list: - # for i in range(len(img)): - # name = 'image {}'.format(i) - # cv2.imshow(name, img[i]) + # for i in range(len(img)): + # name = 'image {}'.format(i) + # cv2.imshow(name, img[i]) # else: - # cv2.imshow(name, img) + # cv2.imshow(name, img) # cv2.waitKey(0) # cv2.destroyAllWindows() # return 0 From patchwork Tue May 12 00:03:16 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laurent Pinchart X-Patchwork-Id: 3772 Return-Path: Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 8813060DF9 for ; Tue, 12 May 2020 02:03:45 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="gsIQvt8X"; 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 B8C3211F6; Tue, 12 May 2020 02:03:44 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1589241825; bh=4IZZdoN0Og6HNynzINvU4JR3yEDmfU1J2rOMd6jYbuY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=gsIQvt8XFlEgafrPnbjFAnEVuB3NipFAF7YXDRdHz3HHpSV3RcxL7ZlWFyYNG9IB5 unhRMKFlgCABYhK+3pcNntd0LqodiGODbmD+cPNO/S29saKn1GFZpE1SrFaxOMpMAR ZCxcgnI+B7vBWYpDRRCXdlP9bJEyORcsaGVo4+T8= From: Laurent Pinchart To: libcamera-devel@lists.libcamera.org Date: Tue, 12 May 2020 03:03:16 +0300 Message-Id: <20200512000322.11753-19-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 18/24] utils: raspberrypi: ctt: Fix pycodestyle E713 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:45 -0000 E713 test for membership should be 'not in' Signed-off-by: Laurent Pinchart --- utils/raspberrypi/ctt/ctt.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/utils/raspberrypi/ctt/ctt.py b/utils/raspberrypi/ctt/ctt.py index 3ebd10711d94..6caa5a552230 100755 --- a/utils/raspberrypi/ctt/ctt.py +++ b/utils/raspberrypi/ctt/ctt.py @@ -216,7 +216,7 @@ class Camera: Check if alsc tables have been generated, if not then do ccm without alsc """ - if (not "rpi.alsc" in self.disable) and do_alsc_colour: + if ("rpi.alsc" not in self.disable) and do_alsc_colour: """ case where ALSC colour has been done, so no errors should be expected... @@ -285,7 +285,7 @@ class Camera: Check if alsc tables have been generated, if not then do awb without alsc correction """ - if (not "rpi.alsc" in self.disable) and do_alsc_colour: + if ("rpi.alsc" not in self.disable) and do_alsc_colour: try: cal_cr_list = self.json['rpi.alsc']['calibrations_Cr'] cal_cb_list = self.json['rpi.alsc']['calibrations_Cb'] From patchwork Tue May 12 00:03:17 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laurent Pinchart X-Patchwork-Id: 3773 Return-Path: Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 7459D60DF9 for ; Tue, 12 May 2020 02:03:46 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="pNAU1OaQ"; 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 7510A120C; Tue, 12 May 2020 02:03:45 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1589241825; bh=MxoezXKaj0RqpeUNTZK99ziqfV4jkAWx+EoWQz+B/dk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=pNAU1OaQHdW7Ja2TwXAUo9bfvIvIqLlyCCucRtIkRkcxwXun7Q+jIrooHWCO+l4sK 28RbDSu6x0Puo1wjaQbIQaDdnmIPGA8eFr8tXeTYNJ9X+1tqtNBgAvfhZVLrQA+MLl ysWXfdn5ADkb4OOHFcE2qOxc5xeVZlvvvNfBnevU= From: Laurent Pinchart To: libcamera-devel@lists.libcamera.org Date: Tue, 12 May 2020 03:03:17 +0300 Message-Id: <20200512000322.11753-20-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 19/24] utils: raspberrypi: ctt: Fix pycodestyle E721 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:46 -0000 E721 do not compare types, use 'isinstance()' Signed-off-by: Laurent Pinchart --- utils/raspberrypi/ctt/ctt_tools.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/utils/raspberrypi/ctt/ctt_tools.py b/utils/raspberrypi/ctt/ctt_tools.py index f4b9baac5521..3a2fb4af95c5 100644 --- a/utils/raspberrypi/ctt/ctt_tools.py +++ b/utils/raspberrypi/ctt/ctt_tools.py @@ -36,10 +36,10 @@ def get_config(dictt, key, default, ttype): if 'float' not in str(type(val)): raise ValueError elif ttype == 'dict': - if type(val) != type(dictt): + if not isinstance(val, dict): raise ValueError elif ttype == 'list': - if type(val) != type([]): + if not isinstance(val, list): raise ValueError elif ttype == 'bool': ttype = int(bool(ttype)) From patchwork Tue May 12 00:03:18 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laurent Pinchart X-Patchwork-Id: 3774 Return-Path: Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id D596560E15 for ; Tue, 12 May 2020 02:03:46 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="cFHFHeF8"; 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 5FF6533E; Tue, 12 May 2020 02:03:46 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1589241826; bh=RdKMXsoLJMcRm00J7FudYwK1oT0RjHwUVLVsWcySA00=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=cFHFHeF88FOE2qtgfF+rxPRFSqEIX4vGdpLwIu+CPZVhTuHxbdH9kyZnMXy0k1v6m z5uZhSED0fZkN0lHn4P+x5fpPwTDqWQWuf6h8bJzSM10CC3pg0o9pJ/xbNa+X6tkBo MF8WTtgCmZ7RNhC39mN1vVO5qIxjFUXpELaTXork= From: Laurent Pinchart To: libcamera-devel@lists.libcamera.org Date: Tue, 12 May 2020 03:03:18 +0300 Message-Id: <20200512000322.11753-21-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 20/24] utils: raspberrypi: ctt: Fix pycodestyle E722 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:47 -0000 E722 do not use bare 'except' Signed-off-by: Laurent Pinchart --- utils/raspberrypi/ctt/ctt_image_load.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/utils/raspberrypi/ctt/ctt_image_load.py b/utils/raspberrypi/ctt/ctt_image_load.py index 787307508ba5..e373c7c0d2a0 100644 --- a/utils/raspberrypi/ctt/ctt_image_load.py +++ b/utils/raspberrypi/ctt/ctt_image_load.py @@ -331,7 +331,7 @@ def dng_load_image(Cam, im_str): c3 = np.left_shift(raw_data[1::2, 1::2].astype(np.int64), shift) Img.channels = [c0, c1, c2, c3] - except: + except Exception: print("\nERROR: failed to load DNG file", im_str) print("Either file does not exist or is incompatible") Cam.log += '\nERROR: DNG file does not exist or is incompatible' From patchwork Tue May 12 00:03:19 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laurent Pinchart X-Patchwork-Id: 3775 Return-Path: Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 6212060E08 for ; Tue, 12 May 2020 02:03:47 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="fQKEbbeA"; 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 CBCEA11F3; Tue, 12 May 2020 02:03:46 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1589241827; bh=TqSnq8Y4XimnQqy91muRszj434SxwT5vc5VdA/qpBsM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=fQKEbbeAGMFDUZcFSPyhK/HOkiqaPOKebkM/3qgopxkDsVIl02D8dFiddeKQ+RTRD Dr9w0QClBC71LTzaYy2c6hKlL/s1CliOkBujmCM1QGZy4Dsl2b/Fxpz6GTPqOL3IbR E8InW79SoMdcMpgDcR0oUfpOgHnsd8MhhKCsVI6I= From: Laurent Pinchart To: libcamera-devel@lists.libcamera.org Date: Tue, 12 May 2020 03:03:19 +0300 Message-Id: <20200512000322.11753-22-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 21/24] utils: raspberrypi: ctt: Fix pycodestyle W504 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:48 -0000 W504 line break after binary operator Signed-off-by: Laurent Pinchart --- utils/raspberrypi/ctt/ctt.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/utils/raspberrypi/ctt/ctt.py b/utils/raspberrypi/ctt/ctt.py index 6caa5a552230..cb01a517e8bc 100755 --- a/utils/raspberrypi/ctt/ctt.py +++ b/utils/raspberrypi/ctt/ctt.py @@ -380,7 +380,7 @@ class Camera: if len(self.imgs_alsc) == 1: self.json['rpi.alsc']['sigma'] = 0.005 self.json['rpi.alsc']['sigma_Cb'] = 0.005 - print('\nWarning:\nOnly one alsc calibration found' + + print('\nWarning:\nOnly one alsc calibration found' '\nStandard sigmas used for adaptive algorithm.') print('Finished ALSC calibrations') self.log += '\nWARNING: Only one colour temperature found in ' From patchwork Tue May 12 00:03:20 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laurent Pinchart X-Patchwork-Id: 3776 Return-Path: Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id E09B360E38 for ; Tue, 12 May 2020 02:03:47 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="YjYdc/qa"; 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 5D8FD33E; Tue, 12 May 2020 02:03:47 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1589241827; bh=rgsOsGt+tVmmcbA4kGLjwqlo/Ju4yD6IKzXoFCF0zfs=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=YjYdc/qaYtQiksGStpBCKNXYipOriSZNyH9Nkb5r/bzGey1tb0lEFkgyuqBuEwSLF sUp9LMPI/BZSPhKvZQEdp/hT+dOAzaDqGMZD7qki6HvPlK7oNfDgCYNYSGYlnAHjde gLJBwHgKa9Th2ZY4oBHZ4iQiBr9hlGLTI1ArxvyU= From: Laurent Pinchart To: libcamera-devel@lists.libcamera.org Date: Tue, 12 May 2020 03:03:20 +0300 Message-Id: <20200512000322.11753-23-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 22/24] utils: raspberrypi: ctt: Fix pycodestyle E741 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:48 -0000 E741 ambiguous variable name 'l' Signed-off-by: Laurent Pinchart --- utils/raspberrypi/ctt/ctt.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/utils/raspberrypi/ctt/ctt.py b/utils/raspberrypi/ctt/ctt.py index cb01a517e8bc..8f8e06f069df 100755 --- a/utils/raspberrypi/ctt/ctt.py +++ b/utils/raspberrypi/ctt/ctt.py @@ -478,8 +478,8 @@ class Camera: """ take the average of the interquartile """ - l = len(noise_out) - noise_out = np.mean(noise_out[l//4:1+3*l//4], axis=0) + length = len(noise_out) + noise_out = np.mean(noise_out[length//4:1+3*length//4], axis=0) self.log += '\nAverage noise profile: constant = {} '.format(int(noise_out[1])) self.log += 'slope = {:.3f}'.format(noise_out[0]) """ From patchwork Tue May 12 00:03:21 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laurent Pinchart X-Patchwork-Id: 3777 Return-Path: Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 53DF760E1E for ; Tue, 12 May 2020 02:03:48 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="k2TisRIn"; 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 C984911F3; Tue, 12 May 2020 02:03:47 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1589241828; bh=qYgSzfYk8qfXQvj7AQz1975n95mssuUQXjDhA6CrPfo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=k2TisRInK4BWCAKGwnA9TuKnSCiTTOVPcYTPR7kItEg71CeVk8CdPvXtTtpYBUZOq 8ciH6ah9s7C5FG9UG9OUbqQt2GloZqdZsBes4ZMQ9DqFHEPxa6sv+nISF80l/ruaej PypO/pcBx/p0jY3Vo1YU/KYnDozotrtTB2TMH3j0= From: Laurent Pinchart To: libcamera-devel@lists.libcamera.org Date: Tue, 12 May 2020 03:03:21 +0300 Message-Id: <20200512000322.11753-24-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 23/24] utils: raspberrypi: ctt: Fix pycodestyle E305 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:49 -0000 E305 expected 2 blank lines after class or function definition Signed-off-by: Laurent Pinchart --- utils/raspberrypi/ctt/ctt.py | 2 ++ utils/raspberrypi/ctt/ctt_alsc.py | 2 ++ utils/raspberrypi/ctt/ctt_awb.py | 1 + utils/raspberrypi/ctt/ctt_ccm.py | 2 ++ utils/raspberrypi/ctt/ctt_geq.py | 1 + utils/raspberrypi/ctt/ctt_image_load.py | 1 + utils/raspberrypi/ctt/ctt_lux.py | 1 + utils/raspberrypi/ctt/ctt_macbeth_locator.py | 1 + utils/raspberrypi/ctt/ctt_tools.py | 7 +++++++ 9 files changed, 18 insertions(+) diff --git a/utils/raspberrypi/ctt/ctt.py b/utils/raspberrypi/ctt/ctt.py index 8f8e06f069df..02f1d8531269 100755 --- a/utils/raspberrypi/ctt/ctt.py +++ b/utils/raspberrypi/ctt/ctt.py @@ -60,6 +60,7 @@ def get_col_lux(string): return col, None return int(col), int(lux) + """ Camera object that is the backbone of the tuning tool. Input is the desired path of the output json. @@ -797,6 +798,7 @@ def run_ctt(json_output, directory, config, log_output): else: Cam.write_log(log_output) + if __name__ == '__main__': """ initialise calibration diff --git a/utils/raspberrypi/ctt/ctt_alsc.py b/utils/raspberrypi/ctt/ctt_alsc.py index b697ed3e22b4..b988f565f245 100644 --- a/utils/raspberrypi/ctt/ctt_alsc.py +++ b/utils/raspberrypi/ctt/ctt_alsc.py @@ -218,6 +218,7 @@ def get_16x12_grid(chan, dx, dy): """ return np.array(grid) + """ obtains sigmas for red and blue, effectively a measure of the 'error' """ @@ -257,6 +258,7 @@ def get_sigma(Cam, cal_cr_list, cal_cb_list): # print(sigma_r, sigma_b) return sigma_r, sigma_b + """ calculate sigma from two adjacent gain tables """ diff --git a/utils/raspberrypi/ctt/ctt_awb.py b/utils/raspberrypi/ctt/ctt_awb.py index c269b67a12c0..834d4dec2742 100644 --- a/utils/raspberrypi/ctt/ctt_awb.py +++ b/utils/raspberrypi/ctt/ctt_awb.py @@ -288,6 +288,7 @@ def awb(Cam, cal_cr_list, cal_cb_list, plot): """ return(ct_curve, np.round(transverse_pos, 5), np.round(transverse_neg, 5)) + """ obtain greyscale patches and perform alsc colour correction """ diff --git a/utils/raspberrypi/ctt/ctt_ccm.py b/utils/raspberrypi/ctt/ctt_ccm.py index 0a4eb57a8cdf..dd660e40bb66 100644 --- a/utils/raspberrypi/ctt/ctt_ccm.py +++ b/utils/raspberrypi/ctt/ctt_ccm.py @@ -16,6 +16,7 @@ def degamma(x): x = x * ((2**16)-1) return x + """ FInds colour correction matrices for list of images """ @@ -153,6 +154,7 @@ def ccm(Cam, cal_cr_list, cal_cb_list): }) return ccms + """ calculates the ccm for an individual image. ccms are calculate in rgb space, and are fit by hand. Although it is a 3x3 diff --git a/utils/raspberrypi/ctt/ctt_geq.py b/utils/raspberrypi/ctt/ctt_geq.py index 1ffa4e91b1b7..d24b216389df 100644 --- a/utils/raspberrypi/ctt/ctt_geq.py +++ b/utils/raspberrypi/ctt/ctt_geq.py @@ -165,6 +165,7 @@ def geq_fit(Cam, plot): return round(slope, 5), int(offset) + """" Return green channels of macbeth patches returns g0, g1 where diff --git a/utils/raspberrypi/ctt/ctt_image_load.py b/utils/raspberrypi/ctt/ctt_image_load.py index e373c7c0d2a0..240d68f984a2 100644 --- a/utils/raspberrypi/ctt/ctt_image_load.py +++ b/utils/raspberrypi/ctt/ctt_image_load.py @@ -418,6 +418,7 @@ def load_image(Cam, im_str, mac_config=None, show=False, mac=True, show_meta=Fal # print('\nERROR:\nInvalid file extension') return 0 + """ bytearray splice to number little endian """ diff --git a/utils/raspberrypi/ctt/ctt_lux.py b/utils/raspberrypi/ctt/ctt_lux.py index 55b2aa299ed3..ab367cae37d7 100644 --- a/utils/raspberrypi/ctt/ctt_lux.py +++ b/utils/raspberrypi/ctt/ctt_lux.py @@ -19,6 +19,7 @@ def lux(Cam, Img): channels = [Img.channels[i] for i in Img.order] return lux_calc(Cam, Img, patches, channels), shutter_speed, gain + """ perform lux calibration on bayer channels """ diff --git a/utils/raspberrypi/ctt/ctt_macbeth_locator.py b/utils/raspberrypi/ctt/ctt_macbeth_locator.py index 4e666b0f1089..6567490c5539 100644 --- a/utils/raspberrypi/ctt/ctt_macbeth_locator.py +++ b/utils/raspberrypi/ctt/ctt_macbeth_locator.py @@ -21,6 +21,7 @@ output to the console def fxn(): warnings.warn("runtime", RuntimeWarning) + """ Define the success message """ diff --git a/utils/raspberrypi/ctt/ctt_tools.py b/utils/raspberrypi/ctt/ctt_tools.py index 3a2fb4af95c5..d5d64d47d25b 100644 --- a/utils/raspberrypi/ctt/ctt_tools.py +++ b/utils/raspberrypi/ctt/ctt_tools.py @@ -48,6 +48,8 @@ def get_config(dictt, key, default, ttype): except (KeyError, ValueError): val = default return val + + """ argument parser """ @@ -67,6 +69,8 @@ def parse_input(): if json_output is None: raise ArgError('\n\nERROR! No output json given.') return json_output, directory, config, log_path + + """ custom arg and macbeth error class """ @@ -75,6 +79,7 @@ class ArgError(Exception): class MacbethError(Exception): pass + """ correlation function to quantify match """ @@ -84,6 +89,7 @@ def correlate(im1, im2): cor = np.corrcoef(f1, f2) return cor[0][1] + """ get list of files from directory """ @@ -94,6 +100,7 @@ def get_photos(directory='photos'): filename_list.append(filename) return filename_list + """ display image for debugging... read at your own risk... """ From patchwork Tue May 12 00:03:22 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laurent Pinchart X-Patchwork-Id: 3778 Return-Path: Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id BAE2060E1F for ; Tue, 12 May 2020 02:03:48 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="no+m6j8/"; 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 429CC33E; Tue, 12 May 2020 02:03:48 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1589241828; bh=fKAq1+3vTnfpj7NUbvogQ3/xjDGKdWwswTm/IuswWZY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=no+m6j8/ulreQLtE7XY9syuk5VqZO3NduuUW7JM6lfzlAoSFUqXH/SRAeTDKHk3cL iSpS0uPHhuwb2H38udECRE8HasoRnM2ry40m+iBRCdgDlNtLldQRCaMPejkYdwiko1 jQVYBnsG//idMM8a0XMJFpX0v/dYyIly+ZPryhU0= From: Laurent Pinchart To: libcamera-devel@lists.libcamera.org Date: Tue, 12 May 2020 03:03:22 +0300 Message-Id: <20200512000322.11753-25-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 24/24] utils: raspberrypi: ctt: Fix pycodestyle E302 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:49 -0000 E302 expected 2 blank lines, found 0 Note that issues are still flagged, due to the use of docstrings as multi-lines comments. This will be addressed separately. Signed-off-by: Laurent Pinchart --- utils/raspberrypi/ctt/ctt.py | 2 ++ utils/raspberrypi/ctt/ctt_alsc.py | 1 + utils/raspberrypi/ctt/ctt_awb.py | 1 + utils/raspberrypi/ctt/ctt_ccm.py | 1 + utils/raspberrypi/ctt/ctt_geq.py | 1 + utils/raspberrypi/ctt/ctt_image_load.py | 2 ++ utils/raspberrypi/ctt/ctt_lux.py | 2 ++ utils/raspberrypi/ctt/ctt_macbeth_locator.py | 2 ++ utils/raspberrypi/ctt/ctt_noise.py | 1 + utils/raspberrypi/ctt/ctt_pretty_print_json.py | 4 ++++ utils/raspberrypi/ctt/ctt_ransac.py | 2 ++ utils/raspberrypi/ctt/ctt_tools.py | 1 + 12 files changed, 20 insertions(+) diff --git a/utils/raspberrypi/ctt/ctt.py b/utils/raspberrypi/ctt/ctt.py index 02f1d8531269..81c724aeb2e0 100755 --- a/utils/raspberrypi/ctt/ctt.py +++ b/utils/raspberrypi/ctt/ctt.py @@ -34,6 +34,7 @@ blank json file. This has been done to avoid reproducing the entire json file in the code here, thereby avoiding unecessary clutter. """ + """ Get the colour and lux values from the strings of each inidvidual image """ @@ -702,6 +703,7 @@ class Camera: self.log += '\nERROR: Images are from different cameras' return 0 + def run_ctt(json_output, directory, config, log_output): """ check input files are jsons diff --git a/utils/raspberrypi/ctt/ctt_alsc.py b/utils/raspberrypi/ctt/ctt_alsc.py index b988f565f245..89e86469a78e 100644 --- a/utils/raspberrypi/ctt/ctt_alsc.py +++ b/utils/raspberrypi/ctt/ctt_alsc.py @@ -9,6 +9,7 @@ import matplotlib.pyplot as plt from matplotlib import cm from mpl_toolkits.mplot3d import Axes3D + """ preform alsc calibration on a set of images """ diff --git a/utils/raspberrypi/ctt/ctt_awb.py b/utils/raspberrypi/ctt/ctt_awb.py index 834d4dec2742..3c8cd9027a1a 100644 --- a/utils/raspberrypi/ctt/ctt_awb.py +++ b/utils/raspberrypi/ctt/ctt_awb.py @@ -9,6 +9,7 @@ import matplotlib.pyplot as plt from bisect import bisect_left from scipy.optimize import fmin + """ obtain piecewise linear approximation for colour curve """ diff --git a/utils/raspberrypi/ctt/ctt_ccm.py b/utils/raspberrypi/ctt/ctt_ccm.py index dd660e40bb66..cebecfc248a6 100644 --- a/utils/raspberrypi/ctt/ctt_ccm.py +++ b/utils/raspberrypi/ctt/ctt_ccm.py @@ -7,6 +7,7 @@ from ctt_image_load import * from ctt_awb import get_alsc_patches + """ takes 8-bit macbeth chart values, degammas and returns 16 bit """ diff --git a/utils/raspberrypi/ctt/ctt_geq.py b/utils/raspberrypi/ctt/ctt_geq.py index d24b216389df..2aa668f133a8 100644 --- a/utils/raspberrypi/ctt/ctt_geq.py +++ b/utils/raspberrypi/ctt/ctt_geq.py @@ -8,6 +8,7 @@ from ctt_tools import * import matplotlib.pyplot as plt import scipy.optimize as optimize + """ Uses green differences in macbeth patches to fit green equalisation threshold model. Ideally, all macbeth chart centres would fall below the threshold as diff --git a/utils/raspberrypi/ctt/ctt_image_load.py b/utils/raspberrypi/ctt/ctt_image_load.py index 240d68f984a2..66adb23733d7 100644 --- a/utils/raspberrypi/ctt/ctt_image_load.py +++ b/utils/raspberrypi/ctt/ctt_image_load.py @@ -210,6 +210,7 @@ class Image: self.patches = all_patches return 1 + def brcm_load_image(Cam, im_str): """ Load image where raw data and metadata is in the BRCM format @@ -290,6 +291,7 @@ def brcm_load_image(Cam, im_str): return Img + def dng_load_image(Cam, im_str): try: Img = Image(None) diff --git a/utils/raspberrypi/ctt/ctt_lux.py b/utils/raspberrypi/ctt/ctt_lux.py index ab367cae37d7..4e7785ef35e1 100644 --- a/utils/raspberrypi/ctt/ctt_lux.py +++ b/utils/raspberrypi/ctt/ctt_lux.py @@ -5,6 +5,8 @@ # ctt_lux.py - camera tuning tool for lux level from ctt_tools import * + + """ Find lux values from metadata and calculate Y """ diff --git a/utils/raspberrypi/ctt/ctt_macbeth_locator.py b/utils/raspberrypi/ctt/ctt_macbeth_locator.py index 6567490c5539..35c848072a08 100644 --- a/utils/raspberrypi/ctt/ctt_macbeth_locator.py +++ b/utils/raspberrypi/ctt/ctt_macbeth_locator.py @@ -13,6 +13,7 @@ NOTE: some custom functions have been used here to make the code more readable. These are defined in tools.py if they are needed for reference. """ + """ Some inconsistencies between packages cause runtime warnings when running the clustering algorithm. This catches these warnings so they don't flood the @@ -291,6 +292,7 @@ def find_macbeth(Cam, img, mac_config=(0, 0)): return(coords_fit) + def get_macbeth_chart(img, ref_data): """ function returns coordinates of macbeth chart vertices and square centres, diff --git a/utils/raspberrypi/ctt/ctt_noise.py b/utils/raspberrypi/ctt/ctt_noise.py index ba57f1d1d2c5..0afcf8f850cc 100644 --- a/utils/raspberrypi/ctt/ctt_noise.py +++ b/utils/raspberrypi/ctt/ctt_noise.py @@ -7,6 +7,7 @@ from ctt_image_load import * import matplotlib.pyplot as plt + """ Find noise standard deviation and fit to model: diff --git a/utils/raspberrypi/ctt/ctt_pretty_print_json.py b/utils/raspberrypi/ctt/ctt_pretty_print_json.py index fac9e98ba9dd..73383ea09665 100644 --- a/utils/raspberrypi/ctt/ctt_pretty_print_json.py +++ b/utils/raspberrypi/ctt/ctt_pretty_print_json.py @@ -4,6 +4,7 @@ # # ctt_pretty_print_json.py - camera tuning tool JSON formatter + """ takes a collapsed json file and makes it more readable """ @@ -11,10 +12,12 @@ def process_file(string, fout, state): for c in string: process_char(c, fout, state) + def print_newline(fout, state): fout.write('\n') fout.write(' '*state["indent"]*4) + def process_char(c, fout, state): if c == '{': if not state["skipnewline"]: @@ -61,6 +64,7 @@ def process_char(c, fout, state): fout.write(c) state["skipnewline"] = (c == '[') + def pretty_print_json(str_in, output_filename): state = {"indent": 0, "inarray": [False], "arraycount": [], "skipnewline": True} with open(output_filename, "w") as fout: diff --git a/utils/raspberrypi/ctt/ctt_ransac.py b/utils/raspberrypi/ctt/ctt_ransac.py index 392275445c14..11515a4fab08 100644 --- a/utils/raspberrypi/ctt/ctt_ransac.py +++ b/utils/raspberrypi/ctt/ctt_ransac.py @@ -8,6 +8,7 @@ import numpy as np scale = 2 + """ constructs normalised macbeth chart corners for ransac algorithm """ @@ -57,6 +58,7 @@ def get_square_verts(c_err=0.05, scale=scale): # print(square_verts) return np.array(square_verts, np.float32), mac_norm + def get_square_centres(c_err=0.05, scale=scale): """ define macbeth square centres diff --git a/utils/raspberrypi/ctt/ctt_tools.py b/utils/raspberrypi/ctt/ctt_tools.py index d5d64d47d25b..48e0aac26a1f 100644 --- a/utils/raspberrypi/ctt/ctt_tools.py +++ b/utils/raspberrypi/ctt/ctt_tools.py @@ -22,6 +22,7 @@ understanding of the code. They ar collated here to attempt to improve code readability in the main files. """ + """ obtain config values, unless it doesnt exist, in which case pick default Furthermore, it can check if the input is the correct type