Пример #1
0
def get_camera_node(serial):
    root = NxLibItem()  # References the root
    cameras = root[ITM_CAMERAS][
        ITM_BY_SERIAL_NO]  # References the cameras subnode
    for i in range(cameras.count()):
        found = cameras[i].name() == serial
        if found:
            return cameras[i]
Пример #2
0
def main(args):
    parser = argparse.ArgumentParser()
    parser.add_argument(
        "-s",
        "--serial",
        type=str,
        required=True,
        help="The serial of the stereo camera, you want to open")
    args = parser.parse_args(args)

    camera_serial = args.serial

    try:
        # Waits for the cameras to be initialized
        api.initialize()

        # Opens the camera with the serial stored in camera_serial variable
        cmd = NxLibCommand(CMD_OPEN)
        cmd.parameters()[ITM_CAMERAS] = camera_serial
        cmd.execute()

        # Captures with the previous openend camera
        capture = NxLibCommand(CMD_CAPTURE)
        capture.parameters()[ITM_CAMERAS] = camera_serial
        capture.execute()

        # Rectify the the captures raw images
        rectification = NxLibCommand(CMD_RECTIFY_IMAGES)
        rectification.execute()

        # Compute the disparity map
        disparity_map = NxLibCommand(CMD_COMPUTE_DISPARITY_MAP)
        disparity_map.execute()

        # Compute the point map from the disparitu map
        point_map = NxLibCommand(CMD_COMPUTE_POINT_MAP)
        point_map.execute()
        points = NxLibItem()[ITM_CAMERAS][camera_serial][ITM_IMAGES][
            ITM_POINT_MAP].get_binary_data()

        average_z = compute_average_z(points)
        print("The z-Average of this point cloud is {}".format(average_z))

        # Closes all open cameras
        NxLibCommand(CMD_CLOSE).execute()

    except NxLibException as e:
        print("An NxLibException occured: Error Text: {}".format(
            e.get_error_text()))
    except:
        print("Something bad happenend, that has been out of our control.")
Пример #3
0
def main():
    try:
        # Waits for the cameras to be initialized
        api.initialize()

        # References to the root of the nxLib tree
        root = NxLibItem()

        # Reference to the serials subnode of all cameras
        cameras = root[ITM_CAMERAS][ITM_BY_SERIAL_NO]

        # Loop over the array
        for i in range(cameras.count()):
            if cameras[i][ITM_STATUS][ITM_OPEN].exists():
                is_available = cameras[i][ITM_STATUS][ITM_AVAILABLE].as_bool()
                serial = cameras[i].name()
                print("Camera with serial {} is currently {}".format(serial, "available" if is_available else "closed"))

    except NxLibException as e:
        print("An NxLibException occured: Error Text: {}".format(e.get_error_text()))
    except:
        print("Something bad happenend, that has been out of our control.")
