forked from snavely/bundler_sfm
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathImageData.h
452 lines (348 loc) · 13.6 KB
/
ImageData.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
/*
* Copyright (c) 2008-2010 Noah Snavely (snavely (at) cs.cornell.edu)
* and the University of Washington
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
*/
/* ImageData.h */
/* Simple image storage and operations */
#ifndef __image_data_h__
#define __image_data_h__
#include <vector>
using namespace std;
#ifndef __BUNDLER__
#include "wx/wx.h"
#endif /* __BUNDLER__ */
#include "BoundingBox.h"
#include "Camera.h"
#include "Geometry.h"
#include "ParameterBound.h"
// #include "Polygon.h"
#include "keys.h"
#include "image.h"
enum ImageBoundary {
BoundaryNorth,
BoundaryEast,
BoundarySouth,
BoundaryWest,
};
class ImageNote {
public:
void Read(FILE *f, double width, double height);
char *m_text;
BoundingBox m_bbox;
};
class ImageDate {
public:
ImageDate() : m_known(false) { }
void GetString(char *buf);
void GetMonthString(char *buf);
/* Return the date in the form of a double */
double GetDateDouble();
double GetDateOnlyDouble();
/* Return the time in the form of a double */
double GetTimeDouble();
bool m_known; /* Is the date/time known? */
int m_month, m_day, m_year; /* Date */
int m_hour, m_minute, m_second; /* Time */
};
int CompareImageDates(ImageDate *date1, ImageDate *date2);
class AnnotationData {
public:
AnnotationData(int idx, BoundingBox bbox) : m_idx(idx), m_bbox(bbox) { }
AnnotationData() { }
int m_idx;
BoundingBox m_bbox;
};
#ifndef __BUNDLER__
class TPSBasis {
public:
TPSBasis() {
m_LU = NULL;
m_ipiv = NULL;
}
void Clear() {
if (m_LU != NULL) {
delete [] m_LU;
m_LU = NULL;
}
if (m_ipiv != NULL) {
delete [] m_ipiv;
m_ipiv = NULL;
}
m_basis_points.clear();
m_indices.clear();
}
double *m_LU;
int *m_ipiv;
std::vector<DPoint> m_basis_points;
std::vector<int> m_indices;
};
#endif /* __BUNDLER__ */
class ImageData {
public:
ImageData() {
m_img = NULL;
m_thumb_fixed = NULL;
m_thumb = NULL;
m_thumb256 = NULL;
m_marked = -1;
m_canonical=false;
m_canonical_pano=false;
m_rahul_pano_index=-1;
m_texture_index = m_back_texture_index = -1;
m_thumb_texture_index = -1;
m_thumb_fixed_texture_index = -1;
m_texture_image_loaded = false;
m_panorama_index = -1;
m_keys_loaded = false;
m_keys_desc_loaded = false;
m_keys_scale_rot_loaded = false;
m_cached_dimensions = false;
m_cached_keys = false;
//m_k0 = 1.0;
//m_k1 = m_k2 = m_k3 = m_k4 = 0.0;
m_known_intrinsics = false;
//m_rd_focal = 0.0;
m_init_focal = 0.0;
m_has_init_focal = false;
m_rotation = 0;
m_is_dragged = false;
m_is_dropped = false;
m_ignore_in_bundle = false;
m_licensed = false;
m_real_name = NULL;
m_partition = -1;
m_layout_x = m_layout_y = 0;
m_lat = m_long = 0.0;
m_day_photo = true;
m_added = false;
m_is_rep = false;
m_geosupport = 0.0;
}
/* Initialize the image data given a string description */
void InitFromString(char *buf, const char *path,
bool fisheye_by_default);
/* Create a pinhole view for the keys */
void UndistortKeys();
std::vector<Keypoint> UndistortKeysCopy();
void DistortPoint(double x, double y, double *R,
double &x_out, double &y_out) const;
void DistortPoint(double x, double y, double &x_out, double &y_out) const;
void UndistortPoint(double x, double y,
double &x_out, double &y_out) const;
/* Radial distortion routines */
void DistortPointRD(double x, double y,
double &x_out, double &y_out) const;
void UndistortPointRD(double x, double y,
double &x_out, double &y_out) const;
img_t *UndistortImage(double theta = 0.0, double phi = 0.0,
int num_rot = 0);
/* Undistort the image to a different size than the original */
img_t *UndistortImageResize(int w_new, int h_new);
void ToNDC(double x, double y, double &x_n, double &y_n);
void FromNDC(double x_n, double y_n, double &x, double &y);
/* Save the dimensions of the image */
void CacheDimensions();
void CacheNumKeys();
/* Return the image dimensions */
int GetWidth();
int GetHeight();
int GetArea();
void GetBaseName(char *buf);
void GetName(char *buf);
void GetCompressedTextureFilename(char *buf) const;
bool CompressedTextureExists();
/* Return the bounding box of the image */
BoundingBox GetBoundingBox();
/* Get the texture coordinates for a point */
v2_t GetPointTexCoords(v2_t point);
/* Get the texture coordinates of a set of points */
std::vector<v2_t> GetPointTexCoords(const std::vector<v2_t> &pts);
/* Returns true if the given pixel is in range */
bool PixelInRange(double x, double y);
void LoadImage();
void UnloadImage();
void LoadTexImage();
void UnloadTexImage();
void LoadBackTexImage();
void UnloadBackTexImage();
bool TexImageExists();
/* Compute a Gaussian pyramid for the current image */
bool LoadFeatureWeightMap();
void SaveFeatureWeightMap();
void ComputeFeatureWeightMap(int id,
const std::vector<PointData> &pt_data);
void ComputeFeatureWeightMap(int id,
const std::vector<PointData> &pt_data,
const std::vector<int> &used_points);
void CheckLoadFloatingThumb();
void LoadFloatingThumbnail();
void UnloadFloatingThumbnail();
void CheckLoadFixedThumb();
void LoadFixedThumbnail(int w_max, int h_max, int rotation);
void UnloadFixedThumbnail();
void LoadThumb256();
void UnloadThumb256();
int GetNumKeys();
void LoadOrExtractKeys(const char *sift_binary, bool undistort = true);
void LoadKeys(bool descriptor = true, bool undistort = true);
void LoadDescriptors(bool undistort);
void LoadKeysWithScaleRot(bool descriptor = true, bool undistort = true);
void UnloadKeys();
void UnloadKeysWithScaleRot();
void ExtractFeatures(const char *sift_binary, bool undistort);
/* Find line segments in the image */
void DetectLineSegments(double sigma,
double threshold1, double threshold2,
double min_line_segment_size);
/* Render line segments to an image */
img_t *RenderLineSegments();
/* Query whether a given line segment is supported by the image */
bool LineSegmentSupportedByImage(LineSegment2D &line);
/* Return true if the given line intersects the image */
bool LineIntersectsImage(double *line, double *isect1, double *isect2,
ImageBoundary &b1, ImageBoundary &b2);
/* Find the gradient direction at the given position */
void Gradient(double x, double y, double *grad);
vector<bool> m_visinfo;
vector<int> m_visindex;
/* Read key colors */
void ReadKeyColors();
/* Read the camera */
bool ReadCamera();
/* Read the tracks */
bool ReadTracks(int img_idx, std::vector<PointData> &pt_list);
/* Write the camera */
void WriteCamera();
/* Write the camera in XML format */
void WriteCameraXML(FILE *f);
/* Write the tracks */
void WriteTracks();
void ReadMetadata();
/* Get notes associated with this image */
std::vector<ImageNote> GetNotes();
#ifndef __BUNDLER__
/* Compute 3D points used for estimating the amount of distortion
* in the image */
void ComputeDistortionPoints(const std::vector<PointData> &pt_data,
std::vector<DPoint3> &pts_world,
std::vector<DPoint3> &pts_plane);
void ComputeOrthoPlane(const std::vector<PointData> &pt_data);
void ComputeTPSBasis(const std::vector<PointData> &pt_data);
void FreeTPSBasis();
#endif /* __BUNDLER__ */
void ComputeHistogram(int nbins, double *r_hist,
double *g_hist, double *b_hist);
void ComputeHistogramLUV(int nbins, double *L_hist,
double *U_hist, double *V_hist);
void ComputeHistogramLUVNorm(int nbins, double *L_hist,
double *U_hist, double *V_hist);
int m_width, m_height; /* Cached dimensions */
int m_xmin,m_xmax,m_ymin,m_ymax; /*dimensions of bounding box of geometry projected onto the image*/
bool m_cached_dimensions;
int m_num_keys; /* Cached number of keys */
bool m_cached_keys;
bool m_added;
int m_marked; /* if true, then the camera is on some orbit*/
bool m_canonical;
bool m_canonical_pano;
int m_rahul_pano_index;
char *m_real_name;
char *m_name; /* Filename */
char *m_key_name; /* Key filename */
char m_user_name[256]; /* User name */
char m_flickr_index[256]; /* Flickr index */
ImageDate m_date; /* Date / time the photo was taken */
bool m_day_photo; /* Was this photo shot during the day? */
#ifndef __BUNDLER__
wxImage *m_wximage; /* WX image */
wxBitmap *m_bitmap; /* Bitmap */
#endif /* __BUNDLER__ */
img_t *m_img; /* Image */
img_t *m_texture_img; /* Texture image for foreground -- rahul*/
img_t *m_back_texture_img;/* Texture Image for background -- rahul*/
img_t *m_thumb; /* Thumbnail 1 */
img_t *m_thumb8; /* Thumbnail 2 */
img_t *m_thumb_fixed; /* Thumbnail 3 */
img_t *m_thumb256; /* Thumbnail 4 */
img_t *m_feature_weight_map; /* Weighting for image comparison */
bool m_image_loaded, m_keys_loaded, m_keys_desc_loaded,
m_keys_scale_rot_loaded;
bool m_texture_image_loaded;
bool m_licensed; /* Can we actually use this image? */
bool m_fisheye; /* Is this a fisheye image? */
double m_fCx, m_fCy; /* Fisheye center */
double m_fRad, m_fAngle; /* Other fisheye parameters */
double m_fFocal; /* Desired focal length */
double m_lat, m_long; /* Latitude and longitude (if known) */
double m_geocentric[3]; /* Geocentric position */
double m_geoplanar[3]; /* Geoplanar */
double m_geosupport; /* What proportion of pairs vouch for me? */
std::vector<AnnotationData> m_notes;
/* Radial distortion parameters */
bool m_known_intrinsics;
double m_K[9];
//double m_k0, m_k1, m_k2, m_k3, m_k4, m_rd_focal;
double m_k[5];
bool m_ignore_in_bundle; /* Ignore this image during bundle
* adjustment */
/* Focal length parameters */
bool m_has_init_focal; /* Do we have an initial focal length? */
double m_init_focal; /* Initial focal length */
CameraInfo m_camera; /* Information on the camera used to
* capture this image */
std::vector<LineSegment2D> m_line_segments;
/* Texture mapping data */
int m_texture_index; /* Texture index of this image */
int m_back_texture_index; /* Texture index OF background image*/
int m_thumb_texture_index; /* Texture index of the thumbnail */
int m_thumb_fixed_texture_index; /* Texture index of the thumbnail */
ParameterBound m_bounds; /* Texture coord bounds */
ParameterBound m_thumb_bounds;
ParameterBound m_thumb_fixed_bounds;
PlaneData m_fit_plane; /* Plane fit to the observed points */
// PlaneData m_ortho_plane;
PlaneData m_current_plane; /* Temporary plane valid for current
* view */
std::vector<Keypoint> m_keys; /* Keypoints in this image */
std::vector<KeypointWithDesc> m_keys_desc; /* Keypoints with descriptors */
std::vector<KeypointWithScaleRot> m_keys_scale_rot;
std::vector<bool> m_key_flags;
std::vector<int> m_visible_points; /* Indices of points visible
* in this image */
std::vector<int> m_visible_keys;
std::vector<int> m_visible_lines; /* Indices of lines visible
* in this image */
#ifndef __BUNDLER__
std::vector<DPoint3> m_dist_pts_world;
std::vector<DPoint3> m_dist_pts_plane;
#endif /* __BUNDLER__ */
std::vector<int> m_neighbors; /* List of neighboring images */
int m_rotation; /* Orientation of this image
* (0,1,2,3) */
int m_panorama_index; /* Index of the panorama this
* view belongs to */
bool m_is_dragged; /* Is this image being dragged? */
bool m_is_dropped; /* Has this image been dropped? */
bool m_is_rep; /* Is this a representative image? */
int m_drag_x, m_drag_y; /* Screen coords of drag
* position */
double m_drop_pt[3]; /* World coords of drop
* position */
int m_partition; /* Partition this image belongs to */
int m_layout_x, m_layout_y; /* 2D layout positions */
#ifndef __BUNDLER__
TPSBasis m_tps_basis; /* Thin-plate spline basis */
#endif
};
#endif /* __image_data_h__ */