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)
help='camera roll mounting offset from aircraft') args = parser.parse_args() proj = ProjectMgr.ProjectMgr(args.project) # copy/overlay/update the specified camera config into the existing # 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
local_config = os.path.join(dirname, "camera.json") config = PropertyNode() if args.camera: # seed the camera calibration and distortion coefficients from a # known camera config print('Setting camera config from:', args.camera) props_json.load(args.camera, config) config.setString('name', args.camera) props_json.save(local_config, config) elif os.path.exists(local_config): # load local config file if it exists props_json.load(local_config, config) K_list = [] for i in range(9): K_list.append( config.getFloatEnum('K', i) ) K = np.copy(np.array(K_list)).reshape(3,3) dist = [] for i in range(5): dist.append( config.getFloatEnum("dist_coeffs", i) ) # check for required input files if not os.path.isfile(args.video): print("%s doesn't exist, aborting ..." % args.video) quit() if os.path.isfile(basename + ".srt"): srtname = basename + ".srt" elif os.path.isfile(basename + ".SRT"): srtname = basename + ".SRT" else:
#file = args.movie scale = args.scale skip_frames = args.skip_frames # pathname work abspath = os.path.abspath(args.movie) filename, ext = os.path.splitext(abspath) dirname = os.path.dirname(args.movie) output_csv = filename + ".csv" camera_config = dirname + "/camera.json" # load config file if it exists config = PropertyNode() props_json.load(camera_config, config) cam_yaw = config.getFloatEnum('mount_ypr', 0) cam_pitch = config.getFloatEnum('mount_ypr', 1) cam_roll = config.getFloatEnum('mount_ypr', 2) # setup camera calibration and distortion coefficients if args.select_cam: # set the camera calibration from known preconfigured setups name, K, dist = cam_calib.set_camera_calibration(args.select_cam) config.setString('name', name) config.setFloat("fx", K[0][0]) config.setFloat("fy", K[1][1]) config.setFloat("cu", K[0][2]) config.setFloat("cv", K[1][2]) for i, d in enumerate(dist): config.setFloatEnum("dist_coeffs", i, d) props_json.save(camera_config, config)
# 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(args.yaw_deg, args.pitch_deg, args.roll_deg) # note: dist_coeffs = array[5] = k1, k2, p1, p2, k3