From d80ad918334b359ac63caed295525be16990bb70 Mon Sep 17 00:00:00 2001 From: Eric Bezzam Date: Fri, 29 Sep 2023 18:40:00 +0200 Subject: [PATCH] Clean up remote script. --- configs/demo.yaml | 3 +- scripts/measure/on_device_capture.py | 3 +- scripts/measure/remote_capture.py | 90 ++++++++++++++++------------ 3 files changed, 55 insertions(+), 41 deletions(-) diff --git a/configs/demo.yaml b/configs/demo.yaml index d3a6bc27..47f13ba4 100644 --- a/configs/demo.yaml +++ b/configs/demo.yaml @@ -42,7 +42,8 @@ capture: nbits_out: 8 # light data transer, doesn't seem to worsen performance nbits: 12 legacy: True - gray: False + gray: False # only for legacy=True, if bayer=True, remote script returns grayscale data + # rgb: False # only for legacy=True, if bayer=True, remote script return RGB data raw_data_fn: raw_data bayer: True source: white diff --git a/scripts/measure/on_device_capture.py b/scripts/measure/on_device_capture.py index e176c313..f0aae9b5 100644 --- a/scripts/measure/on_device_capture.py +++ b/scripts/measure/on_device_capture.py @@ -210,6 +210,7 @@ def capture(config): else: output = (np.sum(stream.array, axis=2) >> 2).astype(np.uint8) + # returning non-bayer data if rgb or gray: if sixteen: n_bits = 12 # assuming Raspberry Pi HQ @@ -248,7 +249,7 @@ def capture(config): else: - # returning non-bayer data + # capturing and returning non-bayer data from picamerax import PiCamera camera = PiCamera() diff --git a/scripts/measure/remote_capture.py b/scripts/measure/remote_capture.py index e2532c74..411a0f4c 100644 --- a/scripts/measure/remote_capture.py +++ b/scripts/measure/remote_capture.py @@ -119,48 +119,60 @@ def liveview(config): "RPi distribution" in result_dict.keys() and "bullseye" in result_dict["RPi distribution"] and not legacy - and bayer ): - # copy over DNG file - remotefile = f"~/{remote_fn}.dng" - localfile = f"{fn}.dng" - print(f"\nCopying over picture as {localfile}...") - os.system('scp "%s@%s:%s" %s' % (username, hostname, remotefile, localfile)) - raw = rawpy.imread(localfile) - - # https://letmaik.github.io/rawpy/api/rawpy.Params.html#rawpy.Params - # https://www.libraw.org/docs/API-datastruct-eng.html - if nbits_out > 8: - # only 8 or 16 bit supported by postprocess - if nbits_out != 16: - print("casting to 16 bit...") - output_bps = 16 + + if bayer: + + # copy over DNG file + remotefile = f"~/{remote_fn}.dng" + localfile = f"{fn}.dng" + print(f"\nCopying over picture as {localfile}...") + os.system('scp "%s@%s:%s" %s' % (username, hostname, remotefile, localfile)) + raw = rawpy.imread(localfile) + + # https://letmaik.github.io/rawpy/api/rawpy.Params.html#rawpy.Params + # https://www.libraw.org/docs/API-datastruct-eng.html + if nbits_out > 8: + # only 8 or 16 bit supported by postprocess + if nbits_out != 16: + print("casting to 16 bit...") + output_bps = 16 + else: + if nbits_out != 8: + print("casting to 8 bit...") + output_bps = 8 + img = raw.postprocess( + adjust_maximum_thr=0, # default 0.75 + no_auto_scale=False, + gamma=(1, 1), + output_bps=output_bps, + bright=1, # default 1 + exp_shift=1, + no_auto_bright=True, + use_camera_wb=True, + use_auto_wb=False, # default is False? f both use_camera_wb and use_auto_wb are True, then use_auto_wb has priority. + ) + + # print image properties + print_image_info(img) + + # save as PNG + png_out = f"{fn}.png" + print(f"Saving RGB file as: {png_out}") + cv2.imwrite(png_out, cv2.cvtColor(img, cv2.COLOR_RGB2BGR)) + else: - if nbits_out != 8: - print("casting to 8 bit...") - output_bps = 8 - img = raw.postprocess( - adjust_maximum_thr=0, # default 0.75 - no_auto_scale=False, - gamma=(1, 1), - output_bps=output_bps, - bright=1, # default 1 - exp_shift=1, - no_auto_bright=True, - use_camera_wb=True, - use_auto_wb=False, # default is False? f both use_camera_wb and use_auto_wb are True, then use_auto_wb has priority. - ) - - # print image properties - print_image_info(img) - - # save as PNG - png_out = f"{fn}.png" - print(f"Saving RGB file as: {png_out}") - cv2.imwrite(png_out, cv2.cvtColor(img, cv2.COLOR_RGB2BGR)) - if not bayer: - os.remove(localfile) + remotefile = f"~/{remote_fn}.png" + localfile = f"{fn}.png" + if save: + localfile = os.path.join(save, localfile) + print(f"\nCopying over picture as {localfile}...") + os.system('scp "%s@%s:%s" %s' % (username, hostname, remotefile, localfile)) + + img = load_image(localfile, verbose=True) + + # legacy software running on RPi else: # copy over file # more pythonic? https://stackoverflow.com/questions/250283/how-to-scp-in-python