Skip to content

Commit

Permalink
Merge pull request Cephla-Lab#53 from veerwang/master
Browse files Browse the repository at this point in the history
issue modify, when autoLevels turnoff, open live would cause displaying abnormal
  • Loading branch information
hongquanli authored Jun 6, 2024
2 parents ddb5bc1 + 5379009 commit b6f0f85
Show file tree
Hide file tree
Showing 8 changed files with 96 additions and 13 deletions.
4 changes: 4 additions & 0 deletions software/configurations/configuration_HCS_v2.ini
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,10 @@ _inverted_objective_options=[True,False]

illumination_intensity_factor = 0.6

awb_ratios_r = 1.375
awb_ratios_g = 1
awb_ratios_b = 1.4141

[LIMIT_SWITCH_POLARITY]
x_home = 1
y_home = 1
Expand Down
4 changes: 4 additions & 0 deletions software/control/_def.py
Original file line number Diff line number Diff line change
Expand Up @@ -570,6 +570,10 @@ class SOFTWARE_POS_LIMIT:
MULTIPOINT_PIEZO_DELAY_MS = 20
MULTIPOINT_PIEZO_UPDATE_DISPLAY = True

AWB_RATIOS_R = 1.375
AWB_RATIOS_G = 1
AWB_RATIOS_B = 1.4141

try:
with open("cache/config_file_path.txt", 'r') as file:
for line in file:
Expand Down
27 changes: 25 additions & 2 deletions software/control/camera.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ def open(self,index=0):
print(self.get_awb_ratios())
# self.set_wb_ratios(1.28125,1.0,2.9453125)
# self.set_wb_ratios(2,1,2)
self.set_wb_ratios(1.375,1,1.4141)
self.set_wb_ratios(AWB_RATIOS_R, AWB_RATIOS_G, AWB_RATIOS_B)

# temporary
self.camera.AcquisitionFrameRate.set(1000)
Expand Down Expand Up @@ -220,6 +220,20 @@ def set_wb_ratios(self, wb_r=None, wb_g=None, wb_b=None):
self.camera.BalanceRatioSelector.set(2)
awb_b = self.camera.BalanceRatio.set(wb_b)

def set_balance_white_auto(self, value):
if value in [0, 1, 2]:
if self.camera.BalanceWhiteAuto.is_implemented():
if self.camera.BalanceWhiteAuto.is_writable():
self.camera.BalanceWhiteAuto.set(value)

def get_balance_white_auto(self):
if self.camera.BalanceWhiteAuto.is_implemented():
if self.camera.BalanceWhiteAuto.is_readable():
return self.camera.BalanceWhiteAuto.get()

def get_is_color(self):
return self.is_color

def set_reverse_x(self,value):
self.camera.ReverseX.set(value)

Expand Down Expand Up @@ -506,6 +520,15 @@ def get_awb_ratios(self):
def set_wb_ratios(self, wb_r=None, wb_g=None, wb_b=None):
pass

def set_balance_white_auto(self, value):
pass

def get_balance_white_auto(self):
return 0

def get_is_color(self):
return False

def start_streaming(self):
self.frame_ID_software = 0

Expand Down Expand Up @@ -563,4 +586,4 @@ def set_line3_to_strobe(self):
pass

def set_line3_to_exposure_active(self):
pass
pass
2 changes: 1 addition & 1 deletion software/control/camera_toupcam.py
Original file line number Diff line number Diff line change
Expand Up @@ -455,7 +455,7 @@ def set_resolution(self,width,height):

def _update_buffer_settings(self):
# resize the buffer
width, height = self.camera.get_Size()
xoffset, yoffset, width, height = self.camera.get_Roi()

self.Width = width
self.Height = height
Expand Down
22 changes: 20 additions & 2 deletions software/control/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -1317,6 +1317,8 @@ def run_autofocus(self):
if focus_measure < focus_measure_max*AF.STOP_THRESHOLD:
break

QApplication.processEvents()

