From 9ef0e3a2ee36a3ea4acb34c0fe918dc3533c0cd8 Mon Sep 17 00:00:00 2001 From: ChrisCoxArt Date: Tue, 11 Apr 2017 16:41:01 -0700 Subject: [PATCH] enable green and blue lasers add UI for laser color choice (default red), get the correct color channel matching that choice, default profile info --- res/locale/en/LC_MESSAGES/horus.po | 16 ++++++++++++++ .../engine/algorithms/laser_segmentation.py | 21 +++++++++++++------ src/horus/gui/workbench/adjustment/panels.py | 3 +++ src/horus/util/profile.py | 7 +++++++ 4 files changed, 41 insertions(+), 6 deletions(-) diff --git a/res/locale/en/LC_MESSAGES/horus.po b/res/locale/en/LC_MESSAGES/horus.po index 90f4dc84..030eec21 100644 --- a/res/locale/en/LC_MESSAGES/horus.po +++ b/res/locale/en/LC_MESSAGES/horus.po @@ -109,6 +109,22 @@ msgstr "Remove background" msgid "Red channel" msgstr "Red channel" +#: ../../src/horus/util/profile.py:250 ../../src/horus/util/profile.py:315 +msgid "Laser color" +msgstr "Laser color" + +#: ../../src/horus/util/profile.py:250 ../../src/horus/util/profile.py:315 +msgid "Red" +msgstr "Red" + +#: ../../src/horus/util/profile.py:250 ../../src/horus/util/profile.py:315 +msgid "Green" +msgstr "Green" + +#: ../../src/horus/util/profile.py:250 ../../src/horus/util/profile.py:315 +msgid "Blue" +msgstr "Blue" + #: ../../src/horus/util/profile.py:254 ../../src/horus/util/profile.py:319 msgid "Enable threshold" msgstr "Enable threshold" diff --git a/src/horus/engine/algorithms/laser_segmentation.py b/src/horus/engine/algorithms/laser_segmentation.py index 82bc2f8b..8ea85542 100644 --- a/src/horus/engine/algorithms/laser_segmentation.py +++ b/src/horus/engine/algorithms/laser_segmentation.py @@ -23,6 +23,7 @@ def __init__(self): self.point_cloud_roi = PointCloudROI() self.red_channel = 'R (RGB)' + self.color_channel = 'Red' self.threshold_enable = False self.threshold_value = 0 self.blur_enable = False @@ -34,6 +35,9 @@ def __init__(self): def set_red_channel(self, value): self.red_channel = value + def set_color_channel(self, value): + self.color_channel = value + def set_threshold_enable(self, value): self.threshold_enable = value @@ -86,8 +90,8 @@ def compute_line_segmentation(self, image, roi_mask=False): # Apply ROI mask if roi_mask: image = self.point_cloud_roi.mask_image(image) - # Obtain red channel - image = self._obtain_red_channel(image) + # Obtain laser channel (usually red) + image = self._obtain_laser_channel(image) if image is not None: # Threshold image image = self._threshold_image(image) @@ -95,13 +99,18 @@ def compute_line_segmentation(self, image, roi_mask=False): image = self._window_mask(image) return image - def _obtain_red_channel(self, image): + def _obtain_laser_channel(self, image): ret = None - if self.red_channel == 'R (RGB)': + # color channel takes priority over unused YCrCb and YUV tests + if self.color_channel == 'Green': + ret = cv2.split(image)[1] + elif self.color_channel == 'Blue': + ret = cv2.split(image)[2] + elif self.red_channel == 'R (RGB)': ret = cv2.split(image)[0] - elif self.red_channel == 'Cr (YCrCb)': + elif self.red_channel == 'Cr (YCrCb)': # unused, UI code commented out ret = cv2.split(cv2.cvtColor(image, cv2.COLOR_RGB2YCR_CB))[1] - elif self.red_channel == 'U (YUV)': + elif self.red_channel == 'U (YUV)': # unused, UI code commented out ret = cv2.split(cv2.cvtColor(image, cv2.COLOR_RGB2YUV))[1] return ret diff --git a/src/horus/gui/workbench/adjustment/panels.py b/src/horus/gui/workbench/adjustment/panels.py index b406b68d..1407ecbe 100644 --- a/src/horus/gui/workbench/adjustment/panels.py +++ b/src/horus/gui/workbench/adjustment/panels.py @@ -150,6 +150,7 @@ def __init__(self, parent, on_selected_callback): def add_controls(self): # self.add_control('red_channel_scanning', ComboBox) + self.add_control('color_channel_scanning', ComboBox) self.add_control( 'threshold_value_scanning', Slider, _("Remove all pixels which intensity is less that the threshold value")) @@ -172,6 +173,7 @@ def add_controls(self): def update_callbacks(self): # self.update_callback('red_channel_scanning', laser_segmentation.set_red_channel) + self.update_callback('color_channel_scanning', laser_segmentation.set_color_channel) self.update_callback('threshold_value_scanning', laser_segmentation.set_threshold_value) self.update_callback('threshold_enable_scanning', laser_segmentation.set_threshold_enable) self.update_callback('blur_value_scanning', laser_segmentation.set_blur_value) @@ -192,6 +194,7 @@ def on_selected(self): laser_mode.set_exposure(profile.settings['exposure_laser_scanning']) image_capture.set_remove_background(profile.settings['remove_background_scanning']) laser_segmentation.set_red_channel(profile.settings['red_channel_scanning']) + laser_segmentation.set_color_channel(profile.settings['color_channel_scanning']) laser_segmentation.set_threshold_value(profile.settings['threshold_value_scanning']) laser_segmentation.set_threshold_enable(profile.settings['threshold_enable_scanning']) laser_segmentation.set_blur_value(profile.settings['blur_value_scanning']) diff --git a/src/horus/util/profile.py b/src/horus/util/profile.py index 6e308f15..0a39995a 100644 --- a/src/horus/util/profile.py +++ b/src/horus/util/profile.py @@ -213,6 +213,9 @@ def _initialize_settings(self): # Hack to translate combo boxes: _('Texture') _('Laser') + _('Red') + _('Green') + _('Blue') self._add_setting( Setting('capture_mode_scanning', _('Capture mode'), 'profile_settings', unicode, u'Texture', possible_values=(u'Texture', u'Laser'))) @@ -250,6 +253,10 @@ def _initialize_settings(self): Setting('red_channel_scanning', _('Red channel'), 'profile_settings', unicode, u'R (RGB)', possible_values=(u'R (RGB)', u'Cr (YCrCb)', u'U (YUV)'))) + self._add_setting( + Setting('color_channel_scanning', _('Laser color'), 'profile_settings', + unicode, u'Red', + possible_values=(u'Red', u'Green', u'Blue'))) self._add_setting( Setting('threshold_enable_scanning', _('Enable threshold'), 'profile_settings', bool, True))