def set_camera(project_dir, camera, yaw_deg=0.0, pitch_deg=-90.0, roll_deg=0.0): proj = ProjectMgr.ProjectMgr(project_dir) if camera: # specified on command line camera_file = camera else: # auto detect camera from image meta data camera, make, model, lens_model = proj.detect_camera() camera_file = os.path.join("..", "cameras", camera + ".json") print("Camera:", camera_file) # copy/overlay/update the specified camera config into the existing # project configuration cam_node = getNode('/config/camera', True) tmp_node = PropertyNode() if props_json.load(camera_file, tmp_node): for child in tmp_node.getChildren(expand=False): if tmp_node.isEnum(child): # print(child, tmp_node.getLen(child)) for i in range(tmp_node.getLen(child)): cam_node.setFloatEnum(child, i, tmp_node.getFloatEnum(child, i)) else: # print(child, type(tmp_node.__dict__[child])) child_type = type(tmp_node.__dict__[child]) if child_type is float: cam_node.setFloat(child, tmp_node.getFloat(child)) elif child_type is int: cam_node.setInt(child, tmp_node.getInt(child)) elif child_type is str: cam_node.setString(child, tmp_node.getString(child)) else: print('Unknown child type:', child, child_type) proj.cam.set_mount_params(yaw_deg, pitch_deg, roll_deg) # note: dist_coeffs = array[5] = k1, k2, p1, p2, k3 # ... and save proj.save() else: # failed to load camera config file if not camera: print("Camera autodetection failed.") print( "Consider running the new camera script to create a camera config" ) print("and then try running this script again.") else: print("Provided camera config not found:", camera)
# project configuration cam_node = getNode('/config/camera', True) tmp_node = PropertyNode() props_json.load(args.camera, tmp_node) for child in tmp_node.getChildren(expand=False): if tmp_node.isEnum(child): # print(child, tmp_node.getLen(child)) for i in range(tmp_node.getLen(child)): cam_node.setFloatEnum(child, i, tmp_node.getFloatEnum(child, i)) else: # print(child, type(tmp_node.__dict__[child])) child_type = type(tmp_node.__dict__[child]) if child_type is float: cam_node.setFloat(child, tmp_node.getFloat(child)) elif child_type is int: cam_node.setInt(child, tmp_node.getInt(child)) elif child_type is str: cam_node.setString(child, tmp_node.getString(child)) else: print('Unknown child type:', child, child_type) proj.cam.set_mount_params(args.yaw_deg, args.pitch_deg, args.roll_deg) # note: dist_coeffs = array[5] = k1, k2, p1, p2, k3 # the following counts as cruft, but saving it for now until I can # migrate these# over to official camera database files. # if args.sentera_3M: # # need confirmation on these numbers because they don't all exactly jive # # 1 pixel = 1.67 micrometer