def loadCalibration(dir="calib"): filenames = ("CM1.txt", "CM2.txt", "D1.txt", "D2.txt", "R.txt", "T.txt", "E.txt", "F.txt") for fn in ["{0}/{1}".format(dir, f) for f in filenames]: errors.checkexists(fn) CM1 = cv.Load("{0}/{1}".format(dir, filenames[0])) CM2 = cv.Load("{0}/{1}".format(dir, filenames[1])) D1 = cv.Load("{0}/{1}".format(dir, filenames[2])) D2 = cv.Load("{0}/{1}".format(dir, filenames[3])) R = cv.Load("{0}/{1}".format(dir, filenames[4])) T = cv.Load("{0}/{1}".format(dir, filenames[5])) E = cv.Load("{0}/{1}".format(dir, filenames[6])) F = cv.Load("{0}/{1}".format(dir, filenames[7])) print "Calibration files loaded from dir '{0}'.".format(dir) return (CM1, CM2, D1, D2, R, T, E, F)
def saveCalibration(cal, cdir="calib"): filenames = ("CM1.txt", "CM2.txt", "D1.txt", "D2.txt", "R.txt", "T.txt", "E.txt", "F.txt") errors.checkexists(cdir, True) assert len(filenames) == 8 (CM1, CM2, D1, D2, R, T, E, F) = cal cv.Save("{0}/{1}".format(cdir, filenames[0]), CM1) cv.Save("{0}/{1}".format(cdir, filenames[1]), CM2) cv.Save("{0}/{1}".format(cdir, filenames[2]), D1) cv.Save("{0}/{1}".format(cdir, filenames[3]), D2) cv.Save("{0}/{1}".format(cdir, filenames[4]), R) cv.Save("{0}/{1}".format(cdir, filenames[5]), T) cv.Save("{0}/{1}".format(cdir, filenames[6]), E) cv.Save("{0}/{1}".format(cdir, filenames[7]), F) print "Calibration parameters written to directory '{0}'.".format(cdir)
def loadRectif(dir="rect"): filenames = ("R1.txt", "R2.txt", "P1.txt", "P2.txt", "Q.txt", "ROI.txt") for fn in ["{0}/{1}".format(dir, f) for f in filenames]: errors.checkexists(fn) R1 = cv.Load("{0}/{1}".format(dir, filenames[0])) R2 = cv.Load("{0}/{1}".format(dir, filenames[1])) P1 = cv.Load("{0}/{1}".format(dir, filenames[2])) P2 = cv.Load("{0}/{1}".format(dir, filenames[3])) Q = cv.Load("{0}/{1}".format(dir, filenames[4])) f = open("{0}/{1}".format(dir, filenames[5])) roi = tuple([int(x) for x in f.readline().split()]) print "Rectification parameters loaded from dir '{0}'.".format(dir) return (R1, R2, P1, P2, Q, roi)
def saveRectif(rect, dir="rect"): filenames = ("R1.txt", "R2.txt", "P1.txt", "P2.txt", "Q.txt", "ROI.txt") errors.checkexists(dir, True) (R1, R2, P1, P2, Q, roi) = rect cv.Save("{0}/{1}".format(dir, filenames[0]), R1) cv.Save("{0}/{1}".format(dir, filenames[1]), R2) cv.Save("{0}/{1}".format(dir, filenames[2]), P1) cv.Save("{0}/{1}".format(dir, filenames[3]), P1) cv.Save("{0}/{1}".format(dir, filenames[4]), Q) f = open("{0}/{1}".format(dir, filenames[5]), 'w') f.write("{0}\n".format(' '.join([str(c) for c in roi]))) f.close() print "Rectification parameters written to directory '{0}'.".format(dir)
def getChessboards(n, fname="chessboards.txt"): """ Load chessboard point coordinates from file. n - number of boards to load from file fname - filename of file to load coordinates from """ p1 = cv.CreateMat(1, n * COLS * ROWS, cv.CV_64FC2) p2 = cv.CreateMat(1, n * COLS * ROWS, cv.CV_64FC2) errors.checkexists(fname) f = open(fname, 'r') lr = 0 for j in range(n): for i in range(COLS * ROWS): c1 = f.readline() c2 = f.readline() c1 = c1.split() c2 = c2.split() cv.Set1D(p1, j * COLS * ROWS + i, cv.Scalar(float(c1[0]), float(c1[1]))) cv.Set1D(p2, j * COLS * ROWS + i, cv.Scalar(float(c2[0]), float(c2[1]))) f.readline() return (p1, p2)