Ejemplo n.º 1
0
def ipm(imgFile, cfgFile):
    image = cv2.cvtColor(cv2.imread(imgFile), cv2.COLOR_BGR2RGB)
    TARGET_H, TARGET_W = 1024, 1024
    # TARGET_H, TARGET_W = 800, 800

    plane = Plane(20, -25, 0, 0, 0, 0, TARGET_H, TARGET_W, 0.035)

    extrinsic, intrinsic = load_camera_params(cfgFile)

    warped1 = ipm_from_parameters(image, plane.xyz, intrinsic, extrinsic,
                                  TARGET_H, TARGET_W)

    return warped1
Ejemplo n.º 2
0
def test_perspective():
    extrinsic, intrinsic = load_camera_params('camera.json')
    P = intrinsic @ extrinsic
    plane = Plane(
        0,
        -1,
        0,  # x, y, z
        0,
        0,
        0,  # roll, pitch, yaw
        3,
        3,
        2)  # col, row, scale

    print(perspective(plane.xyz, P, 3, 3))
Ejemplo n.º 3
0
def ipm_from_opencv(image, source_points, target_points):
    # Compute projection matrix
    M = cv2.getPerspectiveTransform(source_points, target_points)
    # Warp the image
    warped = cv2.warpPerspective(image, M, (TARGET_W, TARGET_H), flags=cv2.INTER_LINEAR, borderMode=cv2.BORDER_CONSTANT,
                                 borderValue=0)
    return warped

if __name__ == '__main__':
    ################
    # Derived method
    ################
    # Define the plane on the region of interest (road)
    plane = Plane(0, -25, 0, 0, 0, 0, TARGET_H, TARGET_W, 0.1)
    # Retrieve camera parameters
    extrinsic, intrinsic = load_camera_params('camera.json')
    # Apply perspective transformation
    warped1 = ipm_from_parameters(image, plane.xyz, intrinsic, extrinsic)

    ################
    # OpenCV
    ################
    # Vertices coordinates in the source image
    s = np.array([[830, 598],
                  [868, 568],
                  [1285, 598],
                  [1248, 567]], dtype=np.float32)

    # Vertices coordinates in the destination image
    t = np.array([[177, 231],
                  [213, 231],
Ejemplo n.º 4
0
    return file_name


if __name__ == '__main__':

    parser = argparse.ArgumentParser(description='Shadow detection')
    parser.add_argument("--data_path", "-i", type=str)
    parser.add_argument("--pin_num", type=int, default=5)

    ARGS = parser.parse_args()

    o_path = os.path.join(ARGS.data_path, "tmp")
    if not os.path.exists(o_path):
        os.makedirs(o_path)

    camera_matrix, camera_dist = utils.load_camera_params(ARGS.data_path)

    img_paths = glob.glob(os.path.join(ARGS.data_path, "*.png"))
    img_paths = sorted(img_paths)
    img_paths = np.array(img_paths, dtype=str)
    imgs = [cv2.imread(path)[:, :, ::-1] for path in img_paths]
    imgs = [cv2.undistort(i, camera_matrix, camera_dist) for i in imgs]

    file_names = [__file_name(path) for path in img_paths]
    marker_coordinates_paths = [
        os.path.join(ARGS.data_path, "{}_marker_coordinates.npz".format(path))
        for path in file_names
    ]
    marker_coordinates = [
        np.load(path)["marker_coordinates"]
        for path in marker_coordinates_paths
Ejemplo n.º 5
0
def getImageFiles(rootDir):
    imgFiles = os.listdir(rootDir)
    imgFiles = [os.path.join(rootDir, img) for img in imgFiles]

    return imgFiles


if __name__ == '__main__':
    rootDir = argv[1]
    cfgFile = argv[2]

    imgFiles = getImageFiles(rootDir)

    TARGET_H, TARGET_W = 1024, 1024
    extrinsic, intrinsic = load_camera_params(cfgFile)
    plane = Plane(20, -25, 0, 0, 0, 0, TARGET_H, TARGET_W, 0.035)

    i = 1
    for imgFile in tqdm(imgFiles, total=len(imgFiles)):
        image = cv2.cvtColor(cv2.imread(imgFile), cv2.COLOR_BGR2RGB)

        warped = ipm_from_parameters(image, plane.xyz, intrinsic, extrinsic)

        cv2.imwrite(imgFile, cv2.cvtColor(warped, cv2.COLOR_BGR2RGB))

        # outFile = os.path.join(rootDir, str(i) + ".png")
        # cv2.imwrite(outFile, cv2.cvtColor(warped, cv2.COLOR_BGR2RGB))
        # i += 1

        # fig, ax = plt.subplots(1, 2)