def octahedron(center=(0, 0, 0), size=1, **kwds): r""" Return an octahedron. INPUT: - ``center`` -- (default: (0,0,0)) - ``size`` -- (default: 1) - ``color`` -- a string that describes a color; this can also be a list of 3-tuples or strings length 6 or 3, in which case the faces (and oppositive faces) are colored. - ``opacity`` -- (default: 1) if less than 1 then is transparent EXAMPLES:: sage: G = octahedron((1,4,3), color='orange') sage: G += octahedron((0,2,1), size=2, opacity=0.6) sage: G Graphics3d Object """ if 'aspect_ratio' not in kwds: kwds['aspect_ratio'] = [1, 1, 1] return prep(Box(1, 1, 1).dual(**kwds), center, size, kwds)
def _get_all_ious(bbox_coords, conv_rows, conv_cols, anchor_dims, img_width, img_height, stride): # not used anymore, might be useful to keep around as a reference num_boxes = conv_rows * conv_cols * len(anchor_dims) num_gt_boxes = len(bbox_coords) result = np.zeros((num_boxes, num_gt_boxes)) out_of_bounds_idxs = [] num_boxes = conv_rows * conv_cols * len(anchor_dims) for i in range(num_boxes): y, x, anchor_idx = _idx_to_conv(i, conv_cols, len(anchor_dims)) x_center, y_center = _get_conv_center(x, y, stride) anchor_height, anchor_width = anchor_dims[anchor_idx] anchor_box = Box.from_center_dims_int(x_center, y_center, anchor_width, anchor_height) if _out_of_bounds(anchor_box, img_width, img_height): out_of_bounds_idxs.append(i) continue for bbox_idx in range(num_gt_boxes): iou = calc_iou(bbox_coords[bbox_idx], anchor_box.corners) result[i, bbox_idx] = iou return result, out_of_bounds_idxs
def extract_img_metadata(base_path, img_num): images_base = os.path.join(base_path, IMAGES_DIR) annotations_base = os.path.join(base_path, ANNOTATIONS_DIR) annotations_path = os.path.join(annotations_base, img_num + '.xml') if not os.path.exists(annotations_path): # hack for KITTI test data since there are no annotation files and we need annotation files to load the data filename = img_num + '.png' image_path = os.path.join(images_base, filename) raw_img = cv2.imread(image_path) height, width, depth = raw_img.shape root_node = ElementTree.Element('annotation') filename_node = ElementTree.Element('filename') filename_node.text = filename root_node.append(filename_node) size_node = ElementTree.Element('size') width_node = ElementTree.Element('width') width_node.text = str(width) height_node = ElementTree.Element('height') height_node.text = str(height) depth_node = ElementTree.Element('depth') depth_node.text = str(depth) size_node.append(width_node) size_node.append(height_node) size_node.append(depth_node) root_node.append(size_node) with open(annotations_path, 'w+') as f: to_write = str(ElementTree.tostring(root_node), 'utf-8') f.write(to_write) xml = ElementTree.parse(annotations_path) annotation = xml.getroot() image_path = os.path.join(images_base, annotation.find('filename').text) size = annotation.find('size') width = int(size.find('width').text) height = int(size.find('height').text) gt_boxes = [] for object in annotation.findall('object'): name = object.find('name').text bndbox = object.find('bndbox') # coords start at 1 in annotations, 0 in keras/tf xmin = int(float(bndbox.find('xmin').text)) - 1 xmax = int(float(bndbox.find('xmax').text)) - 1 ymin = int(float(bndbox.find('ymin').text)) - 1 ymax = int(float(bndbox.find('ymax').text)) - 1 difficult = int(object.find('difficult').text) == 1 box = Box(xmin, ymin, xmax, ymax) gt_box = GroundTruthBox(obj_cls=name, difficult=difficult, box=box) gt_boxes.append(gt_box) img_metadata = Metadata(img_num, width=width, height=height, gt_boxes=gt_boxes, image_path=image_path) return img_metadata
def createRepresentativeShape(self): drawer = LegacyDrawer() lightBox = Box() lightBox.setDrawer(drawer) lightBox.create() # material can be defined to match with light color lightBox.setMaterial(Material(**MaterialDefs.LIGHT_BOX)) return lightBox
def _process(self, image): # internal method, performs the expensive calculations needed to produce training inputs. conv_rows, conv_cols = self.calc_conv_dims(image.height, image.width) num_anchors = conv_rows * conv_cols * len(self.anchor_dims) bbreg_targets = np.zeros((num_anchors, 4), dtype=np.float32) can_use = np.zeros(num_anchors, dtype=np.bool) is_pos = np.zeros(num_anchors, dtype=np.bool) gt_box_coords = get_bbox_coords(image.gt_boxes) anchor_coords = _get_all_anchor_coords(conv_rows, conv_cols, self.anchor_dims, self.stride) out_of_bounds_idxs = _get_out_of_bounds_idxs(anchor_coords, image.width, image.height) all_ious = cross_ious(anchor_coords, gt_box_coords) # all_ious, out_of_bounds_idxs = get_all_ious_faster(gt_box_coords, conv_rows, conv_cols, ANCHORS_PER_LOC, image.width, image.height, self.stride) max_iou_by_anchor = np.amax(all_ious, axis=1) max_idx_by_anchor = np.argmax(all_ious, axis=1) max_iou_by_gt_box = np.amax(all_ious, axis=0) max_idx_by_gt_box = np.argmax(all_ious, axis=0) # anchors with more than 0.7 IOU with a gt box are positives pos_box_idxs = np.where(max_iou_by_anchor > POS_OVERLAP)[0] # for each gt box, the highest non-zero IOU anchor is a positive eligible_idxs = np.where(max_iou_by_gt_box > 0.0) more_pos_box_idxs = max_idx_by_gt_box[eligible_idxs] total_pos_idxs = np.unique( np.concatenate((pos_box_idxs, more_pos_box_idxs))) can_use[total_pos_idxs] = 1 is_pos[total_pos_idxs] = 1 # don't bother optimizing, profiling showed this loop's runtime is negligible for box_idx in total_pos_idxs: y, x, anchor_idx = _idx_to_conv(box_idx, conv_cols, len(self.anchor_dims)) x_center, y_center = _get_conv_center(x, y, self.stride) anchor_height, anchor_width = self.anchor_dims[anchor_idx] anchor_box = Box.from_center_dims_int(x_center, y_center, anchor_width, anchor_height) gt_box_idx = max_idx_by_anchor[box_idx] reg_params = get_reg_params(anchor_box.corners, gt_box_coords[gt_box_idx]) bbreg_targets[box_idx, :] = BBREG_MULTIPLIERS * reg_params neg_box_idxs = np.where( np.logical_and(is_pos == 0, max_iou_by_anchor < NEG_OVERLAP))[0] can_use[neg_box_idxs] = 1 can_use[out_of_bounds_idxs] = 0 self._cache[image.cache_key] = { 'can_use': can_use, 'is_pos': is_pos, 'bbreg_targets': bbreg_targets }
def make_box(self, scale, color): """ Create a Cube with the specified parameters @param scale: scale factor for the cube @param color: color for the cube @return: the created cube """ box = Box() box.set_color(c=color) box.set_location(0, 0, 0) box.set_size(scale, scale, scale) return box
def addBox(self, xlabel=' ', ylabel=' ', title=" ", lw=2, fontsize=24, mplprops={}): pixelSize = self.width b = Box.Box(xlabel, ylabel, title, lw, fontsize, mplprops, self) self.drawOrder.append(b) return b
def make_box(self, scale, color): """ Create a Cube with the specified parameters @param scale: scale factor for the cube @param color: color for the cube @return: the created cube """ box = Box() box.set_color(c=color) box.set_location(0, 0, 0) box.set_size(scale, scale, scale) return box
def cube(center=(0, 0, 0), size=1, color=None, frame_thickness=0, frame_color=None, **kwds): """ A 3D cube centered at the origin with default side lengths 1. INPUT: - ``center`` -- (default: (0,0,0)) - ``size`` -- (default: 1) the side lengths of the cube - ``color`` -- a string that describes a color; this can also be a list of 3-tuples or strings length 6 or 3, in which case the faces (and oppositive faces) are colored. - ``frame_thickness`` -- (default: 0) if positive, then thickness of the frame - ``frame_color`` -- (default: None) if given, gives the color of the frame - ``opacity`` -- (default: 1) if less than 1 then it's transparent EXAMPLES: A simple cube:: sage: cube() Graphics3d Object A red cube:: sage: cube(color="red") Graphics3d Object A transparent grey cube that contains a red cube:: sage: cube(opacity=0.8, color='grey') + cube(size=3/4) Graphics3d Object A transparent colored cube:: sage: cube(color=['red', 'green', 'blue'], opacity=0.5) Graphics3d Object A bunch of random cubes:: sage: v = [(random(), random(), random()) for _ in [1..30]] sage: sum([cube((10*a,10*b,10*c), size=random()/3, color=(a,b,c)) for a,b,c in v]) Graphics3d Object Non-square cubes (boxes):: sage: cube(aspect_ratio=[1,1,1]).scale([1,2,3]) Graphics3d Object sage: cube(color=['red', 'blue', 'green'],aspect_ratio=[1,1,1]).scale([1,2,3]) Graphics3d Object And one that is colored:: sage: cube(color=['red', 'blue', 'green', 'black', 'white', 'orange'], ....: aspect_ratio=[1,1,1]).scale([1,2,3]) Graphics3d Object A nice translucent color cube with a frame:: sage: c = cube(color=['red', 'blue', 'green'], frame=False, frame_thickness=2, ....: frame_color='brown', opacity=0.8) sage: c Graphics3d Object A raytraced color cube with frame and transparency:: sage: c.show(viewer='tachyon') This shows :trac:`11272` has been fixed:: sage: cube(center=(10, 10, 10), size=0.5).bounding_box() ((9.75, 9.75, 9.75), (10.25, 10.25, 10.25)) AUTHORS: - William Stein """ if isinstance(color, (list, tuple)) and len(color) > 0 and isinstance( color[0], (list, tuple, str)): B = ColorCube(size=[0.5, 0.5, 0.5], colors=color, **kwds) else: if color is not None: kwds['color'] = color B = Box(0.5, 0.5, 0.5, **kwds) if frame_thickness > 0: if frame_color is None: B += frame3d((-0.5, -0.5, -0.5), (0.5, 0.5, 0.5), thickness=frame_thickness) else: B += frame3d((-0.5, -0.5, -0.5), (0.5, 0.5, 0.5), thickness=frame_thickness, color=frame_color) return prep(B, center, size, kwds)
def add_box(self): """ Add a box to the current scene """ self.scenes[self.current_scene].add_object(Box()) self.redraw()
from ode import FixedJoint, environment from shapes import Scene, Box from dog_model import make_dog scene = Scene() dog = make_dog(scene) # box = Box(scene, density=1, dimensions=(.05, .05, .05), position=(0, -.15, 0.1), color=(1, 0.2, 0.2)) floor = Box(scene, density=1, dimensions=(1, .2, 1), position=(0, -.30, 0), color=(0.7, 0.7, 0.7)) joint = FixedJoint(scene.world) joint.attach(floor.body, environment) joint.setFixed() scene.visualize(duration=10.0, delta=0.005)
def subdivide(self, shapeName, value): shape = self.__shapeListLS.get(shapeName) shape.subdivide(value) self.updateShapeListSS(shapeName) def setDrawStyle(self, drawStyle): self.__drawStyle = drawStyle def draw(self): for i in self.__shapeListSS.values(): # I will break camera class coupling with the shape class # It may not be efficent I am thinking on it. i.setDrawStyle(self.__drawStyle) i = self.__activeCam.view(i) i.draw() Light.lightsON(self.__lightsStatus) for light in self.__lights: if (light.getLightStatus()): light = self.__activeCam.view(light) light.draw() def __str__(self): return "Scene" if __name__ == "__main__": a = Scene("main") a.addShape("box", Box()) a.addShape("spehere", Sphere())