1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
| def estimateIntrinsics(boardSize: Point2d, objectPoints: List[List[Point3f]], imagePoints: List[List[Point2f]]) -> void: xi, k1, k2, p1, p2, u0, v0 = 1.0, 0.0, 0.0, 0.0, 0.0, imageWidth / 2.0, imageHeight() / 2.0
for eachImage in imagePoints: for eachRow in eachImage: for idx, (x, y) in enumerate(eachRow): P[idx, :] = [x - u0, y - v0, 0.5, -0.5 * (square(x - u0) + square(y - v0))] cv2.svd.solveZ(P, C) t = square(C[0]) + square(C[1]) + C[2] * C[3] gamma = sqrt(C[2] / C[3]) rvecs, tvecs = estimateExtrinsics(objetcPoints, imagePoints, gamma) reprojErr = reprojectionError(objetcPoints, imagePoints, rvecs, tvecs, gamma) if reprojErr < minReprojErr: minReprojErr = reprojErr gamma0 = gamma if gamm0 <= 0.0 and minReprojErr > float('inf'): raise RuntimeError return gamma0
|