Skip to content

Commit

Permalink
Clean up remote script.
Browse files Browse the repository at this point in the history
  • Loading branch information
ebezzam committed Sep 29, 2023
1 parent ddafc09 commit d80ad91
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 41 deletions.
3 changes: 2 additions & 1 deletion configs/demo.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion scripts/measure/on_device_capture.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -248,7 +249,7 @@ def capture(config):

else:

# returning non-bayer data
# capturing and returning non-bayer data
from picamerax import PiCamera

camera = PiCamera()
Expand Down
90 changes: 51 additions & 39 deletions scripts/measure/remote_capture.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit d80ad91

Please sign in to comment.