def __init__(self, controller_ip=0, controller_port=0, source="kinect", standalone=False, filepath="default", test=0): self.logger = logging.getLogger("Borg.Brain.Vision.ObstacleDetector") avm.__init__(self, controller_ip, controller_port) self.fail_count = 0 #TODO: Remove this hack (inserted to be backwards compitable for config files that set "kinect" as source instead of "kinect_depth": if source == "kinect": source = "kinect_depth" if standalone: self.logger.setLevel("WARNING") # if detector is run as standalone, the kinect images will be retreived # directly from the kinect instead of from shared memory # set standalone true, if you want to use the obstacle detector without the architecture self.standalone = standalone # update frequency of the behaviour self.update_frequency = 20 # bit depth of the used depth image self.imageDepth = 8 #tolerance when it comes to detecting obstacles (don't set it too tight) # The higher the tollerance, the larger an obstacle should be before it is detected # when it's to low the risk is taken it will detect the floor as an obstacle... self.tolerance = 2.0 self.minTolerance = self.tolerance self.maxTolerance = self.tolerance # calibration matrix (containing floor calibrated data) # min.cal, max.cal and avg.cal are files generated during calibrations. # They contain the distance min, max and average distance to the floor from the kinect. # The test files are used by obstacledetectortest.py if test == 0: minfile = os.environ[ 'BORG'] + '/brain/src/vision/obstacledetectorutil/min.cal' maxfile = os.environ[ 'BORG'] + '/brain/src/vision/obstacledetectorutil/max.cal' avgfile = os.environ[ 'BORG'] + '/brain/src/vision/obstacledetectorutil/avg.cal' else: minfile = os.environ[ 'BORG'] + '/brain/src/vision/obstacledetectorutil/testmin.cal' maxfile = os.environ[ 'BORG'] + '/brain/src/vision/obstacledetectorutil/testmax.cal' avgfile = os.environ[ 'BORG'] + '/brain/src/vision/obstacledetectorutil/testavg.cal' # read the calibration files and store the content in variables (multidimensional arrays). self.minMatrix = self.getCalibrationData(minfile) self.maxMatrix = self.getCalibrationData(maxfile) self.avgMatrix = self.getCalibrationData(avgfile) # current image where obstacles should be detected in. self.image = 0 #segmentizer, used for segmentating images into segments self.segmentizer = Segmentizer() # specify the source (file or kinect) # reading from file is used for testing # when read from kinect, the depth images are read from the shared memory, or directly from the kinect (specified in self.standalone) self.source = source if source == "file": if filepath == "default": self.path = os.environ[ 'BORG'] + '/brain/data/od_images/ball_left/' else: self.path = filepath self.filelist = glob.glob(os.path.join(self.path, '*.png')) self.framenumber = 0 else: self.vid_mem_reader = util.vidmemreader.VidMemReader([self.source])