Пример #4
0
def test_capture_pipeline():
    api.initialize()

    camera_serial = "test_cam"

    cmd = NxLibCommand(CMD_CREATE_CAMERA)
    cmd.parameters()[ITM_SERIAL_NUMBER] = camera_serial
    cmd.parameters()[ITM_FOLDER_PATH] = test_camera
    cmd.execute()

    cmd = NxLibCommand(CMD_OPEN)
    cmd.parameters()[ITM_CAMERAS] = camera_serial
    cmd.execute()

    capture = NxLibCommand(CMD_CAPTURE)
    capture.parameters()[ITM_CAMERAS] = camera_serial
    capture.execute()

    img_left = NxLibItem()[ITM_CAMERAS][camera_serial][ITM_IMAGES][ITM_RAW][ITM_LEFT].get_binary_data()
    _test_binary_data(img_left, 1024, 1280, 1, numpy.uint8)

    img_right = NxLibItem()[ITM_CAMERAS][camera_serial][ITM_IMAGES][ITM_RAW][ITM_RIGHT].get_binary_data()
    _test_binary_data(img_right, 1024, 1280, 1, numpy.uint8)

    recitfication = NxLibCommand(CMD_RECTIFY_IMAGES)
    recitfication.execute()

    img_left_rectified = NxLibItem()[ITM_CAMERAS][camera_serial][ITM_IMAGES][ITM_RECTIFIED][ITM_LEFT].get_binary_data()
    _test_binary_data(img_left_rectified, 1024, 1280, 1, numpy.uint8)

    img_right_rectified = NxLibItem(
    )[ITM_CAMERAS][camera_serial][ITM_IMAGES][ITM_RECTIFIED][ITM_RIGHT].get_binary_data()
    _test_binary_data(img_right_rectified, 1024, 1280, 1, numpy.uint8)

    disparity_map = NxLibCommand(CMD_COMPUTE_DISPARITY_MAP)
    disparity_map.execute()
    disp_map = NxLibItem()[ITM_CAMERAS][camera_serial][ITM_IMAGES][ITM_DISPARITY_MAP].get_binary_data()
    _test_binary_data(disp_map, 1024, 1280, 1, numpy.int16)

    point_map = NxLibCommand(CMD_COMPUTE_POINT_MAP)
    point_map.execute()
    points = NxLibItem()[ITM_CAMERAS][camera_serial][ITM_IMAGES][ITM_POINT_MAP].get_binary_data()
    _test_binary_data(points, 1024, 1280, 3, numpy.float32)
Пример #5
0
def test_is_not_array():
    assert NxLibItem()[ITM_DEFAULT_PARAMETERS][ITM_RENDER_VIEW].is_array() == False
Пример #6
0
def test_is_false():
    assert NxLibItem()[ITM_DEFAULT_PARAMETERS][ITM_COMPUTE_DISPARITY_MAP][ITM_STATIC_BUFFERS].is_bool() == False
Пример #7
0
def test_is_number():
    assert NxLibItem()[ITM_CALIBRATION][ITM_PATTERN][ITM_GRID_SPACING].is_number() == True
Пример #8
0
def test_as_json():
    NxLibItem().as_json()
Пример #9
0
def test_set_and_return():
    NxLibItem()["test"]["item"] = 42
    assert NxLibItem()["test"]["item"].is_number()

    value = NxLibItem()["test"]["item"].as_int()
    assert value == 42
Пример #10
0
def test_exists():
    assert NxLibItem()[ITM_DEFAULT_PARAMETERS][ITM_RENDER_VIEW].exists() == True
Пример #11
0
def test_doesnt_exist():
    assert NxLibItem()[ITM_DEFAULT_PARAMETERS]["Blubb"].exists() == False
Пример #12
0
def test_is_string():
    assert NxLibItem()[ITM_CALIBRATION][ITM_PATTERN][ITM_TYPE].is_string() == True
Пример #13
0
def test_type():
    assert NxLibItem()[ITM_DEFAULT_PARAMETERS][ITM_RENDER_VIEW][ITM_SIZE].type() == 5
Пример #14
0
def test_is_true():
    assert NxLibItem()[ITM_DEFAULT_PARAMETERS][ITM_RENDER_VIEW][ITM_SHOW_CAMERAS].is_bool() == True
Пример #15
0
def test_is_array():
    assert NxLibItem()[ITM_DEFAULT_PARAMETERS][ITM_RENDER_VIEW][ITM_SIZE].is_array() == True
Пример #16
0
def test_is_not_object():
    assert NxLibItem()[ITM_DEFAULT_PARAMETERS][ITM_RENDER_VIEW][ITM_SHOW_CAMERAS].is_object() == False
Пример #17
0
def test_is_object():
    assert NxLibItem()[ITM_CALIBRATION][ITM_PATTERN].is_object() == True
Пример #18
0
def test_is_null():
    assert NxLibItem()[ITM_CALIBRATION][ITM_ASSEMBLY_CALIBRATION].is_null() == True