def updateGeoPoints(self): gps = self.gPoints acs = self.attach.corners #make sure the gpoints are left-up and right-down dis = [[], []] xyzs = [ gps[0].xyz, (gps[1].xyz[0], gps[0].xyz[1], gps[1].xyz[2]), gps[1].xyz, (gps[0].xyz[0], gps[1].xyz[1], gps[0].xyz[2]) ] for i in range(2): for xyz in xyzs: dis[i].append(utils.pointsDistance(xyz, acs[i * 2].xyz)) xyz = xyzs[dis[i].index(min(dis[i]))] gps[i] = objs.GeoPoint(self.scene, None, xyz) # stick to wall boundary localBbox2d = [] for i in range(2): xyz = list(gps[i].xyz) dis = utils.pointsDirectionPow(acs[i * 2].xyz, gps[i].xyz, 2) cxz = math.sqrt(dis[0] + dis[2]) / self.attach.width cy = math.sqrt(dis[1]) / self.scene.layoutHeight if cxz <= 0.03: xyz[0] = acs[i * 2].xyz[0] xyz[2] = acs[i * 2].xyz[2] cxz = 0 if cy <= 0.03: xyz[1] = acs[i * 2].xyz[1] cy = 0 gps[i] = objs.GeoPoint(self.scene, None, tuple(xyz)) coord = (cxz, cy) if i == 0 else (1 - cxz, 1 - cy) localBbox2d.append(coord) self.localBbox2d = tuple(localBbox2d)
def updateCorners(self): gps = self.gPoints cameraH = self.scene.cameraHeight cam2ceilH = self.scene.layoutHeight - cameraH self.corners = [ objs.GeoPoint((gps[0].xyz[0], cam2ceilH, gps[0].xyz[2])), objs.GeoPoint((gps[1].xyz[0], cam2ceilH, gps[1].xyz[2])), objs.GeoPoint((gps[1].xyz[0], -cameraH, gps[1].xyz[2])), objs.GeoPoint((gps[0].xyz[0], -cameraH, gps[0].xyz[2])) ]
def updateCorners(self): gps = self.gPoints scene = self.scene self.corners = [ objs.GeoPoint(scene, None, gps[0].xyz), objs.GeoPoint(scene, None, (gps[1].xyz[0], gps[0].xyz[1], gps[1].xyz[2])), objs.GeoPoint(scene, None, gps[1].xyz), objs.GeoPoint(scene, None, (gps[0].xyz[0], gps[1].xyz[1], gps[0].xyz[2])) ]
def lnet2scene(data_path): with open(data_path) as f: content = f.readlines() data = [x.strip().split() for x in content] scene = objs.Scene() scene.cameraHeight = 1.6 scene.layoutHeight = float(data[0][0]) if math.isnan(scene.layoutHeight): return None for i in range(1, 5): if math.isnan(float(data[i][0])) or math.isnan(float(data[i][1])): return None xyz = (float(data[i][0]), 0, -float(data[i][1])) scene.layoutPoints.append(objs.GeoPoint(scene, None, xyz)) scene.layoutPoints.reverse() scene.genLayoutWallsByPoints(scene.layoutPoints) scene.updateLayoutGeometry() return scene
def data2scene(fp_points, height): # cam-ceiling / cam-floor scale = (height - 1.6) / 1.6 #layout_fp, fp_points = fit_layout(fp, scale=None, max_cor=12) size = 512 ratio = 20/size fp_points = fp_points.astype(float) fp_points[0] -= size/2 fp_points[1] -= size/2 fp_points *= scale fp_points[0] += size/2 fp_points[1] += size/2 fp_points = fp_points.astype(int) scene = objs.Scene() scene.cameraHeight = 1.6 scene.layoutHeight = float(height) scene.layoutPoints = [] for i in range(fp_points.shape[1]): fp_xy = (fp_points[:,i] - size/2) * ratio xyz = (fp_xy[1], 0, fp_xy[0]) scene.layoutPoints.append(objs.GeoPoint(scene, None, xyz)) scene.genLayoutWallsByPoints(scene.layoutPoints) scene.updateLayoutGeometry() return scene
def updateCorners(self): self.corners = [] for gp in self.gPoints: if self.isCeiling: xyz = (gp.xyz[0], self.height, gp.xyz[2]) else: xyz = (gp.xyz[0], -self.height, gp.xyz[2]) corner = objs.GeoPoint(xyz) self.corners.append(corner)
def loadLabelByJson(path, scene): with open(path) as f: jdata = json.load(f) scene.cameraHeight = jdata['cameraHeight'] scene.layoutHeight = jdata['layoutHeight'] pointsDict = jdata['layoutPoints'] pointsList = pointsDict['points'] gPoints = [] for point in pointsList: xyz = tuple(point['xyz']) gPoint = objs.GeoPoint(xyz) gPoints.append(gPoint) scene.layoutPoints = gPoints scene.genLayoutWallsByPoints(scene.layoutPoints) scene.updateLayoutGeometry() walls = scene.layoutWalls if 'layoutObj2ds' in jdata: obj2dsDict = jdata['layoutObj2ds'] obj2dsList = obj2dsDict['obj2ds'] object2ds = [] for obj2d in obj2dsList: gp1 = objs.GeoPoint(tuple(obj2d['points'][0])) gp2 = objs.GeoPoint(tuple(obj2d['points'][1])) wall = walls[int(obj2d['wallIdx'])] object2d = objs.Object2D(scene, [gp1, gp2], wall) object2ds.append(object2d) scene.layoutObject2d = object2ds
def pts2scene(fp_pts, height): camera_h = cf.camera_h scale = (height - camera_h) / camera_h fp_pts = fp_pts.astype(float) fp_pts -= cf.fp_size / 2 fp_pts *= scale fp_pts = fp_pts.astype(int) scene = objs.Scene() scene.cameraHeight = camera_h scene.layoutHeight = float(height) scene.layoutPoints = [] for i in range(fp_pts.shape[1]): fp_xy = fp_pts[:,i] * (cf.fp_meter / cf.fp_size) xyz = (fp_xy[1], 0, fp_xy[0]) scene.layoutPoints.append(objs.GeoPoint(xyz)) scene.genLayoutWallsByPoints(scene.layoutPoints) scene.updateLayoutGeometry() return scene