def test_seek_by_device_time(playback: PyK4APlayback): # TODO fetch capture/data and validate time playback.open() playback.seek(1, origin=SeekOrigin.DEVICE_TIME ) # TODO add correct timestamp from datablock here capture = playback.get_next_capture() assert capture.color is not None
def test_get_next_capture(playback: PyK4APlayback): playback.open() capture = playback.get_next_capture() assert capture is not None assert capture.depth is not None assert capture.color is not None assert capture._calibration is not None # Issue #81
def test_get_previouse_capture(playback: PyK4APlayback): playback.open() playback.seek(0, origin=SeekOrigin.END) capture = playback.get_previouse_capture() assert capture is not None assert capture.depth is not None assert capture.color is not None assert capture._calibration is not None # Issue #81
def test_get_next_capture(playback: PyK4APlayback): playback.open() capture = playback.get_next_capture() assert capture is not None assert capture.depth is not None assert capture.color is not None assert capture.depth_timestamp_usec == 800222 assert capture.color_timestamp_usec == 800222 assert capture.ir_timestamp_usec == 800222 assert capture._calibration is not None # Issue #81
def test_seek_from_start(playback: PyK4APlayback): # TODO fetch capture/data and validate time playback.open() playback.get_next_capture() playback.seek(playback.configuration["start_timestamp_offset_usec"], origin=SeekOrigin.BEGIN) capture = playback.get_next_capture() assert capture.color is not None with pytest.raises(EOFError): playback.get_previouse_capture()
def playback(recording_good_file: str) -> Iterator[PyK4APlayback]: playback = PyK4APlayback(path=recording_good_file) yield playback # autoclose try: playback.close() except K4AException: pass
def test_seek_from_end(playback: PyK4APlayback): # TODO fetch capture/data and validate time playback.open() playback.seek(0, origin=SeekOrigin.END) capture = playback.get_previouse_capture() assert capture.color is not None with pytest.raises(EOFError): playback.get_next_capture()
def play(playback: PyK4APlayback): while True: try: capture = playback.get_next_capture() if capture.color is not None: cv2.imshow( "Color", convert_to_bgra_if_required( playback.configuration["color_format"], capture.color)) if capture.depth is not None: cv2.imshow("Depth", colorize(capture.depth, (None, 5000))) key = cv2.waitKey(10) if key != -1: break except EOFError: break cv2.destroyAllWindows()
def main() -> None: parser = ArgumentParser(description="pyk4a player") parser.add_argument("--seek", type=float, help="Seek file to specified offset in seconds", default=0.0) parser.add_argument("FILE", type=str, help="Path to MKV file written by k4arecorder") args = parser.parse_args() filename: str = args.FILE offset: float = args.seek playback = PyK4APlayback(filename) playback.open() info(playback) if offset != 0.0: playback.seek(int(offset * 1000000)) play(playback) playback.close()
def test_good_file(playback: PyK4APlayback): playback.open() assert playback.length == 1234
def test_double_open(playback: PyK4APlayback): playback.open() with pytest.raises(K4AException, match=r"Playback already opened"): playback.open()
def test_not_existing_path(recording_not_exists_file: str): playback = PyK4APlayback(path=recording_not_exists_file) with pytest.raises(K4AException): playback.open()
def test_path_argument(): playback = PyK4APlayback(path=Path("some.mkv")) assert playback.path == Path("some.mkv") playback = PyK4APlayback(path="some.mkv") assert playback.path == Path("some.mkv")
def test_seek_eof(playback: PyK4APlayback): playback.open() with pytest.raises(EOFError): playback.seek(9999)
def test_not_existing_path(): playback = PyK4APlayback(path="/some/not-exists.file") with pytest.raises(K4AException): playback.open()
def test_good_file(playback: PyK4APlayback): playback.open() assert playback.calibration
def test_validate_if_record_opened(playback: PyK4APlayback): with pytest.raises(K4AException, match="Playback not opened."): playback.seek(1)
def test_readness(playback: PyK4APlayback): playback.open() calibration = playback.calibration assert calibration
def test_readness(playback: PyK4APlayback): playback.open() assert playback.configuration == RECORD_CONFIGURATION
def test_correct_value(playback: PyK4APlayback): playback.open() assert playback.calibration_raw == RECORD_CALIBRATION_JSON
def test_correct_value(playback: PyK4APlayback): playback.open() assert playback.length == RECORD_LENGTH
def test_bad_file(playback_bad: PyK4APlayback): playback_bad.open() with pytest.raises(K4AException): assert playback_bad.calibration_raw
def test_bad_file(playback_bad: PyK4APlayback): playback_bad.open() with pytest.raises(K4AException): playback_bad.seek(10)
def start(useLiveCamera): global k4a if useLiveCamera == False: k4a = PyK4APlayback("C:\data\outSess1.mkv") k4a.open() else: k4a = PyK4A( Config( color_resolution=pyk4a.ColorResolution.RES_1080P, depth_mode=pyk4a.DepthMode.NFOV_UNBINNED, synchronized_images_only=True, )) k4a.start() cal = json.loads(k4a.calibration_raw) depthCal = cal["CalibrationInformation"]["Cameras"][0]["Intrinsics"][ "ModelParameters"] colorCal = cal["CalibrationInformation"]["Cameras"][1]["Intrinsics"][ "ModelParameters"] # https://github.com/microsoft/Azure-Kinect-Sensor-SDK/blob/61951daac782234f4f28322c0904ba1c4702d0ba/src/transformation/mode_specific_calibration.c # from microsfots way of doing things, you have to do the maths here, rememberedding to -0.5f from cx, cy at the end # this should be set from the depth mode type, as the offsets are different, see source code in link #K = np.eye(4, dtype='float32') K = glm.mat4(1.0) K[0, 0] = depthCal[2] * cal["CalibrationInformation"]["Cameras"][0][ "SensorWidth"] # fx K[1, 1] = depthCal[3] * cal["CalibrationInformation"]["Cameras"][0][ "SensorHeight"] # fy K[2, 0] = (depthCal[0] * cal["CalibrationInformation"]["Cameras"][0]["SensorWidth"] ) - 192.0 - 0.5 # cx K[2, 1] = (depthCal[1] * cal["CalibrationInformation"]["Cameras"][0]["SensorHeight"] ) - 180.0 - 0.5 # cy invK = glm.inverse(K) colK = glm.mat4(1.0) colK[0, 0] = colorCal[2] * 1920.0 # fx colK[1, 1] = colorCal[ 3] * 1440.0 # fy # why 1440, since we are 1080p? check the link, the umbers are there, im sure they make sense ... colK[2, 0] = (colorCal[0] * 1920.0) - 0 - 0.5 # cx colK[2, 1] = (colorCal[1] * 1440.0) - 180.0 - 0.5 # cy d2c = glm.mat4( cal["CalibrationInformation"]["Cameras"][1]["Rt"]["Rotation"][0], cal["CalibrationInformation"]["Cameras"][1]["Rt"]["Rotation"][3], cal["CalibrationInformation"]["Cameras"][1]["Rt"]["Rotation"][6], 0, cal["CalibrationInformation"]["Cameras"][1]["Rt"]["Rotation"][1], cal["CalibrationInformation"]["Cameras"][1]["Rt"]["Rotation"][4], cal["CalibrationInformation"]["Cameras"][1]["Rt"]["Rotation"][7], 0, cal["CalibrationInformation"]["Cameras"][1]["Rt"]["Rotation"][2], cal["CalibrationInformation"]["Cameras"][1]["Rt"]["Rotation"][5], cal["CalibrationInformation"]["Cameras"][1]["Rt"]["Rotation"][8], 0, cal["CalibrationInformation"]["Cameras"][1]["Rt"]["Translation"][0], cal["CalibrationInformation"]["Cameras"][1]["Rt"]["Translation"][1], cal["CalibrationInformation"]["Cameras"][1]["Rt"]["Translation"][2], 1) c2d = glm.inverse(d2c) return d2c, c2d, K, invK, colK
def test_good_file(playback: PyK4APlayback): playback.open() playback.seek(10)
def playback(recording_path: Path) -> PyK4APlayback: return PyK4APlayback(path=recording_path)
def capture(playback: PyK4APlayback) -> PyK4ACapture: playback.open() return playback.get_next_capture()