Skip to content

Commit

Permalink
Draw platform center into the video
Browse files Browse the repository at this point in the history
  • Loading branch information
Jesus89 committed May 20, 2016
1 parent a965578 commit 2455e13
Show file tree
Hide file tree
Showing 4 changed files with 75 additions and 54 deletions.
120 changes: 66 additions & 54 deletions src/horus/engine/algorithms/point_cloud_roi.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ class PointCloudROI(object):
def __init__(self):
self.calibration_data = CalibrationData()
self._use_roi = False
self._show_center = True
self._height = 0
self._radious = 0
self._initialize()
Expand Down Expand Up @@ -55,8 +56,11 @@ def set_height(self, value):
def set_use_roi(self, value):
self._use_roi = value

def set_show_center(self, value):
self._show_center = value

def mask_image(self, image):
if self._use_roi:
if self._center_v != 0 and self._center_u != 0 and self._use_roi:
if image is not None:
mask = np.zeros(image.shape, np.uint8)
mask[self._vmin:self._vmax, self._umin:self._umax] = image[
Expand All @@ -82,61 +86,69 @@ def mask_point_cloud(self, point_cloud, texture):

return point_cloud[:, idx], texture[:, idx]

def draw_roi(self, image):
thickness = 6
thickness_hiden = 1
cy = self.calibration_data.camera_matrix[1][2]

center_up_u = self._no_trimmed_umin + \
(self._no_trimmed_umax - self._no_trimmed_umin) / 2
center_up_v = self._upper_vmin + (self._upper_vmax - self._upper_vmin) / 2
center_down_u = self._no_trimmed_umin + \
(self._no_trimmed_umax - self._no_trimmed_umin) / 2
center_down_v = self._lower_vmax + (self._lower_vmin - self._lower_vmax) / 2
axes_up = ((self._no_trimmed_umax - self._no_trimmed_umin) / 2,
((self._upper_vmax - self._upper_vmin) / 2))
axes_down = ((self._no_trimmed_umax - self._no_trimmed_umin) / 2,
((self._lower_vmin - self._lower_vmax) / 2))

# upper ellipse
if (center_up_v < cy):
cv2.ellipse(image, (center_up_u, center_up_v), axes_up,
0, 180, 360, (0, 100, 200), thickness)
cv2.ellipse(image, (center_up_u, center_up_v), axes_up,
0, 0, 180, (0, 100, 200), thickness_hiden)
else:
cv2.ellipse(image, (center_up_u, center_up_v), axes_up,
0, 180, 360, (0, 100, 200), thickness)
cv2.ellipse(image, (center_up_u, center_up_v), axes_up,
0, 0, 180, (0, 100, 200), thickness)

# lower ellipse
cv2.ellipse(image, (center_down_u, center_down_v), axes_down,
0, 180, 360, (0, 100, 200), thickness_hiden)
cv2.ellipse(image, (center_down_u, center_down_v),
axes_down, 0, 0, 180, (0, 100, 200), thickness)

# cylinder lines
cv2.line(image, (self._no_trimmed_umin, center_up_v),
(self._no_trimmed_umin, center_down_v), (0, 100, 200), thickness)
cv2.line(image, (self._no_trimmed_umax, center_up_v),
(self._no_trimmed_umax, center_down_v), (0, 100, 200), thickness)

# view center
if axes_up[0] <= 0 or axes_up[1] <= 0:
axes_up_center = (20, 1)
axes_down_center = (20, 1)
else:
axes_up_center = (20, axes_up[1] * 20 / axes_up[0])
axes_down_center = (20, axes_down[1] * 20 / axes_down[0])
def draw_cross(self, image):
if self._center_v != 0 and self._center_u != 0 and self._show_center:
thickness = 3
v_max, u_max, _ = image.shape
cv2.line(image, (0, self._center_v), (u_max, self._center_v), (200, 0, 0), thickness)
cv2.line(image, (self._center_u, 0), (self._center_u, v_max), (200, 0, 0), thickness)
return image

# upper center
cv2.ellipse(image, (self._center_u, min(center_up_v, self._center_v)),
axes_up_center, 0, 0, 360, (0, 70, 120), -1)
# lower center
cv2.ellipse(image, (self._center_u, self._center_v),
axes_down_center, 0, 0, 360, (0, 70, 120), -1)
def draw_roi(self, image):
if self._center_v != 0 and self._center_u != 0:
thickness = 6
thickness_hiden = 1
cy = self.calibration_data.camera_matrix[1][2]

center_up_u = self._no_trimmed_umin + \
(self._no_trimmed_umax - self._no_trimmed_umin) / 2
center_up_v = self._upper_vmin + (self._upper_vmax - self._upper_vmin) / 2
center_down_u = self._no_trimmed_umin + \
(self._no_trimmed_umax - self._no_trimmed_umin) / 2
center_down_v = self._lower_vmax + (self._lower_vmin - self._lower_vmax) / 2
axes_up = ((self._no_trimmed_umax - self._no_trimmed_umin) / 2,
((self._upper_vmax - self._upper_vmin) / 2))
axes_down = ((self._no_trimmed_umax - self._no_trimmed_umin) / 2,
((self._lower_vmin - self._lower_vmax) / 2))

# upper ellipse
if (center_up_v < cy):
cv2.ellipse(image, (center_up_u, center_up_v), axes_up,
0, 180, 360, (0, 100, 200), thickness)
cv2.ellipse(image, (center_up_u, center_up_v), axes_up,
0, 0, 180, (0, 100, 200), thickness_hiden)
else:
cv2.ellipse(image, (center_up_u, center_up_v), axes_up,
0, 180, 360, (0, 100, 200), thickness)
cv2.ellipse(image, (center_up_u, center_up_v), axes_up,
0, 0, 180, (0, 100, 200), thickness)

# lower ellipse
cv2.ellipse(image, (center_down_u, center_down_v), axes_down,
0, 180, 360, (0, 100, 200), thickness_hiden)
cv2.ellipse(image, (center_down_u, center_down_v),
axes_down, 0, 0, 180, (0, 100, 200), thickness)

# cylinder lines
cv2.line(image, (self._no_trimmed_umin, center_up_v),
(self._no_trimmed_umin, center_down_v), (0, 100, 200), thickness)
cv2.line(image, (self._no_trimmed_umax, center_up_v),
(self._no_trimmed_umax, center_down_v), (0, 100, 200), thickness)

# view center
if axes_up[0] <= 0 or axes_up[1] <= 0:
axes_up_center = (20, 1)
axes_down_center = (20, 1)
else:
axes_up_center = (20, axes_up[1] * 20 / axes_up[0])
axes_down_center = (20, axes_down[1] * 20 / axes_down[0])

# upper center
cv2.ellipse(image, (self._center_u, min(center_up_v, self._center_v)),
axes_up_center, 0, 0, 360, (0, 70, 120), -1)
# lower center
cv2.ellipse(image, (self._center_u, self._center_v),
axes_down_center, 0, 0, 360, (0, 70, 120), -1)
return image

def _compute_roi(self):
Expand Down
2 changes: 2 additions & 0 deletions src/horus/gui/workbench/scanning/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,7 @@ def setup_engine(self):
ciclop_scan.color = struct.unpack(
'BBB', profile.settings['point_cloud_color'].decode('hex'))
ciclop_scan.set_scan_sleep(profile.settings['scan_sleep'])
point_cloud_roi.set_show_center(profile.settings['show_center'])
point_cloud_roi.set_use_roi(profile.settings['use_roi'])
point_cloud_roi.set_diameter(profile.settings['roi_diameter'])
point_cloud_roi.set_height(profile.settings['roi_height'])
Expand All @@ -154,6 +155,7 @@ def get_image(self):
else:
image_capture.stream = True
image = image_capture.capture_texture()
image = point_cloud_roi.draw_cross(image)
if self.scene_view._view_roi:
image = point_cloud_roi.mask_image(image)
image = point_cloud_roi.draw_roi(image)
Expand Down
5 changes: 5 additions & 0 deletions src/horus/gui/workbench/scanning/panels.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,16 @@ def __init__(self, parent, on_selected_callback):
self.main = self.GetParent().GetParent().GetParent()

def add_controls(self):
self.add_control(
'show_center', CheckBox,
_("Shows the center of the platform using the "
"current calibration parameters"))
self.add_control('motor_step_scanning', FloatTextBox)
self.add_control('motor_speed_scanning', FloatTextBox)
self.add_control('motor_acceleration_scanning', FloatTextBox)

def update_callbacks(self):
self.update_callback('show_center', point_cloud_roi.set_show_center)
self.update_callback('motor_step_scanning', ciclop_scan.set_motor_step)
self.update_callback('motor_speed_scanning', ciclop_scan.set_motor_speed)
self.update_callback('motor_acceleration_scanning', ciclop_scan.set_motor_acceleration)
Expand Down
2 changes: 2 additions & 0 deletions src/horus/util/profile.py
Original file line number Diff line number Diff line change
Expand Up @@ -369,6 +369,8 @@ def _initialize_settings(self):
Setting('motor_acceleration_scanning', _(u'Acceleration (º/s²)'), 'profile_settings',
float, 200.0, min_value=1.0, max_value=1000.0))

self._add_setting(
Setting('show_center', _('Show center'), 'profile_settings', bool, True))
self._add_setting(
Setting('use_roi', _('Use ROI'), 'profile_settings', bool, False))
self._add_setting(
Expand Down

0 comments on commit 2455e13

Please sign in to comment.