def positionCamera(point, direction, rotAngle): """Highly globally dependent function. Very complicated geometry positioning. Must not be called before all intrinsic parameters are set.""" perpendicularAxis = direction.cross(defaultVecDir) angle = math.atan2(perpendicularAxis.norm(), direction*defaultVecDir) focalVec, vecxx, vecyy = (focVec, imVecX, imVecY) if defaultVecDir.cross(direction) == ZEROVEC \ else rotate_3d(perpendicularAxis, angle, [focVec, imVecX, imVecY]) vecxx, vecyy = rotate_3d(focalVec, rotAngle, [vecxx, vecyy]) vecbx = (focalVec - vecxx).normalize() * widthP vecby = (focalVec - vecyy).normalize() * heightP origin = point + focalVec - vecbx * (widthPxl-1) / 2. - vecby * (heightPxl-1) / 2. return focalVec, vecbx, vecby, origin
def positionCamera(point, direction, rotAngle): """Highly globally dependent function. Very complicated geometry positioning. Must not be called before all intrinsic parameters are set.""" perpendicularAxis = direction.cross(defaultVecDir) angle = math.atan2(perpendicularAxis.norm(), direction * defaultVecDir) focalVec, vecxx, vecyy = (focVec, imVecX, imVecY) if defaultVecDir.cross(direction) == ZEROVEC \ else rotate_3d(perpendicularAxis, angle, [focVec, imVecX, imVecY]) vecxx, vecyy = rotate_3d(focalVec, rotAngle, [vecxx, vecyy]) vecbx = (focalVec - vecxx).normalize() * widthP vecby = (focalVec - vecyy).normalize() * heightP origin = point + focalVec - vecbx * (widthPxl - 1) / 2. - vecby * (heightPxl - 1) / 2. return focalVec, vecbx, vecby, origin
heightPxl = origImg.shape[0] widthChip = 0.0000014 * 2600 * CHIP_MUL heightChip = 0.0000014 * 1952 * CHIP_MUL widthC = widthChip * (widthPxl-1) / widthPxl heightC = heightChip * (heightPxl-1) / heightPxl widthP = widthChip / widthPxl heightP = heightChip / heightPxl # Intrinsic calculations that do not depend on camera position # Angle between the focal vector and vector that touches the half point of the side # of the image. Length of the said vector and the vector itself. angleX = math.atan(widthC/2./focalLength) angleY = math.atan(heightC/2./focalLength) lenX = math.sqrt(focalLength*focalLength + widthC*widthC/4.) lenY = math.sqrt(focalLength*focalLength + heightC*heightC/4.) imVecX = rotate_3d(perpX, angleX, [defaultVecDir])[0].normalize() * lenX imVecY = rotate_3d(perpY, angleY, [defaultVecDir])[0].normalize() * lenY focVec = defaultVecDir * focalLength # Source camera rotAngleS = 0 source = Vector(X_OFF, Y_OFF, Z_HEIGHT) cameraDirS = Vector(-TILT, 0., -1.).normalize() focVecS, vecbxs, vecbys, originS = positionCamera(source, cameraDirS, rotAngleS) # plotImVs(ax, source, focVecS*1000, vecbxs*1000, vecbys*1000, widthPxl, heightPxl) plotL(ax, source, source + focVecS*1000, 'r') grid = create_grid(widthPxl, heightPxl, vecbxs, vecbys, originS) # plotG(ax, grid, 'r') # Drain camera
heightPxl = origImg.shape[0] widthChip = 0.0000014 * 2600 * CHIP_MUL heightChip = 0.0000014 * 1952 * CHIP_MUL widthC = widthChip * (widthPxl - 1) / widthPxl heightC = heightChip * (heightPxl - 1) / heightPxl widthP = widthChip / widthPxl heightP = heightChip / heightPxl # Intrinsic calculations that do not depend on camera position # Angle between the focal vector and vector that touches the half point of the side # of the image. Length of the said vector and the vector itself. angleX = math.atan(widthC / 2. / focalLength) angleY = math.atan(heightC / 2. / focalLength) lenX = math.sqrt(focalLength * focalLength + widthC * widthC / 4.) lenY = math.sqrt(focalLength * focalLength + heightC * heightC / 4.) imVecX = rotate_3d(perpX, angleX, [defaultVecDir])[0].normalize() * lenX imVecY = rotate_3d(perpY, angleY, [defaultVecDir])[0].normalize() * lenY focVec = defaultVecDir * focalLength # Source camera rotAngleS = 0 source = Vector(X_OFF, Y_OFF, Z_HEIGHT) cameraDirS = Vector(-TILT, 0., -1.).normalize() focVecS, vecbxs, vecbys, originS = positionCamera(source, cameraDirS, rotAngleS) # plotImVs(ax, source, focVecS*1000, vecbxs*1000, vecbys*1000, widthPxl, heightPxl) plotL(ax, source, source + focVecS * 1000, 'r') grid = create_grid(widthPxl, heightPxl, vecbxs, vecbys, originS) # plotG(ax, grid, 'r')