예제 #1
0
class casoCalibExtr:
    def __init__(self, fullData, intrCalibResults, case, stdPix, allDelta,
                 nCores, nTune, nTuneInter, tuneBool, tune_thr, tallyBool,
                 convChecksBool, rndSeedBool, scaNdim, scaAl, nDraws, nChains,
                 indexSave, pathFiles):
        self.case = case
        self.nCores = nCores
        self.nTune = nTune
        self.nTuneInter = nTuneInter
        self.tuneBool = tuneBool
        self.tune_thr = tune_thr
        self.tallyBool = tallyBool
        self.convChecksBool = convChecksBool
        self.rndSeedBool = rndSeedBool
        self.scaNdim = scaNdim
        self.scaAl = scaAl
        self.nDraws = nDraws
        self.nChains = nChains
        self.indexSave = indexSave
        self.pathFiles = pathFiles
        self.allDelta = allDelta

        self.camera = fullData.Synt.Intr.camera
        self.model = fullData.Synt.Intr.model
        self.imgSize = fullData.Synt.Intr.s
        Ns = [2, 3]
        Xint = intrCalibResults['mean'][:3]
        self.cameraMatrix, self.distCoeffs = bl.flat2int(Xint, Ns, self.model)

        caseData = extractCaseData(exCase)
        self.imagePoints = caseData[0]
        self.xi, self.yi = self.imagePoints.T
        self.objpoints = caseData[1]
        self.rVecsT = caseData[2]
        self.tVecsT = caseData[3]
        self.xAllT = np.concatenate([self.rVecsT, self.tVecsT])
        self.nPt = self.objpoints.shape[0]
        self.nFree = 6
        self.observedNormed = np.zeros((self.nPt * 2))

        self.Crt = False  # no RT error
        self.Cf = np.zeros((4, 4))
        self.Cf[2:, 2:] = intrCalibResults['cov'][:2, :2]
        self.Ck = intrCalibResults['cov'][2, 2]
        self.Cfk = np.zeros(4)
        self.Cfk[2:] = intrCalibResults['cov'][:2, 2]
        self.Ci = np.array([stdPix**2 * np.eye(2)] * self.nPt)

        # tau de 1/5 pra la ventana movil
        self.weiEsp = np.exp(- np.arange(nDraws) * 5 / nDraws)[::-1]
        self.weiEsp /= np.sum(self.weiEsp)
예제 #2
0
    def __init__(self, fullData, intrCalibResults, case, stdPix, allDelta,
                 nCores, nTune, nTuneInter, tuneBool, tune_thr, tallyBool,
                 convChecksBool, rndSeedBool, scaNdim, scaAl, nDraws, nChains,
                 indexSave, pathFiles):
        self.case = case
        self.nCores = nCores
        self.nTune = nTune
        self.nTuneInter = nTuneInter
        self.tuneBool = tuneBool
        self.tune_thr = tune_thr
        self.tallyBool = tallyBool
        self.convChecksBool = convChecksBool
        self.rndSeedBool = rndSeedBool
        self.scaNdim = scaNdim
        self.scaAl = scaAl
        self.nDraws = nDraws
        self.nChains = nChains
        self.indexSave = indexSave
        self.pathFiles = pathFiles
        self.allDelta = allDelta

        self.camera = fullData.Synt.Intr.camera
        self.model = fullData.Synt.Intr.model
        self.imgSize = fullData.Synt.Intr.s
        Ns = [2, 3]
        Xint = intrCalibResults['mean'][:3]
        self.cameraMatrix, self.distCoeffs = bl.flat2int(Xint, Ns, self.model)

        caseData = extractCaseData(exCase)
        self.imagePoints = caseData[0]
        self.xi, self.yi = self.imagePoints.T
        self.objpoints = caseData[1]
        self.rVecsT = caseData[2]
        self.tVecsT = caseData[3]
        self.xAllT = np.concatenate([self.rVecsT, self.tVecsT])
        self.nPt = self.objpoints.shape[0]
        self.nFree = 6
        self.observedNormed = np.zeros((self.nPt * 2))

        self.Crt = False  # no RT error
        self.Cf = np.zeros((4, 4))
        self.Cf[2:, 2:] = intrCalibResults['cov'][:2, :2]
        self.Ck = intrCalibResults['cov'][2, 2]
        self.Cfk = np.zeros(4)
        self.Cfk[2:] = intrCalibResults['cov'][:2, 2]
        self.Ci = np.array([stdPix**2 * np.eye(2)] * self.nPt)

        # tau de 1/5 pra la ventana movil
        self.weiEsp = np.exp(- np.arange(nDraws) * 5 / nDraws)[::-1]
        self.weiEsp /= np.sum(self.weiEsp)
