예제 #1
0
def main(camindex = 0, capture_width = 800, capture_height = 600, chessboard_width = 9, chessboard_height = 6, planemode = False, gridsize = 0.029, calibrationFile = "default"):
    global save_location

    if planemode:
        mode = 7
    else:
        mode = 0

    dims = (chessboard_width, chessboard_height)

    cam = Camera(camindex, prop_set = { "width": capture_width, "height": capture_height })
    d = Display((capture_width, capture_height))

    save_location = "" #change this if you want to save your calibration images

    calibration_set = [] #calibration images
    fc_set = []

    introMessage()


    while not d.isDone():
        time.sleep(0.01)
        i = cam.getImage().flipHorizontal()
        cb = i.findChessboard(dims, subpixel = False)


        if cb:
            cb = cb[0]
        elif mode != 6:
            showText(i, "Put a chessboard in the green outline")

        if mode == 0:  #10 pictures, chessboard filling 80% of the view space
            findLargeFlat(cb, i, calibration_set, dims)
            if (len(calibration_set) == 10):
                mode = 1
        elif mode == 1:  #5 pictures, chessboard filling 60% of screen, at 45 deg horiz
            findHorizTilted(cb, i, calibration_set, dims)
            if (len(calibration_set) == 15):
                mode = 2
        elif mode == 2:  #5 pictures, chessboard filling 60% of screen, at 45 deg vert
            findVertTilted(cb, i, calibration_set, dims)
            if (len(calibration_set) == 20):
                mode = 3
        elif mode == 3:  #5 pictures, chessboard filling 40% of screen, corners at 45
            findCornerTilted(cb, i, calibration_set, dims)
            if (len(calibration_set) == 25):
                mode = 4
        elif mode == 4:  #10 pictures, chessboard filling 12% - 25% of view space
            findSmallFlat(cb, i, calibration_set, dims)
            if (len(calibration_set) == 35):
                mode = 5
        elif mode == 5:
            cam.calibrate(calibration_set, gridsize, dims)
            cam.saveCalibration(calibrationFile)
            mode = 6
        elif mode == 6:
            showText(i,  "Saved calibration to " + calibrationFile)
        elif mode == 7:
            findPlane(cb, i, calibration_set, dims)
            if (len(calibration_set) == 25):
                mode = 5

        if cb:
            cb.draw()

        i.save(d)