def __init__(self, parent=None, statusbar=False, connect={}, **kwds): wx.Frame.__init__(self, parent, -1) Widget.__init__(self, None, connect, **kwds) Container.__init__(self) if statusbar: self.CreateStatusBar() self.parent = parent
def __init__(self, place, orientation='horizontal', **kwds): orient = { 'horizontal': wx.TB_HORIZONTAL, 'vertical': wx.TB_VERTICAL } [orientation] wx.ToolBar.__init__(self, place[0], style=wx.SUNKEN_BORDER|wx.TB_FLAT|wx.TB_TEXT|orient) Widget.__init__(self, place, **kwds) Container.__init__(self) self.Bind(wx.EVT_TOOL, self.on_tool) self.tools = {}
def __init__(self, place, **kwds): wx.MenuBar.__init__(self) Container.__init__(self) self.frame = place[0] Widget.__init__(self, place, **kwds) self.frame.Bind(wx.EVT_MENU, self.on_menu) self.menus = {} self.items = {}
def __init__(self, place, **args): ScrolledPanel.__init__(self, place[0], -1)#, style=wx.SUNKEN_BORDER) Widget.__init__(self, place, **args) Container.__init__(self) self.layout = wx.BoxSizer(wx.VERTICAL) self.SetSizer(self.layout) self.SetAutoLayout(True) self.SetupScrolling()
def __init__(self, place, **args): ScrolledPanel.__init__(self, place[0], -1) #, style=wx.SUNKEN_BORDER) Widget.__init__(self, place, **args) Container.__init__(self) self.layout = wx.BoxSizer(wx.VERTICAL) self.SetSizer(self.layout) self.SetAutoLayout(True) self.SetupScrolling()
def __init__(self, place, orientation, **kwds): self.orientation = orientation MultiSplitterWindow.__init__(self, place[0], style=wx.SP_LIVE_UPDATE) Widget.__init__(self, place, **kwds) Container.__init__(self) self.SetOrientation({ 'horizontal': wx.HORIZONTAL, 'vertical': wx.VERTICAL }[orientation])
def __init__(self, menubar=None, label=None): Container.__init__(self) self._menu = _menu() self.menubar = menubar self.name = label self.items = {} self._menu.Bind(wx.EVT_MENU, self.on_menu) if menubar is not None: menubar.Append(self._menu, label) menubar.menus[label] = self
def __init__(self, place, rows=2, columns=2, **args): wx.Panel.__init__(self, place[0], -1) Widget.__init__(self, place, **args) Container.__init__(self) self.layout = wx.GridBagSizer(rows, columns) self.layout.SetEmptyCellSize((0, 0)) self.SetSizer(self.layout) # self.layout.SetSizeHints(self) self.SetAutoLayout(True)
def __init__(self, place, rows=2, columns=2, **args): wx.Panel.__init__(self, place[0], -1) Widget.__init__(self, place, **args) Container.__init__(self) self.layout = wx.GridBagSizer(rows, columns) self.layout.SetEmptyCellSize((0,0)) self.SetSizer(self.layout) # self.layout.SetSizeHints(self) self.SetAutoLayout(True)
def __init__(self, place, connect={}, **kwds): wx.Notebook.__init__(self, place[0], -1) Widget.__init__(self, place, connect, **kwds) Container.__init__(self) # item images self.imagelist = wx.ImageList(16, 16) self.SetImageList(self.imagelist) self.pixmaps = {} self.pages = []
def __init__(self, place, orientation='vertical', **kwds): wx.Panel.__init__(self, place[0], -1) Widget.__init__(self, place, **kwds) Container.__init__(self) if orientation == 'horizontal': self.layout = wx.BoxSizer(wx.HORIZONTAL) elif orientation == 'vertical': self.layout = wx.BoxSizer(wx.VERTICAL) else: raise NameError self.SetAutoLayout(True) self.SetSizer(self.layout)
def __init__(self, place, orientation='horizontal', **kwds): orient = { 'horizontal': wx.TB_HORIZONTAL, 'vertical': wx.TB_VERTICAL }[orientation] wx.ToolBar.__init__(self, place[0], style=wx.SUNKEN_BORDER | wx.TB_FLAT | wx.TB_TEXT | orient) Widget.__init__(self, place, **kwds) Container.__init__(self) self.Bind(wx.EVT_TOOL, self.on_tool) self.tools = {}
def getStateForSaving(self): """Returns state for saving @type state: dictionary @param state: State of the object """ state = Container.getStateForSaving(self) if not state.has_key("attributes"): state["attributes"] = [] state["attributes"].append("Container") state.update(CarryableItem.getStateForSaving(self)) return state
def find(self, robot): c = Container() bins = [self.find_bin(i, robot) for i in xrange(4)] c.bins = filter(lambda b: b.found, bins) if len(c.bins) > 0: c.orientation = radians(self.yaw - robot.yaw) % pi return True, c else: c.orientation = None return False, c
def find(self, robot): self.buoys = filter(lambda x: x.found, self.buoys) for buoy in self.buoys: buoy.found = False new_buoys = [] for pos, color in izip(self.positions, self.color_names): absolute_pos = self.absolute_point(pos) theta, phi = robot.find_point("forward", absolute_pos) dist = numpy.linalg.norm(absolute_pos - robot.pos) if dist > 6 and dist < 25 and \ theta != None and \ phi != None: theta *= robot.get_camera_fov("forward", vertical=False) / 2 phi *= robot.get_camera_fov("forward", vertical=True) / 2 # Find existing bouy with similar theta and phi similar_buoy_found = False for buoy in self.buoys: if buoy.color == color: similar_buoy_found = True buoy.found = True buoy.theta = theta buoy.phi = phi buoy.r = dist break # Create new buoy if not similar_buoy_found: buoy = Container() buoy.found = True buoy.theta = theta buoy.phi = phi buoy.r = dist buoy.color = color buoy.id = self.id_counter self.id_counter += 1 new_buoys.append(buoy) self.buoys.extend(new_buoys) # Copy self.buoys to self.output.buoys buoy_found = False self.output.buoys = [] for buoy in self.buoys: if buoy.found: buoy_found = True self.output.buoys.append(buoy) return buoy_found, self.output
def find_paths(robot, entities): paths = [] for entity in entities: print "Looking at:", entity if entity.__class__.__name__ == "PathEntity": found, data = entity.find(robot) print " ", found, data if found: paths.append(data) c = Container() c.paths = paths return c
def init(self): self.output = Container() self.adaptive_thresh_blocksize = 31 self.adaptive_thresh = 10 self.min_area = 20 self.max_area = 5000 self.mid_sep = 50 self.recent_id = 1 self.trans_thresh = 30 self.candidates = [] self.confirmed = [] self.lastseen_thresh = 0 self.seencount_thresh = 2
def find(self, robot): c = Container() c.left_pole = robot.find_point("forward", self.absolute_point((0, 5))) c.right_pole = robot.find_point("forward", self.absolute_point( (0, -5))) if c.left_pole: c.left_pole *= self.image_width / 2 if c.right_pole: c.right_pole *= self.image_width / 2 gate_found = False if c.left_pole is not None or c.right_pole is not None: gate_found = True return gate_found, c
def __init__(self, *args, **kwargs): self.positions = [ numpy.array(kwargs.pop("pos_red", (0, 0, 0))), numpy.array(kwargs.pop("pos_green", (0, 0, 0))), numpy.array(kwargs.pop("pos_yellow", (0, 0, 0))), ] super(BuoyEntity, self).__init__(*args, **kwargs) self.colors = [ (1, 0, 0), (0, 1, 0), (1, 1, 0), ] self.color_names = ("red", "green", "yellow") self.output = Container() self.buoys = [] self.output.buoys = [] self.id_counter = 0
def process_frame(self, frame, debug=True): # Scale image to reduce processing #scale_in_place(frame, (frame.width*0.7, frame.height*0.7)) if debug: debug_frame = cv.CloneImage(frame) else: debug_frame = False # Searching State # Search for buoys, then move to tracking when they are found if self.state == "searching": trackers = self.initial_search(frame, debug_frame) if trackers: self.trackers = trackers self.state = "tracking" try: svr.debug_close("Saturation") svr.debug_close("Red") svr.debug_close("AdaptiveThreshold") except: pass # Tracking State num_buoys_found = 0 if self.state == "tracking": num_buoys_found, locations = self.buoy_track( frame, self.trackers, debug_frame) if num_buoys_found > 0: self.buoy_locations = locations if debug: svr.debug("Buoy2011", debug_frame) # Convert to output format self.output.buoys = [] for location in self.buoy_locations: buoy = Container() buoy.theta = location[0] * (34 / (frame.width / 2)) buoy.phi = location[1] * (30 / (frame.height / 2) ) # Complete guess on vertical fov buoy.id = 1 self.output.buoys.append(buoy) self.return_output()
def process_frame(self, frame): buoy_locations = [] # Scale image to reduce processing ''' scale = 0.7 frame_scaled = cv.CreateImage((int(frame.width*scale), int(frame.height*scale)), 8, 3) cv.Resize(frame, frame_scaled) cv.SetImageROI(frame, (0, 0, int(frame.width*scale), int(frame.height*scale))) ''' # Create debug_frame if self.debug: debug_frame = cv.CloneImage(frame) else: debug_frame = False # Look for buoys if there aren't any trackers yet if not self.trackers: self.trackers = self.initial_search(frame, debug_frame) if self.trackers: buoy_locations = map(lambda x: adjust_location(x.object_center, frame.width, frame.height), self.trackers) if debug_frame: svr.debug("Buoy", debug_frame) return # Tracking else: num_buoys_found, buoy_locations = self.buoy_track(frame, self.trackers, debug_frame) if debug_frame: svr.debug("Buoy", debug_frame) # Convert to output format self.output.buoys = [] for location in buoy_locations: buoy = Container() buoy.theta = location[0] buoy.phi = location[1] buoy.id = 1 self.output.buoys.append(buoy) if self.output.buoys: self.return_output() return self.output
def process_frame(self, frame): buoy_locations = [] # Create debug_frame if self.debug: debug_frame = cv.CloneImage(frame) else: debug_frame = False # Look for buoys if there aren't any trackers yet if not self.trackers: self.trackers = self.initial_search(frame, debug_frame) if self.trackers: buoy_locations = map(lambda x: adjust_location(x.object_center, frame.width, frame.height), self.trackers) if debug_frame: svr.debug("Buoy", debug_frame) return # Tracking else: num_buoys_found, buoy_locations = self.buoy_track(frame, self.trackers, debug_frame) # Debug info if debug_frame: for tracker in self.trackers: print "Drawing Circle!!!!", tracker.object_center cv.Circle(debug_frame, (int(tracker.object_center[0]), int(tracker.object_center[1])), tracker.size[0], (0, 0, 255), 2) if debug_frame: svr.debug("Buoy", debug_frame) # Convert to output format self.output.buoys = [] for location in buoy_locations: buoy = Container() buoy.theta = location[0] buoy.phi = location[1] buoy.id = 1 self.output.buoys.append(buoy) if self.output.buoys: self.return_output() return self.output
def __init__(self, *args, **kwargs): """ pos, color=(0.5, 0.5, 0.5), yaw=0, pitch=0, roll=0): ARGS: * pos: list of format [x,y,z] specifying the location of the buoy group/array/entity. * color: ??? * yaw: z-axis rotation of the buoys entity * pitch: y-axis rotation of the buoys entity * roll: x-axis rotation of the buoys entity KWARGS: * pos_<color>: the XYZ position of a buoy entity. <color> can be red, green, or yellow. """ # pop off class specific keyword arguments first pos_red = numpy.array(kwargs.pop("pos_red", (0, 0, 0))) pos_green = numpy.array(kwargs.pop("pos_green", (0, 0, 0))) pos_yellow = numpy.array(kwargs.pop("pos_yellow", (0, 0, 0))) # inherit base class super(BuoyEntity, self).__init__(*args, **kwargs) # visual parameters self.positions = [ pos_red, pos_green, pos_yellow, ] self.colors = [ (1, 0, 0), (0, 1, 0), (1, 1, 0), ] self.color_names = ("red", "green", "yellow") # internal buoy tracking variables self.buoys = [] self.id_counter = 0 # generate output container self.output = Container() self.output.buoys = []
def find_bin(self, i, robot): # I, Robot. The book is 1,000,000 times # better than the movie pos = BIN_POSITIONS[i] center = self.absolute_point((pos[0], pos[1], 0)) b = Container() b.theta, b.phi = robot.find_point("down", center) b.found = b.theta is not None and b.phi is not None b.shape = SHAPE_NAMES[i] if b.found: if self.bin_ids.get(i, None) is None: # Assign new id to bin self.bin_ids[i] = self.bins_counter self.bins_counter += 1 b.id = self.bin_ids[i] else: b.id = None self.bin_ids[i] = b.id return b
def find(self, robot): c = Container() c.left_pole = robot.find_point("forward", self.absolute_point((0, 3))) c.right_pole = robot.find_point("forward", self.absolute_point( (0, -3))) c.center_pole = robot.find_point("forward", self.absolute_point( (0, 0))) bottom_pole = robot.find_point("forward", self.absolute_point((0, 0, -4)))[1] if c.left_pole: c.left_pole *= robot.get_camera_fov("forward") / 2 if c.right_pole: c.right_pole *= robot.get_camera_fov("forward") / 2 if c.center_pole: c.center_pole *= robot.get_camera_fov("forward") / 2 if bottom_pole: bottom_pole *= robot.get_camera_fov("forward", vertical=True) / 2 if c.left_pole and c.right_pole: theta = abs(c.left_pole - c.right_pole) c.r = 3 / tan(radians(theta / 2)) elif c.center_pole: theta = abs(c.center_pole) c.r = 3 / tan(radians(theta / 2)) else: c.r = None if c.r and bottom_pole: c.crossbar_depth = -1 * c.r * tan(radians(bottom_pole)) else: c.crossbar_depth = None hedge_found = False if c.left_pole is not None or c.right_pole is not None or c.center_pole is not None: hedge_found = True return hedge_found, c
def __init__(self, parent=None, connect={}, **kwds): wx.Dialog.__init__(self, parent, -1, style=wx.THICK_FRAME) Widget.__init__(self, None, connect, **kwds) Container.__init__(self) self.parent = parent
def __init__(self, *args, **kwargs): super(PathEntity, self).__init__(*args, **kwargs) self.output = Container()
def init(self): self.output = Container() self.trackers = [] self.seen_buoy_count = 0 # Used in initial_search
def init(self): self.output = Container() self.trackers = [] self.seen_buoy_count = 0 # Used in initial_search self.last_buoy = None self.last_buoy_time = None
def process_frame(self, frame): # This is equivalent to the old routine, but it isn't actually necessary #height, width, depth = libvision.cv_to_cv2(frame).shape #self.debug_frame = np.zeros((height, width, 3), np.uint8) # Debug numpy is CV2 self.debug_frame = libvision.cv_to_cv2(frame) # CV2 Transforms self.numpy_frame = self.debug_frame.copy() self.numpy_frame = cv2.medianBlur(self.numpy_frame, 5) self.numpy_frame = cv2.cvtColor(self.numpy_frame, cv2.COLOR_BGR2HSV) (self.frame1, self.frame2, self.frame3) = cv2.split(self.numpy_frame) # Change the frame number to determine what channel to focus on self.numpy_frame = self.frame2 # Thresholding self.numpy_frame = cv2.adaptiveThreshold( self.numpy_frame, 255, cv2.ADAPTIVE_THRESH_MEAN_C, cv2.THRESH_BINARY_INV, self.adaptive_thresh_blocksize, self.adaptive_thresh) kernel = cv2.getStructuringElement(cv2.MORPH_ELLIPSE, (3, 3)) kernel2 = cv2.getStructuringElement(cv2.MORPH_ELLIPSE, (4, 4)) # kernel = np.ones((2,2), np.uint8) self.numpy_frame = cv2.erode(self.numpy_frame, kernel) self.numpy_frame = cv2.dilate(self.numpy_frame, kernel2) self.adaptive_frame = self.numpy_frame.copy() # Find contours contours, hierarchy = cv2.findContours(self.numpy_frame, cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE) self.raw_buoys = [] if len(contours) > 0: cnt = contours[0] cv2.drawContours(self.numpy_frame, contours, -1, (255, 255, 255), 3) for h, cnt in enumerate(contours): approx = cv2.approxPolyDP(cnt, 0.01 * cv2.arcLength(cnt, True), True) center, radius = cv2.minEnclosingCircle(cnt) x, y = center if len(approx) > 12: if (radius > 30): new_buoy = Buoy(int(x), int(y), int(radius), "unknown") new_buoy.id = self.recent_id self.recent_id += 1 self.raw_buoys.append(new_buoy) cv2.drawContours(self.numpy_frame, [cnt], 0, (0, 0, 255), -1) self.raw_buoys.append(new_buoy) for buoy1 in self.raw_buoys[:]: for buoy2 in self.raw_buoys[:]: if buoy1 is buoy2: continue if buoy1 in self.raw_buoys and buoy2 in self.raw_buoys and \ math.fabs(buoy1.centerx - buoy2.centerx) > self.mid_sep and \ math.fabs(buoy1.centery - buoy2.centery) > self.mid_sep: if buoy1.radius < buoy2.radius: self.raw_buoys.remove(buoy1) elif buoy2.radius < buoy1.radius: self.raw_buoys.remove(buoy2) for buoy in self.raw_buoys: self.match_buoys(buoy) self.sort_buoys() self.draw_buoys() self.return_output() self.debug_to_cv = libvision.cv2_to_cv(self.debug_frame) self.numpy_to_cv = libvision.cv2_to_cv(self.numpy_frame) self.adaptive_to_cv = libvision.cv2_to_cv(self.adaptive_frame) svr.debug("processed", self.numpy_to_cv) svr.debug("adaptive", self.adaptive_to_cv) svr.debug("debug", self.debug_to_cv) # Convert to output format self.output.buoys = [] if self.raw_buoys is not None and len(self.raw_buoys) > 0: for buoy in self.raw_buoys: x = buoy.centerx y = buoy.centery buoy = Container() buoy.theta = x buoy.phi = y buoy.id = 1 self.output.buoys.append(buoy) if self.output.buoys: self.return_output() return self.output
def get(self): if not self.url: raise AttributeError("Object has None url") self.container = Container(self.url, 'euc-kr', webkit=True) self.elements = self._getBaseElements() self._getAll()
def __init__(self, place, orientation, **kwds): self.orientation = orientation MultiSplitterWindow.__init__(self, place[0], style=wx.SP_LIVE_UPDATE) Widget.__init__(self, place, **kwds) Container.__init__(self) self.SetOrientation({'horizontal':wx.HORIZONTAL, 'vertical':wx.VERTICAL}[orientation])
def __init__ (self, item_type, **kwargs): Container.__init__(self, **kwargs) CarryableItem.__init__(self, item_type, **kwargs) self.own_bulk = 0 self.own_weight = 0
def placeItem(self,item, index=None): if len(self.items) > 0 : raise self.SlotBusy ('%s is already busy' % self) Container.placeItem(self, item)
def __init__ (self, **kwargs): Container.__init__(self, **kwargs)