예제 #3
0
    def perform(self, node, inputs_storage, output_storage):
        # global projCount
        # projCount += 1
        # self.count += 1
        # print('IDX %d projection %d, global %d' %
        #       (self.idx, self.count, projCount))
        Xint, Xext = inputs_storage

        # saco los parametros de flat para que los use la func de projection
        # print(Xint)
        cameraMatrix, distCoeffs = bl.flat2int(Xint, Ns, model)
        # print(cameraMatrix, distCoeffs)
        xy = np.zeros((n, m, 2))
        cm = np.zeros((n, m, 2, 2))

        for j in range(n):
            rVec, tVec = bl.flat2ext(Xext[j])
            xy[j, :, 0], xy[j, :, 1], cm[j] = cl.inverse(imagePoints.reshape(
                (n, m, 2))[j],
                                                         rVec,
                                                         tVec,
                                                         cameraMatrix,
                                                         distCoeffs,
                                                         model,
                                                         Cccd=Ci[j])

        # print(xy)

        xy -= objpoints2D

        S = np.linalg.inv(cm)

        u, s, v = np.linalg.svd(S)

        sdiag = np.zeros_like(u)
        sdiag[:, :, [0, 1], [0, 1]] = np.sqrt(s)

        A = (u.reshape((n, m, 2, 2, 1, 1)) * sdiag.reshape(
            (n, m, 1, 2, 2, 1)) * v.transpose((0, 1, 3, 2)).reshape(
                (n, m, 1, 1, 2, 2))).sum(axis=(3, 4))

        xy = np.sum(xy.reshape((n, m, 2, 1)) * A, axis=3)

        output_storage[0][0] = xy
예제 #4
0
    def perform(self, node, inputs_storage, output_storage):
        # global projCount
        # projCount += 1
        # self.count += 1
        # print('IDX %d projection %d, global %d' %
        #       (self.idx, self.count, projCount))
        Xint, Xext = inputs_storage

        # saco los parametros de flat para que los use la func de projection
        # print(Xint)
        cameraMatrix, distCoeffs = bl.flat2int(Xint, Ns, model)
        # print(cameraMatrix, distCoeffs)
        xy = np.zeros((n, m, 2))
        cm = np.zeros((n, m, 2, 2))

        for j in range(n):
            rVec, tVec = bl.flat2ext(Xext[j])
            xy[j, :, 0], xy[j, :, 1], cm[j] = cl.inverse(
                    imagePoints.reshape((n, m, 2))[j], rVec, tVec,
                    cameraMatrix, distCoeffs, model, Cccd=Ci[j])

        # print(xy)

        xy -= objpoints2D

        S = np.linalg.inv(cm)

        u, s, v = np.linalg.svd(S)

        sdiag = np.zeros_like(u)
        sdiag[:,:,[0,1],[0,1]] = np.sqrt(s)

        A = (u.reshape((n, m, 2, 2, 1, 1)) *
             sdiag.reshape((n, m, 1, 2 ,2, 1)) *
             v.transpose((0,1,3,2)).reshape((n, m, 1, 1, 2, 2))
             ).sum(axis=(3,4))

        xy = np.sum(xy.reshape((n,m,2,1)) * A, axis=3)

        output_storage[0][0] = xy
예제 #5
0
extrinsicFolder = "./resources/intrinsicCalib/" + camera + "/"

# load model specific data
#distCoeffs = np.load(distCoeffsFile)
#cameraMatrix = np.load(linearCoeffsFile)

# load intrinsic calib uncertainty
resultsML = np.load(intrinsicParamsFile).all()  # load all objects
#Nmuestras = resultsML["Nsamples"]
Xint = resultsML['paramsMU']
covarDist = resultsML['paramsVAR']
#muCovar = resultsML['paramsMUvar']
#covarCovar = resultsML['paramsVARvar']
Ns = resultsML['Ns']
cameraMatrix, distCoeffs = bl.flat2int(Xint, Ns, model)

if model == modelos[3]:
    Cf = np.zeros((4, 4))
    Cf[2:, 2:] = covarDist[:2, :2]

    Ck = covarDist[2, 2]
else:
    Cf = covarDist[:4, :4]
    Ck = covarDist[4:, 4:]

