Ejemplo n.º 1
0
def dewarp(imagedir):
    # Loading from json file
    C = CameraParams.fromfile(os.path.join(imagedir, "params.json"))
    K = C.K
    D = C.D
    print("Loaded camera parameters from " + os.path.join(imagedir, "params.json"))

    for f in file_list(imagedir, ['jpg', 'jpeg', 'png']):
        print(f)
        colour = cv2.imread(f)
        grey = cv2.cvtColor(colour, cv2.COLOR_BGR2GRAY)

        h, w = grey.shape[:2]
        newcameramtx, roi=cv2.getOptimalNewCameraMatrix(K, D, (w,h), 1, (w,h))
        mapx, mapy = cv2.initUndistortRectifyMap(K, D, None, newcameramtx, (w,h), 5)
        dewarped = cv2.remap(grey, mapx, mapy, cv2.INTER_LINEAR)

        x, y, w, h = roi
        dewarped = dewarped[y:y+h, x:x+w]
        grey = cv2.resize(grey, (0,0), fx=0.5, fy=0.5) 
        dewarped = cv2.resize(dewarped, (0,0), fx=0.5, fy=0.5) 

        cv2.imshow("Original", grey )
        cv2.imshow("Dewarped", dewarped)
        cv2.waitKey(-1)
Ejemplo n.º 2
0
def dewarp(imagedir):
    # Loading from json file
    C = CameraParams.fromfile(os.path.join(imagedir, "params.json"))
    K = C.K
    D = C.D
    print("Loaded camera parameters from " +
          os.path.join(imagedir, "params.json"))

    for f in file_list(imagedir, ['jpg', 'jpeg', 'png']):
        print(f)
        colour = cv2.imread(f)
        grey = cv2.cvtColor(colour, cv2.COLOR_BGR2GRAY)

        h, w = grey.shape[:2]
        newcameramtx, roi = cv2.getOptimalNewCameraMatrix(
            K, D, (w, h), 1, (w, h))
        mapx, mapy = cv2.initUndistortRectifyMap(K, D, None, newcameramtx,
                                                 (w, h), 5)
        dewarped = cv2.remap(grey, mapx, mapy, cv2.INTER_LINEAR)

        x, y, w, h = roi
        dewarped = dewarped[y:y + h, x:x + w]
        grey = cv2.resize(grey, (0, 0), fx=0.5, fy=0.5)
        dewarped = cv2.resize(dewarped, (0, 0), fx=0.5, fy=0.5)

        cv2.imshow("Original", grey)
        cv2.imshow("Dewarped", dewarped)
        cv2.waitKey(-1)
Ejemplo n.º 3
0
def test_do_calibrate():
    dirry = os.path.join('.', 'cuav', 'data', 'ChameleonArecort')
    outfile = os.path.join('.', 'cuav', 'data', 'ChameleonArecort', 'paramsout.json')
    calibrate.calibrate(dirry, 10, 7)
    assert os.path.isfile(outfile)
    C = CameraParams.fromfile(outfile)
    assert C is not None
    os.remove(outfile)
Ejemplo n.º 4
0
def test_cam_params_txt():
    C = CameraParams(lens=4.0, sensorwidth=5.0, xresolution=1280, yresolution=960)
    C.setParams([[1, 2, 3], [4, 5, 6]], [0, 6, 7, 8])
    C.save('foo.txt')
    C2 = CameraParams.fromfile('foo.txt')
    assert str(C) == str(C2)
    assert numpy.array_equal(C.K, C2.K)
    assert numpy.array_equal(C.D, C2.D)
    os.remove('foo.txt')
Ejemplo n.º 5
0
def test_cam_params_txt():
    C = CameraParams(lens=4.0,
                     sensorwidth=5.0,
                     xresolution=1280,
                     yresolution=960)
    C.setParams([[1, 2, 3], [4, 5, 6]], [0, 6, 7, 8])
    C.save('foo.txt')
    C2 = CameraParams.fromfile('foo.txt')
    assert str(C) == str(C2)
    assert numpy.array_equal(C.K, C2.K)
    assert numpy.array_equal(C.D, C2.D)
    os.remove('foo.txt')