Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/raw_output' into sqm
Browse files Browse the repository at this point in the history
  • Loading branch information
mrosseel committed Oct 24, 2024
2 parents 76b26a6 + eef32af commit 439d012
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 11 deletions.
6 changes: 2 additions & 4 deletions python/PiFinder/camera_debug.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ def get_cam_type(self) -> str:
return self.camType


def get_images(shared_state, camera_image, command_queue, console_queue, log_queue):
def get_images(shared_state, camera_image, bias_image, command_queue, console_queue, log_queue):
"""
Instantiates the camera hardware
then calls the universal image loop
Expand All @@ -83,6 +83,4 @@ def get_images(shared_state, camera_image, command_queue, console_queue, log_que
cfg = config.Config()
exposure_time = cfg.get_option("camera_exp")
camera_hardware = CameraDebug(exposure_time)
camera_hardware.get_image_loop(
shared_state, camera_image, command_queue, console_queue, cfg
)
camera_hardware.get_image_loop(shared_state, camera_image, bias_image, command_queue, console_queue, cfg)
13 changes: 10 additions & 3 deletions python/PiFinder/camera_interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
from typing import Tuple
import logging
from PiFinder import utils
import numpy as np

logger = logging.getLogger("Camera.Interface")

Expand Down Expand Up @@ -79,21 +80,26 @@ def get_image_loop(
imu_start = shared_state.imu()
image_start_time = time.time()
if not debug:
base_image = self.capture()
base_image, raw_image = self.capture()
base_image = base_image.convert("L")
bias_image = self.capture_bias()
base_image = bias_image.convert("L")
rotate_amount = 0
if camera_rotation is None:
if (
screen_direction == "right"
or screen_direction == "straight"
or screen_direction == "flat3"
):
base_image = base_image.rotate(90)
rotate_amount = 90
else:
base_image = base_image.rotate(270)
rotate_amount = 270
else:
# TODO: support arbitrary numpy rotations?
base_image = base_image.rotate(int(camera_rotation) * -1)

base_image = base_image.rotate(rotate_amount)
raw_image = np.rot90(raw_image, rotate_amount / 90)
else:
# load image and wait
base_image = Image.open(test_image_path)
Expand All @@ -113,6 +119,7 @@ def get_image_loop(

camera_image.paste(base_image)
bias_image.paste(bias_image)
shared_state.set_cam_raw(raw_image)
shared_state.set_last_image_metadata(
{
"exposure_start": image_start_time,
Expand Down
26 changes: 22 additions & 4 deletions python/PiFinder/camera_pi.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
from typing import Tuple
import logging
from PiFinder.multiproclogging import MultiprocLogging
import numpy as np

logger = logging.getLogger("Camera.Pi")

Expand Down Expand Up @@ -48,11 +49,14 @@ def initialize(self) -> None:
{
"size": (512, 512),
},
raw={"size": (1456, 1088)},
raw={"size": (1456, 1088), "format": "R8"},
)
else:
# using this smaller scale auto-selects binning on the sensor...
cam_config = self.camera.create_still_configuration({"size": (512, 512)})
# cam_config = self.camera.create_still_configuration({"size": (512, 512)})
cam_config = self.camera.create_still_configuration(
{"size": (512, 512)}, raw={"size": (2028, 1520), "format": "SRGGB10"}
)
self.camera.configure(cam_config)
self._default_controls()
self.camera.start()
Expand All @@ -63,11 +67,25 @@ def _default_controls(self) -> None:
self.camera.set_controls({"ExposureTime": self.exposure_time})

def capture(self) -> Image.Image:
tmp_capture = self.camera.capture_image()
_request = self.camera.capture_request()
tmp_capture = _request.make_image("main")
raw_capture = _request.make_array("raw")
_request.release()
if self.camera_type == "imx296":
# Sensor orientation is different
raw_capture = raw_capture.copy().view(np.uint16)[:,184:-184]
raw_capture = raw_capture.astype(np.float32)
raw_capture = (raw_capture / 1024 * 255).astype(np.uint8)
tmp_capture = tmp_capture.rotate(180)
return tmp_capture
raw_capture = np.rot90(raw_capture, 2)
else:
# For OG camera type, the array needs to be converted
# from RGB to L. Easiest way to do this is just to
# add the flux from all the channels
raw_capture = np.sum(raw_capture, axis=[0, 1])
raw_image = Image.fromarray(raw_capture).resize((512, 512))
# return tmp_capture, raw_image
return raw_image

def capture_bias(self) -> Image.Image:
"""Capture a bias frame for dark subtraction"""
Expand Down
7 changes: 7 additions & 0 deletions python/PiFinder/state.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@ def __init__(self):
self.__solve_pixel = config.Config().get_option("solve_pixel")
self.__arch = None
self.__camera_align = False
self.__cam_raw = None

def serialize(self, output_file):
with open(output_file, "wb") as f:
Expand Down Expand Up @@ -265,6 +266,12 @@ def screen(self):
def set_screen(self, v):
self.__screen = v

def cam_raw(self):
return self.__cam_raw

def set_cam_raw(self, v):
self.__cam_raw = v

def ui_state(self):
return self.__ui_state

Expand Down

0 comments on commit 439d012

Please sign in to comment.