def set_compressed_image(self, compressed_path, add=True): ''' Loads an image as the target object in compressed form. The compressing robot arm is assumed to also be in the image, so areas with the same color as it will be ignored. Thus, the compressed object should have a different color from the arm. Args: compressed_path: file path to arm object image. add: boolean denoting whether to add the compressed image to the list of images, or to create a new list starting with the current image. force: amount of force used to achieve the object compresssion in the image (in Newtons). Returns: True if image was loaded and segmented successfully; false otherwise. ''' if compressed_path is None: return False if os.path.isdir(compressed_path): for file in sorted(os.listdir(compressed_path)): if file.endswith(".png") or file.endswith(".jpg"): self.set_compressed_image(compressed_path + file) new_obj = SegmentedObject(self.bg_path, compressed_path) if not self._color_low is None and not self._color_high is None: new_obj.set_ignore_color(self._color_low, self._color_high) if add: self.compress_obj.append(new_obj) #self.compress_force.append(force) else: self.compress_obj = [new_obj] #self.compress_force = [force] return True
def set_uncompressed_image(self, uncompressed_path): ''' Loads an image as the target object in uncompressed form. Args: uncompressed_path: file path to arm object image. Returns: True if image was loaded and segmented successfully; false otherwise. ''' if uncompressed_path is None: return False self.uncompress_obj = SegmentedObject(self.bg_path, uncompressed_path) return True
def set_box_image(self, box_path): ''' Loads an image as the reference box object, which will be segmented to determine the reference dimensions. Previous dimensions settings, included hardcoded dimensions, will be replaced. Args: box_path: file path to reference box object image. Returns: True if image was loaded and segmented successfully, and reference box dimension set; false otherwise. ''' if box_path is None: return False self.box_obj = SegmentedObject(self.bg_path, box_path) self._box_size = None return True
def set_arm_image(self, arm_path, hue_tolerance=60, saturation_tolerance=96, value_tolerance=128): ''' Loads an image as the arm object, which will be segmented to determine its color (which will be ignored in segmentation of the compressed object). Note that this color is represented as a range in HSV space, which is determined based on the colors the object 'mostly' consists of. Previous color range settings, included hardcoded values, will be replaced. The size of the range in hue, saturation, and value can be adjusted as parameters. Note the domain of hue = 0 to 180, saturation = 0 to 256, and value = 0 to 256. Args: arm_path: file path to arm object image. hue_tolerance: size of the hue range for the arm's color. saturation_tolerance: size of saturation range for the arm's color. value_tolerance: size of the value range for the arm's color. Returns: True if image was loaded and segmented successfully, and arm color range set; false otherwise. ''' if arm_path is None: return False if not (0 <= hue_tolerance <= 180): return False if not (0 <= saturation_tolerance <= 256): return False if not (0 <= value_tolerance <= 256): return False self.arm_obj = SegmentedObject(self.bg_path, arm_path) self._color_tol = [ hue_tolerance, saturation_tolerance, value_tolerance ] self._update_arm_color() return True
def set_measure_image(self, measure_path, width_mm, height_mm): ''' Loads an image as the measurement reference object, which is segmented to determine the millimeter per pixel resolution of the BaxterObject's images. Args: measure_path: file path to measurement reference box object image. width_mm: millimeter width of the measure object. height_mm: millimeter height of the measure object. Returns: True if image was loaded and segmented successfully, and reference box dimension set; false otherwise. ''' if measure_path is None: return False self.measure_obj = SegmentedObject(self.bg_path, measure_path) self._measure_mm = (width_mm, height_mm) self._measure_size = None return True