Example #1
0
 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
Example #2
0
 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
Example #3
0
 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
Example #4
0
 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
Example #5
0
 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()
Example #6
0
def playback(recording_good_file: str) -> Iterator[PyK4APlayback]:
    playback = PyK4APlayback(path=recording_good_file)
    yield playback
    # autoclose
    try:
        playback.close()
    except K4AException:
        pass
Example #7
0
 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()
Example #8
0
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()
Example #9
0
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()
Example #10
0
 def test_good_file(playback: PyK4APlayback):
     playback.open()
     assert playback.length == 1234
Example #11
0
 def test_double_open(playback: PyK4APlayback):
     playback.open()
     with pytest.raises(K4AException, match=r"Playback already opened"):
         playback.open()
Example #12
0
 def test_not_existing_path(recording_not_exists_file: str):
     playback = PyK4APlayback(path=recording_not_exists_file)
     with pytest.raises(K4AException):
         playback.open()
Example #13
0
    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")
Example #14
0
 def test_seek_eof(playback: PyK4APlayback):
     playback.open()
     with pytest.raises(EOFError):
         playback.seek(9999)
Example #15
0
 def test_not_existing_path():
     playback = PyK4APlayback(path="/some/not-exists.file")
     with pytest.raises(K4AException):
         playback.open()
Example #16
0
 def test_good_file(playback: PyK4APlayback):
     playback.open()
     assert playback.calibration
Example #17
0
 def test_validate_if_record_opened(playback: PyK4APlayback):
     with pytest.raises(K4AException, match="Playback not opened."):
         playback.seek(1)
Example #18
0
 def test_readness(playback: PyK4APlayback):
     playback.open()
     calibration = playback.calibration
     assert calibration
Example #19
0
 def test_readness(playback: PyK4APlayback):
     playback.open()
     assert playback.configuration == RECORD_CONFIGURATION
Example #20
0
 def test_correct_value(playback: PyK4APlayback):
     playback.open()
     assert playback.calibration_raw == RECORD_CALIBRATION_JSON
Example #21
0
 def test_correct_value(playback: PyK4APlayback):
     playback.open()
     assert playback.length == RECORD_LENGTH
Example #22
0
 def test_bad_file(playback_bad: PyK4APlayback):
     playback_bad.open()
     with pytest.raises(K4AException):
         assert playback_bad.calibration_raw
Example #23
0
 def test_bad_file(playback_bad: PyK4APlayback):
     playback_bad.open()
     with pytest.raises(K4AException):
         playback_bad.seek(10)
Example #24
0
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
Example #25
0
 def test_good_file(playback: PyK4APlayback):
     playback.open()
     playback.seek(10)
Example #26
0
def playback(recording_path: Path) -> PyK4APlayback:
    return PyK4APlayback(path=recording_path)
Example #27
0
def capture(playback: PyK4APlayback) -> PyK4ACapture:
    playback.open()
    return playback.get_next_capture()