@ -1,7 +1,5 @@
#!/usr/bin/env python3
#from __future__ import print_function
import stretch_funmap.max_height_image as mh
import numpy as np
import scipy.ndimage as nd
@ -63,8 +61,6 @@ def find_object_to_grasp(height_image, display_on=False):
if display_on :
rgb_image = height_image . rgb_image . copy ( )
#rgb_image[surface_mask > 0] = (rgb_image[surface_mask > 0]/2) + [0, 127, 0]
#rgb_image[obstacle_selector] = (rgb_image[obstacle_selector]/2) + [0, 0, 127]
rgb_image [ surface_mask > 0 ] = ( rgb_image [ surface_mask > 0 ] / / 2 ) + [ 0 , 127 , 0 ]
rgb_image [ obstacle_selector ] = ( rgb_image [ obstacle_selector ] / / 2 ) + [ 0 , 0 , 127 ]
cv2 . imshow ( ' obstacles ' , rgb_image )
@ -73,8 +69,6 @@ def find_object_to_grasp(height_image, display_on=False):
if display_on :
rgb_image = height_image . rgb_image . copy ( )
#rgb_image[surface_mask > 0] = (rgb_image[surface_mask > 0]/2) + [0, 127, 0]
#rgb_image[obstacle_mask > 0] = (rgb_image[obstacle_mask > 0]/2) + [0, 0, 127]
rgb_image [ surface_mask > 0 ] = ( rgb_image [ surface_mask > 0 ] / / 2 ) + [ 0 , 127 , 0 ]
rgb_image [ obstacle_mask > 0 ] = ( rgb_image [ obstacle_mask > 0 ] / / 2 ) + [ 0 , 0 , 127 ]
@ -92,7 +86,6 @@ def find_object_to_grasp(height_image, display_on=False):
# and other phenomena.
kernel_width_pix = 5 #3
iterations = 3 #5
#kernel_radius_pix = (kernel_width_pix - 1) / 2
kernel_radius_pix = ( kernel_width_pix - 1 ) / / 2
kernel = np . zeros ( ( kernel_width_pix , kernel_width_pix ) , np . uint8 )
cv2 . circle ( kernel , ( kernel_radius_pix , kernel_radius_pix ) , kernel_radius_pix , 255 , - 1 )
@ -107,9 +100,7 @@ def find_object_to_grasp(height_image, display_on=False):
# Process the candidate object points
# Treat connected components of candidate object points as objects. Fit ellipses to these segmented objects.
#label_image, max_label_index = sk.measure.label(obstacles_on_surface, neighbors=8, background=0, return_num=True, connectivity=None)
label_image , max_label_index = sk . measure . label ( obstacles_on_surface , background = 0 , return_num = True , connectivity = 2 )
#region_properties = sk.measure.regionprops(label_image, intensity_image=None, cache=True, coordinates='xy')
region_properties = sk . measure . regionprops ( label_image , intensity_image = None , cache = True )
if display_on :
rgb_image = height_image . rgb_image . copy ( )
@ -218,7 +209,6 @@ def draw_grasp(rgb_image, grasp_target):
surface_convex_hull_mask = grasp_target [ ' surface_convex_hull_mask ' ]
object_selector = grasp_target [ ' object_selector ' ]
object_ellipse = grasp_target [ ' object_ellipse ' ]
#rgb_image[surface_convex_hull_mask > 0] = (rgb_image[surface_convex_hull_mask > 0]/2) + [0, 127, 0]
rgb_image [ surface_convex_hull_mask > 0 ] = ( rgb_image [ surface_convex_hull_mask > 0 ] / / 2 ) + [ 0 , 127 , 0 ]
rgb_image [ object_selector ] = [ 0 , 0 , 255 ]
draw_ellipse_axes ( rgb_image , object_ellipse , color = [ 255 , 255 , 255 ] )
@ -268,9 +258,7 @@ def find_closest_flat_surface(height_image, robot_xy_pix, display_on=False):
if remove_floor :
segments_image [ floor_mask > 0 ] = 0
#label_image, max_label_index = sk.measure.label(segments_image, neighbors=8, background=0, return_num=True, connectivity=None)
label_image , max_label_index = sk . measure . label ( segments_image , background = 0 , return_num = True , connectivity = 2 )
#region_properties = sk.measure.regionprops(label_image, intensity_image=image, cache=True, coordinates='xy')
region_properties = sk . measure . regionprops ( label_image , intensity_image = image , cache = True )
if display_on :
color_label_image = sk . color . label2rgb ( label_image , image = image_rgb , colors = None , alpha = 0.3 , bg_label = 0 , bg_color = ( 0 , 0 , 0 ) , image_alpha = 1 , kind = ' overlay ' )
@ -439,8 +427,6 @@ def render_segments(segments_image, segment_info, output_key_image=False):
font_scale = 1.1 * ( size / 100.0 )
line_width = 1
line_color = ( 0 , 0 , 0 )
#cv2.putText(key_image_color, '%.3f m' % h, ((i*size) + size/10, size/2),
# font, font_scale, line_color, line_width, cv2.LINE_AA)
cv2 . putText ( key_image_color , ' %.3f m ' % h , ( ( i * size ) + size / / 10 , size / / 2 ) ,
font , font_scale , line_color , line_width , cv2 . LINE_AA )
else :
@ -1043,14 +1029,22 @@ def find_floor(segment_info, segments_image, verbose=False):
for i in segment_info :
height_m = segment_info [ i ] [ ' height_m ' ]
bin_value = segment_info [ i ] [ ' bin_value ' ]
# Old values changed on June 3, 2021 due to no floor segment
# being within the bounds, which resulted in an error.
#min_floor_m = -0.02
#max_floor_m = 0.1
# New values set on June 3, 2021.
min_floor_m = - 0.05
max_floor_m = 0.05
print ( ' segment = {0}, histogram bin_value = {1}, height_m = {2}, min_floor_m = {3}, max_floor_m = {4} ' . format ( i , bin_value , height_m , min_floor_m , max_floor_m ) )
if verbose :
print ( ' segment = {0}, histogram bin_value = {1}, height_m = {2}, min_floor_m = {3}, max_floor_m = {4} ' . format ( i , bin_value , height_m , min_floor_m , max_floor_m ) )
if ( height_m > = min_floor_m ) and ( height_m < = max_floor_m ) :
print ( ' found candidate floor segment! ' )
if verbose :
print ( ' found candidate floor segment! ' )
if ( floor_id is None ) and ( bin_value > 0.0 ) :
floor_id = i
max_bin_value = bin_value
@ -1067,7 +1061,8 @@ def find_floor(segment_info, segments_image, verbose=False):
print ( ' floor_id = ' , floor_id )
print ( ' max_bin_value = ' , max_bin_value )
else :
print ( ' segment_max_height_image.py : no floor segment found... ' )
if verbose :
print ( ' segment_max_height_image.py : no floor segment found... ' )
return floor_id , floor_mask