# move to the starting location
# self.navigationController.move_z_usteps(-steps_moved*self.deltaZ_usteps) # combine with the back and forth maneuver below
# self.wait_till_operation_is_completed()
Expand All @@ -1336,6 +1338,8 @@ def run_autofocus(self):
self.navigationController.move_z_usteps((idx_in_focus+1)*self.deltaZ_usteps-steps_moved*self.deltaZ_usteps)
self.wait_till_operation_is_completed()

QApplication.processEvents()

# move to the calculated in-focus position
# self.navigationController.move_z_usteps(idx_in_focus*self.deltaZ_usteps)
# self.wait_till_operation_is_completed() # combine with the movement above
Expand Down Expand Up @@ -3000,6 +3004,9 @@ def __init__(self, window_title='', draw_crosshairs = False, show_LUT=False, aut
self.DrawCrossHairs = False
self.image_offset = np.array([0, 0])

## flag of setting scaling level
self.flag_image_scaling_level_init = False

## Layout
layout = QGridLayout()
if self.show_LUT:
Expand Down Expand Up @@ -3045,16 +3052,27 @@ def mouse_clicked(self, evt):
self.image_click_coordinates.emit(x_pixel_centered, y_pixel_centered, self.graphics_widget.img.width(), self.graphics_widget.img.height())

def display_image(self,image):
def set_autoLevels_value():
if self.autoLevels is True:
self.graphics_widget.img.setImage(image,autoLevels=self.autoLevels)
else:
if self.flag_image_scaling_level_init is False:
self.graphics_widget.img.setImage(image, autoLevels = True)
self.flag_image_scaling_level_init = True
else:
self.graphics_widget.img.setImage(image,autoLevels=self.autoLevels)

if ENABLE_TRACKING:
image = np.copy(image)
self.image_height = image.shape[0],
self.image_width = image.shape[1]
if(self.draw_rectangle):
cv2.rectangle(image, self.ptRect1, self.ptRect2,(255,255,255) , 4)
self.draw_rectangle = False
self.graphics_widget.img.setImage(image,autoLevels=self.autoLevels)

set_autoLevels_value()
else:
self.graphics_widget.img.setImage(image,autoLevels=self.autoLevels)
set_autoLevels_value()

def update_ROI(self):
self.roi_pos = self.ROI.pos()
Expand Down
8 changes: 4 additions & 4 deletions software/control/gui_hcs.py
Original file line number Diff line number Diff line change
Expand Up @@ -280,9 +280,9 @@ def __init__(self, is_simulation = False, *args, **kwargs):
self.nl5Wdiget = NL5Widget.NL5Widget(self.nl5)

if CAMERA_TYPE == "Toupcam":
self.cameraSettingWidget = widgets.CameraSettingsWidget(self.camera, include_gain_exposure_time=False, include_camera_temperature_setting = True)
self.cameraSettingWidget = widgets.CameraSettingsWidget(self.camera, include_gain_exposure_time=False, include_camera_temperature_setting = True, include_camera_auto_wb_setting = False)
else:
self.cameraSettingWidget = widgets.CameraSettingsWidget(self.camera, include_gain_exposure_time=False, include_camera_temperature_setting = False)
self.cameraSettingWidget = widgets.CameraSettingsWidget(self.camera, include_gain_exposure_time=False, include_camera_temperature_setting = False, include_camera_auto_wb_setting = True)
self.liveControlWidget = widgets.LiveControlWidget(self.streamHandler,self.liveController,self.configurationManager,show_display_options=True,show_autolevel=True,autolevel=True)
self.navigationWidget = widgets.NavigationWidget(self.navigationController,self.slidePositionController,widget_configuration='384 well plate')
self.dacControlWidget = widgets.DACControWidget(self.microcontroller)
Expand Down Expand Up @@ -459,9 +459,9 @@ def __init__(self, is_simulation = False, *args, **kwargs):

# widgets
if FOCUS_CAMERA_TYPE == "Toupcam":
self.cameraSettingWidget_focus_camera = widgets.CameraSettingsWidget(self.camera_focus, include_gain_exposure_time = False, include_camera_temperature_setting = True)
self.cameraSettingWidget_focus_camera = widgets.CameraSettingsWidget(self.camera_focus, include_gain_exposure_time = False, include_camera_temperature_setting = True, include_camera_auto_wb_setting = False)
else:
self.cameraSettingWidget_focus_camera = widgets.CameraSettingsWidget(self.camera_focus, include_gain_exposure_time = False, include_camera_temperature_setting = False)
self.cameraSettingWidget_focus_camera = widgets.CameraSettingsWidget(self.camera_focus, include_gain_exposure_time = False, include_camera_temperature_setting = False, include_camera_auto_wb_setting = True)

self.liveControlWidget_focus_camera = widgets.LiveControlWidget(self.streamHandler_focus_camera,self.liveController_focus_camera,self.configurationManager_focus_camera,show_display_options=True)
self.waveformDisplay = widgets.WaveformDisplay(N=1000,include_x=True,include_y=False)
Expand Down
2 changes: 1 addition & 1 deletion software/control/gui_malaria.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ def __init__(self, is_simulation = False, *args, **kwargs):

# set piezo arguments
if ENABLE_OBJECTIVE_PIEZO is True:
if PIEZO_CONTROL_VOLTAGE_RANGE == 5:
if OBJECTIVE_PIEZO_CONTROL_VOLTAGE_RANGE == 5:
OUTPUT_GAINS.CHANNEL7_GAIN = True
else:
OUTPUT_GAINS.CHANNEL7_GAIN = False
Expand Down
40 changes: 37 additions & 3 deletions software/control/widgets.py
Original file line number Diff line number Diff line change
Expand Up @@ -558,15 +558,15 @@ def add_to_focusmap(self):

class CameraSettingsWidget(QFrame):

def __init__(self, camera, include_gain_exposure_time = False, include_camera_temperature_setting = False, main=None, *args, **kwargs):
def __init__(self, camera, include_gain_exposure_time = False, include_camera_temperature_setting = False, include_camera_auto_wb_setting = False, main=None, *args, **kwargs):

super().__init__(*args, **kwargs)
self.camera = camera
self.add_components(include_gain_exposure_time,include_camera_temperature_setting)
self.add_components(include_gain_exposure_time,include_camera_temperature_setting,include_camera_auto_wb_setting)
# set frame style
self.setFrameStyle(QFrame.Panel | QFrame.Raised)

def add_components(self,include_gain_exposure_time,include_camera_temperature_setting):
def add_components(self,include_gain_exposure_time,include_camera_temperature_setting,include_camera_auto_wb_setting):

# add buttons and input fields
self.entry_exposureTime = QDoubleSpinBox()
Expand Down Expand Up @@ -684,12 +684,46 @@ def add_components(self,include_gain_exposure_time,include_camera_temperature_se
hbox1.addWidget(QLabel('offset x'))
hbox1.addWidget(self.entry_ROI_offset_x)

if include_camera_auto_wb_setting:
is_color = False
try:
is_color = self.camera.get_is_color()
except AttributeError:
pass

if is_color is True:
grid_camera_setting_wb = QGridLayout()

# auto white balance
self.btn_auto_wb = QPushButton('Auto White Balance')
self.btn_auto_wb.setCheckable(True)
self.btn_auto_wb.setChecked(False)
self.btn_auto_wb.clicked.connect(self.toggle_auto_wb)
print(self.camera.get_balance_white_auto())
grid_camera_setting_wb.addWidget(self.btn_auto_wb,0,0)

self.grid = QGridLayout()
self.grid.addLayout(grid_ctrl,0,0)
self.grid.addLayout(hbox1,1,0)
if include_camera_auto_wb_setting:
is_color = False
try:
is_color = self.camera.get_is_color()
except AttributeError:
pass
if is_color is True:
self.grid.addLayout(grid_camera_setting_wb,2,0)

self.grid.setRowStretch(self.grid.rowCount(), 1)
self.setLayout(self.grid)

def toggle_auto_wb(self,pressed):
# 0: OFF 1:CONTINUOUS 2:ONCE
if pressed:
self.camera.set_balance_white_auto(1)
else:
self.camera.set_balance_white_auto(0)

def set_exposure_time(self,exposure_time):
self.entry_exposureTime.setValue(exposure_time)

Expand Down

0 comments on commit b6f0f85

Please sign in to comment.