# Calibration points
dataPts = np.loadtxt(calibptsFile)
xIm = dataPts[:, :2]  # PUNTOS DE CALIB EN PIXELES
n = 1
m = dataPts.shape[0]
예제 #6
0
fullDataFile = "./resources/fullDataIntrExtr.npy"
dataFile = open(fullDataFile, "rb")
fullData = pickle.load(dataFile)
dataFile.close()

# cam puede ser ['vca', 'vcaWide', 'ptz'] son los datos que se tienen
camera = fullData.Synt.Intr.camera
#modelos = ['poly', 'rational', 'fisheye', 'stereographic']
model = fullData.Synt.Intr.model
Ns = [2, 3]
nH = fullData.Synt.Extr.h.shape[0]
nAng = fullData.Synt.Extr.ang.shape[0]
fkV = np.concatenate([fullData.Synt.Intr.uv, [fullData.Synt.Intr.k]])  #

# load model specific data
cameraMatrix, distCoeffs = flat2int(fkV, Ns, model)

# load data
rVall = fullData.Synt.Extr.rVecs
rVall = np.transpose([rVall] * nH, (1, 0, 2)).reshape((-1, 3))
tVall = fullData.Synt.Extr.tVecs.reshape((-1, 3))
rtVall = np.concatenate([rVall, tVall], axis=1)

nPt = fullData.Synt.Extr.imgPt.shape[2]  # cantidad de imagenes
nIm = np.prod(fullData.Synt.Extr.imgPt.shape[:2])  # puntos por imagen

# imagePoints = fullData.Synt.Extr.imgPt.reshape((nIm, nPt, 2))
chessboardModel = fullData.Synt.Ches.objPt
imgSize = fullData.Synt.Intr.s

# tomo las detecciones sin ruido
예제 #7
0
fullDataFile = "./resources/fullDataIntrExtr.npy"
dataFile = open(fullDataFile, "rb")
fullData = pickle.load(dataFile)
dataFile.close()

# cam puede ser ['vca', 'vcaWide', 'ptz'] son los datos que se tienen
camera = fullData.Synt.Intr.camera
#modelos = ['poly', 'rational', 'fisheye', 'stereographic']
model = fullData.Synt.Intr.model
Ns = [2,3]
nH = fullData.Synt.Extr.h.shape[0]
nAng = fullData.Synt.Extr.ang.shape[0]
fkV = np.concatenate([fullData.Synt.Intr.uv, [fullData.Synt.Intr.k]]) #

# load model specific data
cameraMatrix, distCoeffs = flat2int(fkV, Ns, model)

# load data
rVall = fullData.Synt.Extr.rVecs
rVall = np.transpose([rVall] * nH, (1, 0, 2)).reshape((-1, 3))
tVall = fullData.Synt.Extr.tVecs.reshape((-1, 3))
rtVall = np.concatenate([rVall, tVall], axis=1)

nPt = fullData.Synt.Extr.imgPt.shape[2]  # cantidad de imagenes
nIm = np.prod(fullData.Synt.Extr.imgPt.shape[:2])  # puntos por imagen

# imagePoints = fullData.Synt.Extr.imgPt.reshape((nIm, nPt, 2))
chessboardModel = fullData.Synt.Ches.objPt
imgSize = fullData.Synt.Intr.s

# tomo las detecciones sin ruido
예제 #8
0
extrinsicFolder = "./resources/intrinsicCalib/" + camera + "/"


# load model specific data
#distCoeffs = np.load(distCoeffsFile)
#cameraMatrix = np.load(linearCoeffsFile)

# load intrinsic calib uncertainty
resultsML = np.load(intrinsicParamsFile).all()  # load all objects
#Nmuestras = resultsML["Nsamples"]
Xint = resultsML['paramsMU']
covarDist = resultsML['paramsVAR']
#muCovar = resultsML['paramsMUvar']
#covarCovar = resultsML['paramsVARvar']
Ns = resultsML['Ns']
cameraMatrix, distCoeffs = bl.flat2int(Xint, Ns, model)

if model==modelos[3]:
    Cf = np.zeros((4,4))
    Cf[2:,2:] = covarDist[:2,:2]
    
    Ck = covarDist[2,2]
else:
    Cf = covarDist[:4,:4]
    Ck = covarDist[4:,4:]


# Calibration points
dataPts = np.loadtxt(calibptsFile)
xIm = dataPts[:,:2]  # PUNTOS DE CALIB EN PIXELES
n = 1