MCPcopy Index your code
hub / github.com/ColmapView/Colmapview.github.io / writeImagesText

Function writeImagesText

src/parsers/colmapTextWriters.ts:33–86  ·  view source on GitHub ↗
(
  images: Map<ImageId, Image>,
  wasmReconstruction?: WasmReconstructionWrapper | null
)

Source from the content-addressed store, hash-verified

31}
32
33export function writeImagesText(
34 images: Map<ImageId, Image>,
35 wasmReconstruction?: WasmReconstructionWrapper | null
36): string {
37 const lines: string[] = [];
38
39 const getPoints2D = (img: Image): Point2D[] => {
40 if (img.points2D.length > 0) return img.points2D;
41 if (wasmReconstruction) {
42 return wasmReconstruction.getImagePoints2DArray(img.imageId);
43 }
44 return [];
45 };
46
47 let totalObs = 0;
48 for (const img of images.values()) {
49 const points2D = getPoints2D(img);
50 totalObs += points2D.filter((p) => p.point3DId !== UNMATCHED_POINT3D_ID).length;
51 }
52 const meanObs = images.size > 0 ? (totalObs / images.size).toFixed(6) : '0';
53
54 lines.push('# Image list with two lines of data per image:');
55 lines.push('# IMAGE_ID, QW, QX, QY, QZ, TX, TY, TZ, CAMERA_ID, NAME');
56 lines.push('# POINTS2D[] as (X, Y, POINT3D_ID)');
57 lines.push(`# Number of images: ${images.size}, mean observations per image: ${meanObs}`);
58
59 for (const imageId of sortedKeys(images)) {
60 const img = images.get(imageId)!;
61 const [qw, qx, qy, qz] = img.qvec;
62 const [tx, ty, tz] = img.tvec;
63 lines.push(
64 [
65 imageId,
66 formatDouble(qw),
67 formatDouble(qx),
68 formatDouble(qy),
69 formatDouble(qz),
70 formatDouble(tx),
71 formatDouble(ty),
72 formatDouble(tz),
73 img.cameraId,
74 img.name,
75 ].join(' ')
76 );
77
78 const points2D = getPoints2D(img);
79 const points2DStr = points2D
80 .map((p) => `${formatDouble(p.xy[0])} ${formatDouble(p.xy[1])} ${toTextPoint3DId(p.point3DId)}`)
81 .join(' ');
82 lines.push(points2DStr);
83 }
84
85 return lines.join('\n') + '\n';
86}
87
88export function writePoints3DText(points3D: Map<Point3DId, Point3D>): string {
89 const lines: string[] = [];

Calls 6

sortedKeysFunction · 0.90
formatDoubleFunction · 0.90
toTextPoint3DIdFunction · 0.90
getPoints2DFunction · 0.85
getMethod · 0.80
valuesMethod · 0.65

Tested by

no test coverage detected