MCPcopy Create free account
hub / github.com/ColmapView/Colmapview.github.io / parseImagesText

Function parseImagesText

src/parsers/images.ts:105–187  ·  view source on GitHub ↗
(text: string)

Source from the content-addressed store, hash-verified

103 * 2362.39 248.498 58396 1784.7 268.254 59027 1784.7 268.254 -1
104 */
105export function parseImagesText(text: string): Map<number, Image> {
106 const images = new Map<number, Image>();
107 const lines = text.split('\n');
108
109 let i = 0;
110 while (i < lines.length) {
111 const line = lines[i].trim();
112
113 // Skip comments and empty lines
114 if (line.startsWith('#') || line === '') {
115 i++;
116 continue;
117 }
118
119 // Parse image header line
120 const headerParts = line.split(/\s+/);
121 if (headerParts.length < 10) {
122 i++;
123 continue;
124 }
125
126 const imageId = parseColmapIntegerToken(headerParts[0], { min: 0 });
127 const qvecValues = parseColmapNumberTokens(headerParts.slice(1, 5));
128 const tvecValues = parseColmapNumberTokens(headerParts.slice(5, 8));
129 const cameraId = parseColmapIntegerToken(headerParts[8], { min: 0 });
130 const name = headerParts[9];
131
132 if (imageId === null || qvecValues === null || tvecValues === null || cameraId === null) {
133 i++;
134 continue;
135 }
136
137 const qvec: [number, number, number, number] = [
138 qvecValues[0],
139 qvecValues[1],
140 qvecValues[2],
141 qvecValues[3],
142 ];
143 const tvec: [number, number, number] = [
144 tvecValues[0],
145 tvecValues[1],
146 tvecValues[2],
147 ];
148
149 // Parse points2D line (next line)
150 i++;
151 const points2D: Point2D[] = [];
152
153 if (i < lines.length && !lines[i].startsWith('#')) {
154 const pointsLine = lines[i].trim();
155 if (pointsLine !== '') {
156 const pointsParts = pointsLine.split(/\s+/);
157
158 // Points are in triplets: X, Y, POINT3D_ID
159 for (let j = 0; j + 2 < pointsParts.length; j += 3) {
160 const x = parseColmapNumberToken(pointsParts[j]);
161 const y = parseColmapNumberToken(pointsParts[j + 1]);
162 const point3DId = parseColmapBigIntToken(pointsParts[j + 2]);

Callers 1

images.test.tsFile · 0.90

Calls 4

parseColmapIntegerTokenFunction · 0.90
parseColmapNumberTokensFunction · 0.90
parseColmapNumberTokenFunction · 0.90
parseColmapBigIntTokenFunction · 0.90

Tested by

no test coverage detected