-
Notifications
You must be signed in to change notification settings - Fork 63
/
slcrunch.cpp
2418 lines (2064 loc) · 86.5 KB
/
slcrunch.cpp
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
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// slcrunch.cpp
// parse images from gray code binary image sequence(s)
// by John De Witt
#include <map>
#include <vector>
#include <string>
#include <iostream>
#include <fstream>
#include <assert.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <stdio.h>
#include <string.h>
#include "util.h"
#include "sl_util.h"
#include <opencv2/opencv.hpp>
#include <opencv2/imgproc/imgproc.hpp>
#include <opencv2/calib3d/calib3d.hpp>
#include <opencv2/highgui/highgui.hpp>
//#include <opencv2/core/core.hpp>
//#include <opencv2/imgcodecs.hpp>
//#include <stdio.h>
//#include <math.h>
//#include <string.h>
//#include <time.h>
//#include <stdint.h>
using namespace cv;
using namespace std;
//using namespace Imf;
//using namespace Imath;
#define DBUG 0
#define THRESHOLD_VALUE 5
#define SUBSAMPLE_GRID 0
#define SUBSAMPLE_POINT 1
enum { DETECTION = 0, CAPTURING = 1, CALIBRATED = 2 };
static void help()
{
printf("This program parses an image sequence of structured light patterns to extract pixel locations.\n"
" Notable options include:\n"
" - subsampling of dense point correspondence data\n"
" - find chessboard corners in camera and projector coordinate spaces\n"
// "ex: lsnum -d folder/ | xargs slcrunch\n"
"ex: slcrunch.out -sf 16 -st grid -chess 5 3 calibset_01.yaml\n"
"Usage: slcrunch\n"
// " image [..] # sequence of images to parse\n"
" input_data # input data\n"
" # - text file with a list of the images in the sequence\n"
" [-red] # process only the red channel of input images\n"
" [-green] # process only the green channel of input images\n"
" [-blue] # process only the blue channel of input images\n"
" [-m <msg>] # message/note to attach to scan for identification\n"
" [-ply] # configure ply 3d point output (disables yaml match output)\n"
" [-prosize <NxM>] # specify the projector space resolution used\n"
" [-procam <file.yaml>] # configure camera-projector calibration input (required for PLY output)\n"
" [-inv|-noinv] # specify whether inverses are shown in sequence\n"
" # default = inv\n"
" [-x|-nox] # specify whether x axis is encoded in sequence\n"
" # default = x\n"
" [-y|-noy] # specify whether y axis is encoded in sequence\n"
" # default = y\n"
" [-chess <w> <h>] # specify that there is a chessboard in view of the camera\n"
" # - w and h refer to the number of inner corners on each axis\n"
" # - corners are found in camera and projector coordinate spaces\n"
" # - corners in projector space are only found if -x -y enabled\n"
" [-s <scale>] # set chessboard scale\n"
" [-chessimg <fname>] # load a full-white image for finding the chessboard\n"
" [-chessidx <number>] # load a full-white image for finding the chessboard from the input sequence\n"
" [-t <thresh_value>] # specify black/white threshold parameter\n"
" [-sf <factor>] # set factor for subsampling output points\n"
" [-st <grid|point>] # set type of subsampling (grid or point)\n"
" # default = grid\n"
" [-c] # coalesce each object space point into a single image space point\n"
" [-f <filter>] # apply filter for output point RGB values (median)\n"
" [-b <bits>] # truncation: number of LSB in the pattern images that will be ignored\n"
" [-noc] # disable point coalescing\n"
" [-prefix <prefix>] # the output filename prefix; it is appended to every output file path\n"
" [-o <out_map>] # the output filename for the image/object correspondence map\n"
" # the text file can be generated with imagelist_creator\n"
" [-yaml|-noyaml] # configure yaml output\n"
" [-nomatch] # disable saving camera-projector correspondences"
" [-vis] # save visualization images\n"
" # default = yaml\n"
" [-vscl] # set color mapping visualization scale\n"
" [-vsize] # supersample the output correspondence visualization output\n"
"\n");
}
// from opencv
static bool readStringList( const string& filename, vector<string>& l )
{
// if( !file_exists(filename) )
// {
// return false;
// }
l.resize(0);
FileStorage fs(filename, FileStorage::READ);
if( !fs.isOpened() )
return false;
FileNode n = fs.getFirstTopLevelNode();
if( n.type() != FileNode::SEQ )
return false;
FileNodeIterator it = n.begin(), it_end = n.end();
for( ; it != it_end; ++it )
l.push_back((string)*it);
return true;
}
// parse a list file and add pathprefix to each file if needed
// get GCB images
// get RGB images
static bool parseStringList( const string& filename, vector<string>& gcb_l, vector<string>& rgb_l )
{
// fail if dir
if( is_dir( filename.c_str() ) )
{
cout << "Can't parse directory as string list.." << endl;
return false;
}
// fail if file doesn't exist
if( !file_exists(filename.c_str()) )
{
return false;
}
string prefix;
string fname;
size_t found = filename.find_last_of("/");
if( found == string::npos )
{
prefix = "";
fname = filename;
}
else
{
prefix = filename.substr(0,found);
fname = filename.substr(found+1);
}
printf("\tprefix : [%s]\n",prefix.c_str());
printf("\tfname : [%s]\n",fname.c_str());
// open the file
FileStorage fs(filename, FileStorage::READ);
gcb_l.resize(0);
rgb_l.resize(0);
if( !fs.isOpened() )
return false;
cout << "parsing [" << filename << "]\n";
// first load all GRAY CODE BINARY images
FileNode gcb_images = fs["gcb_images"];
if( gcb_images.type() == FileNode::SEQ )
{
FileNodeIterator gcb_it = gcb_images.begin(), gcb_it_end = gcb_images.end();
for( ; gcb_it != gcb_it_end; ++gcb_it )
{
// add prefix if no slash present in path
if( ((string)*gcb_it).find("/") == string::npos )
{
if( prefix != "" )
gcb_l.push_back(prefix +"/"+ (string)*gcb_it);
else
gcb_l.push_back((string)*gcb_it);
}
// omit prefix if slash is present in path
else
{
gcb_l.push_back((string)*gcb_it);
}
cout << "[" << gcb_l[gcb_l.size()-1] << "]" << endl;
}
}
// next load all RGB MONOCHROME images
FileNode rgb_images = fs["rgb_images"];
if( rgb_images.type() == FileNode::SEQ )
{
FileNodeIterator rgb_it = rgb_images.begin(), rgb_it_end = rgb_images.end();
for( ; rgb_it != rgb_it_end; ++rgb_it )
{
// add prefix if no slash present in path
if( ((string)*rgb_it).find("/") == string::npos )
{
if( prefix != "" )
rgb_l.push_back(prefix +"/"+ (string)*rgb_it);
else
rgb_l.push_back((string)*rgb_it);
}
// omit prefix if slash is present in path
else
{
rgb_l.push_back((string)*rgb_it);
}
cout << "[" << rgb_l[rgb_l.size()-1] << "]" << endl;
}
}
printf("gcb images : %d, rgb images: %d\n",(int)gcb_l.size(),(int)rgb_l.size());
return true;
}
Vec3b float2Gray( float t ){
t = fmin(fmax(t,0.f),1.f);
Vec3b col;
col[0] = (uint8_t)(255*t);
col[1] = (uint8_t)(255*t);
col[2] = (uint8_t)(255*t);
return col;
}
Vec3b float2Color( float t ){
float n = 4.f;
float dt = 1.f/n;
float r,g,b;
if(t<=1.f*dt)
{
// red to orange
float c = n*(t-0.f*dt);
r = 1.0f;
g = c;
b = 0.f;
}
else if (t<=2.f*dt){
// orange to green
float c = n*(t-1.f*dt);
r = 1.0f-c;
g = 1.0f;
b = 0.f;
}
else if (t<=3.f*dt){
// green to cyan
float c = n*(t-2.f*dt);
r = 0.f;
g = 1.0f;
b = c;
}
else if (t<=4.f*dt){
// cyan to blue
float c = n*(t-3.f*dt);
r = 0.f;
g = 1.f-c;
b = 1.f;
}
/*
if(t<=1.f*dt)
{
float c = n*(t-0.f*dt);
r = c;
g = 0.f;
b = 0.f;
}
else if (t<=2.f*dt){
float c = n*(t-1.f*dt);
r = 1.0f;
g = c;
b = 0.f;
}
else if (t<=3.f*dt){
float c = n*(t-2.f*dt);
r = 1.0f-c;
g = 1.0f;
b = c;
}
else if (t<=4.f*dt){
float c = n*(t-3.f*dt);
r = 0.f;
g = 1.f-c;
b = 1.f-c*0.5;
}
*/
Vec3b col;
col[0] = (uint8_t)(255*b);
col[1] = (uint8_t)(255*g);
col[2] = (uint8_t)(255*r);
// if (t<=1.f*dt)
// { //black -> red
// float c = n*(t-0.f*dt);
// col[0] = c; //0-255
// col[1] = 0.f; //0
// col[2] = 0.f; //0
// }
// else if (t<=2.f*dt)
// { //red -> red,green
// float c = n*(t-1.f*dt);
// col[0] = 255.f; //255
// col[1] = c; //0-255
// col[2] = 0.f; //0
// }
// else if (t<=3.f*dt)
// { //red,green -> green
// float c = n*(t-2.f*dt);
// col[0] = 255.f-c; //255-0
// col[1] = 255.f; //255
// col[2] = 0.f; //0
// }
// else if (t<=4.f*dt)
// { //green -> blue
// float c = n*(t-3.f*dt);
// col[0] = 0.f; //0
// col[1] = 255.f-c; //255-0
// col[2] = c; //0-255
// }
return col;
}
/**
From "Triangulation", Hartley, R.I. and Sturm, P., Computer vision and image understanding, 1997
*/
Mat LinearLSTriangulation(Point3d u, //homogenous image point (u,v,1)
Matx34d P, //camera 1 matrix
Point3d u1, //homogenous image point in 2nd camera
Matx34d P1 //camera 2 matrix
)
{
// build matrix A for homogenous equation system Ax = 0
// assume X = (x,y,z,1), for Linear-LS method
// which turns it into a AX = B system
// where A is 4x3, X is 3x1 and B is 4x1
Matx43d A(u.x * P(2,0)- P(0,0), u.x * P(2,1)-P(0,1), u.x * P(2,2)- P(0,2),
u.y * P(2,0)- P(1,0), u.y * P(2,1)-P(1,1), u.y * P(2,2)- P(1,2),
u1.x* P1(2,0)- P1(0,0), u1.x* P1(2,1)-P1(0,1), u1.x* P1(2,2)-P1(0,2),
u1.y* P1(2,0)- P1(1,0), u1.y* P1(2,1)-P1(1,1), u1.y* P1(2,2)-P1(1,2) );
Mat B = (Mat_<double>(4,1) <<
-(u.x * P(2,3) - P(0,3)),
-(u.y * P(2,3) - P(1,3)),
-(u1.x*P1(2,3) -P1(0,3)),
-(u1.y*P1(2,3) -P1(1,3)));
Mat X;
solve(A,B,X,DECOMP_SVD);
return X;
}
#define EPSILON 0.1
/**
From "Triangulation", Hartley, R.I. and Sturm, P., Computer vision and image understanding, 1997
*/
Mat_<double> IterativeLinearLSTriangulation(Point3d u, //homogenous image point (u,v,1)
Matx34d P, //camera 1 matrix
Point3d u1, //homogenous image point in 2nd camera
Matx34d P1 //camera 2 matrix
) {
double wi = 1, wi1 = 1;
Mat_<double> X(4,1);
for (int i=0; i<10; i++) { //Hartley suggests 10 iterations at most
Mat_<double> X_ = LinearLSTriangulation(u,P,u1,P1);
X(0) = X_(0); X(1) = X_(1); X(2) = X_(2); X_(3) = 1.0;
//recalculate weights
double p2x = Mat_<double>(Mat_<double>(P).row(2)*X)(0);
double p2x1 = Mat_<double>(Mat_<double>(P1).row(2)*X)(0);
//breaking point
if(fabs(wi - p2x) <= EPSILON && fabs(wi1 - p2x1) <= EPSILON) break;
wi = p2x;
wi1 = p2x1;
//reweight equations and solve
Matx43d A((u.x*P(2,0)-P(0,0))/wi, (u.x*P(2,1)-P(0,1))/wi, (u.x*P(2,2)-P(0,2))/wi,
(u.y*P(2,0)-P(1,0))/wi, (u.y*P(2,1)-P(1,1))/wi, (u.y*P(2,2)-P(1,2))/wi,
(u1.x*P1(2,0)-P1(0,0))/wi1, (u1.x*P1(2,1)-P1(0,1))/wi1, (u1.x*P1(2,2)-P1(0,2))/wi1,
(u1.y*P1(2,0)-P1(1,0))/wi1, (u1.y*P1(2,1)-P1(1,1))/wi1, (u1.y*P1(2,2)-P1(1,2))/wi1
);
Mat_<double> B = (Mat_<double>(4,1) << -(u.x*P(2,3) -P(0,3))/wi,
-(u.y*P(2,3) -P(1,3))/wi,
-(u1.x*P1(2,3) -P1(0,3))/wi1,
-(u1.y*P1(2,3) -P1(1,3))/wi1
);
solve(A,B,X_,DECOMP_SVD);
X(0) = X_(0); X(1) = X_(1); X(2) = X_(2); X_(3) = 1.0;
}
return X;
}
// always assume x images precede y images
int main( int argc, char** argv ) {
// Mat test(1050,1680,CV_8UC3,Scalar::all(0));
// for(int r=0; r<test.rows; r++){
// uint8_t* pix = test.ptr<uint8_t>(r);
// for(int c=0; c<test.cols; c++){
// Vec3b col = float2Color( c/(float)test.cols );
// pix[c*3+0]=col[0];
// pix[c*3+1]=col[1];
// pix[c*3+2]=col[2];
// }
// }
// imshow("test",test);
// waitKey(0);
// return 0;
// string
const char* inImgListFN = 0;
const char* outputMapFilename = 0;
const char* outputImgFilename = 0;
const char* outPrefix = 0;
// const char* outputPlyFilename = 0;
// const char* outputDirectImgFilename = 0;
// const char* outputGlobalImgFilename = 0;
//
int n=0;
/*
const char* outMapFN = findNextName( "slscan_%04d.yaml",&n); n=0;
const char* outViscFN = findNextName( "slscan_%04d_rgb.png",&n); n=0;
const char* outVisxFN = findNextName( "slscan_%04d_x.png",&n); n=0;
const char* outVisyFN = findNextName( "slscan_%04d_y.png",&n); n=0;
const char* outVisDirFN = findNextName( "slscan_%04d_direct.png",&n); n=0;
const char* outVisAmbFN = findNextName( "slscan_%04d_indirect.png",&n); n=0;
const char* outChessCamFN = findNextName( "slscan_%04d_chesscam.png",&n); n=0;
const char* outChessProFN = findNextName( "slscan_%04d_chesspro.png",&n); n=0;
const char* outPlyFN = findNextName( "slscan_%04d.ply", &n); n=0;
*/
//(char*)malloc(.
const char* outMapFN = findNextName( "slscan_%04d.yaml",&n); n=0;
const char* outViscFN = findNextName( "slscan_%04d_rgb.png",&n); n=0;
const char* outVisxFN = findNextName( "slscan_%04d_x.png",&n); n=0;
const char* outVisyFN = findNextName( "slscan_%04d_y.png",&n); n=0;
const char* outVisDirFN = findNextName( "slscan_%04d_direct.png",&n); n=0;
const char* outVisAmbFN = findNextName( "slscan_%04d_indirect.png",&n); n=0;
const char* outChessCamFN = findNextName( "slscan_%04d_chesscam.png",&n); n=0;
const char* outChessProFN = findNextName( "slscan_%04d_chesspro.png",&n); n=0;
const char* outPlyFN = findNextName( "slscan_%04d.ply", &n); n=0;
const char* outFilter = 0;
bool rgbFilter = false;
bool chess_image_input = false;
const char* inChessImageFN = 0;
int chess_idx = 23;
//outputMapFilename = outMapFN;
string scanMessage;
vector< stringmap > exifList;
vector< string > gcbFileList;
vector< string > rgbFileList;
vector< Mat > imageList;
// vector< pair<string,stringmap> > image_list;
// memory hog mode (load all images at once)
bool load_all = false;
int diff_threshold = 5;
// procam calib input options
bool enable_procam = false;
const char* inCalibFN = 0;
// projector info
Size2i base_pro_size;
Size2i pro_size_input;
bool enable_prosize_input = false;
// rgb pattern processing
bool enable_rgb_pattern_processing = true;
// color channel selection
bool enable_monochrome_processing = false;
int monochrome_channel_idx = 0;
// chessboard options
bool enable_chess = false;
Size chess_size(0,0);
// what to parse
bool show_inverse = true;
bool show_x = true;
bool show_y = true;
// what to load
bool enable_mapload = false;
const char* inMapFN = 0;
// what to save
bool save_yaml = true;
bool save_ply = false;
bool save_preview = false;
// truncation
bool truncate_enable = false;
int truncate_value = 0; // can abandon last N bits in sequence // must get at least N bits
// whether to output the result
bool save_file = true;
bool save_matches = true;
// subsampling options
bool enable_coalesce = false;
bool enable_subsamp = false;
int subsamp_factor = 1;
int subsamp_type = SUBSAMPLE_GRID;
// useful values
float chess_scale = 1;
int mode = DETECTION;
float vis_scl = 1;
float vis_supersample = 1;
int mult = 1;
int bits = 1;
int offset = 1;
if( argc < 2 ){
help();
return 0;
}
// setup
{
// parse arguments
for(int i=1; i<argc; i++){
const char* s = argv[i];
// printf("%d : %s\n",i,s);
// subsample parameters
if( strcmp(s,"-sf") == 0 )
{
enable_subsamp = true;
if( i+1 >= argc )
return fprintf( stderr, "Subsample factor not provided\n"), -1;
if( sscanf( argv[++i], "%d", &subsamp_factor ) != 1 || subsamp_factor < 1 )
return fprintf( stderr, "Invalid subsample factor\n"), -1;
}
else if( strcmp(s,"-st") == 0 )
{
if( i+1 >= argc )
return fprintf( stderr, "Subsample mode not provided\n"), -1;
const char* s2 = argv[++i];
if(strcmp(s2,"grid") == 0)
subsamp_type = SUBSAMPLE_GRID;
else if(strcmp(s2,"point") == 0)
subsamp_type = SUBSAMPLE_POINT;
else
return fprintf( stderr, "Invalid subsample mode\n"), -1;
}
// RGB filter
else if( strcmp(s,"-f") == 0 )
{
outFilter = argv[++i];
printf("RGB FILTER ENGAGE [%s]\n",outFilter);
}
// output prefix
else if( strcmp(s,"-prefix") == 0 )
{
outPrefix = argv[++i];
printf("outPrefix [%s]\n",argv[i]);
}
// coalesce
else if( strcmp(s,"-c") == 0 )
{
enable_coalesce = true;
printf("enable_coalesce\n");
}
// enable rgb pattern processing
else if( strcmp(s,"-rgb") == 0 )
{
enable_rgb_pattern_processing = true;
printf("enable_rgb_pattern_processing = true\n");
}
// input monochrome red mode
else if( strcmp(s,"-red") == 0 )
{
enable_monochrome_processing = true;
monochrome_channel_idx = 2;
printf("enable_monochrome_processing = red\n");
}
// input monochrome green mode
else if( strcmp(s,"-green") == 0 )
{
enable_monochrome_processing = true;
monochrome_channel_idx = 1;
printf("enable_monochrome_processing = green\n");
}
// input monochrome blue mode
else if( strcmp(s,"-blue") == 0 )
{
enable_monochrome_processing = true;
monochrome_channel_idx = 0;
printf("enable_monochrome_processing = blue\n");
}
// no coalesce
else if( strcmp(s,"-noc") == 0 )
{
enable_coalesce = false;
printf("disable_coalesce\n");
}
// sequence parameters
else if( strcmp(s,"-inv") == 0 )
{
show_inverse = true;
}
else if( strcmp(s,"-noinv") == 0 )
{
show_inverse = false;
}
else if( strcmp(s,"-x") == 0 )
{
show_x = true;
}
else if( strcmp(s,"-nox") == 0 )
{
show_x = false;
}
else if( strcmp(s,"-y") == 0 )
{
show_y = true;
}
else if( strcmp(s,"-noy") == 0 )
{
show_y = false;
}
// output format
else if( strcmp(s,"-vis") == 0 )
{
save_preview = true;
}
else if( strcmp(s,"-ply") == 0 )
{
save_ply = true;
// also turn off yaml output
save_yaml = false;
save_matches = false;
enable_coalesce = true;
printf("enable_coalesce\n");
}
else if( strcmp(s,"-noply") == 0 )
{
save_ply = false;
}
else if( strcmp(s,"-yaml") == 0 )
{
save_yaml = true;
}
else if( strcmp(s,"-noyaml") == 0 )
{
save_yaml = false;
}
// do not save correspondence data
else if( strcmp(s,"-nomatch") == 0 )
{
save_matches = false;
}
else if( strcmp(s,"-nosave") == 0 )
{
// save_file = false;
}
else if( strcmp( s, "-o" ) == 0 )
{
if( i+1 >= argc )
return fprintf( stderr, "Output file name not provided\n"), -1;
outPrefix = argv[++i];
}
else if( strcmp( s, "-m" ) == 0 )
{
if( i+1 >= argc )
return fprintf( stderr, "Scan message not provided\n"), -1;
scanMessage = string(argv[++i]);
}
// load all images into memory first
else if( strcmp(s,"-loadall") == 0 )
{
load_all = true;
}
// set threshold value
else if( strcmp(s,"-t") == 0 )
{
int v = 5;
if( i+1 >= argc )
return fprintf( stderr, "Threshold value not provided\n"), -1;
if( sscanf( argv[++i], "%d", &v ) != 1 || v < 1 )
return fprintf( stderr, "Invalid threshold value\n"), -1;
diff_threshold = v;
}
// set truncate value
else if( strcmp(s,"-b") == 0 )
{
int v = 0;
if( i+1 >= argc )
return fprintf( stderr, "Truncate value not provided\n"), -1;
if( sscanf( argv[++i], "%d", &v ) != 1 || v < 0 )
return fprintf( stderr, "Invalid truncate value\n"), -1;
truncate_enable = true;
truncate_value = v;
}
// enable chessboard detection
else if( strcmp(s,"-chess") == 0 )
{
int w,h;
if( i+2 >= argc )
return fprintf( stderr, "Not enough chessboard parameters provided\n"), -1;
if( sscanf( argv[++i], "%d", &w) != 1 || w<2 )
return fprintf( stderr, "Invalid chessboard width\n"), -1;
if( sscanf( argv[++i], "%d", &h) != 1 || h<2 )
return fprintf( stderr, "Invalid chessboard height\n"), -1;
enable_chess = true;
chess_size.width = w;
chess_size.height = h;
printf("looking for chessboard [%dx%d]\n",w,h);
chess_image_input = true;
}
// set chessboard scale
else if( strcmp(s,"-s") == 0 )
{
float v = 1;
if( i+1 >= argc )
return fprintf(stderr,"Chessboard scale value not provided\n"), -1;
if( sscanf( argv[++i], "%f", &v) != 1 || v<=0 )
return fprintf(stderr,"Invalid chessboard scale value\n"), -1;
chess_scale = v;
}
// set color mapping visualization scale
else if( strcmp(s,"-vscl") == 0 )
{
float v = 1;
if( i+1 >= argc )
return fprintf(stderr,"Color mapping visualization scale value not provided\n"), -1;
if( sscanf( argv[++i], "%f", &v) != 1 || v<=0 )
return fprintf(stderr,"Invalid color mapping visualization scale value\n"), -1;
vis_scl = v;
}
// set color mapping visualization scale
else if( strcmp(s,"-vscale") == 0 )
{
float v = 1;
if( i+1 >= argc )
return fprintf(stderr,"Supersample visualization output scale value not provided\n"), -1;
if( sscanf( argv[++i], "%f", &v) != 1 || v<=0 )
return fprintf(stderr,"Invalid supersample scale value\n"), -1;
vis_supersample = fmin(fmax(v,1.0f),10.0f);
}
else if( strcmp(s,"-prosize") == 0 )
{
if(i+1<argc){
int w,h;
if( sscanf( argv[++i], "%dx%d", &w, &h) != 2 || w<1 || h<1 )
return fprintf( stderr, "Invalid chessboard size\n"), -1;
enable_prosize_input = true;
pro_size_input.width = w;
pro_size_input.height = h;
base_pro_size = pro_size_input;
printf("projector size : %d x %d\n",w,h);
} else {
return fprintf( stderr, "Invalid projector size input\n" ), -1;
}
}
else if( strcmp(s,"-procam") == 0 )
{
if( i+1 >= argc )
return fprintf(stderr,"Projector camera calibration filename not provided\n"),-1;
enable_procam = true;
inCalibFN = argv[++i];
}
else if( strcmp(s,"-chessimg") == 0 )
{
if( i+1 >= argc )
return fprintf(stderr,"Chessboard image filename not provided\n"),-1;
chess_image_input = true;
inChessImageFN = argv[++i];
}
else if( strcmp(s,"-chessidx") == 0 )
{
if( i+1 >= argc )
return fprintf(stderr,"Chessboard image filename not provided\n"),-1;
chess_image_input = true;
if( sscanf( argv[++i], "%d", &chess_idx ) != 1 )
{
printf("error: invalid chess image idx\n");
}
}
else if( strcmp(s,"-load") == 0 )
{
if( i+1 >= argc )
return fprintf(stderr,"Load point map filename not provided\n"),-1;
enable_mapload = true;
inMapFN = argv[++i];
}
// file input
else if( s[0] != '-' ){
inImgListFN = s;
}
else
return fprintf( stderr, "Unknown option %s", s), -1;
}
// args done
string filename(inImgListFN);
string prefix;
size_t found = filename.find_last_of("/");
if( found == string::npos )
{
prefix = filename;
}
else
{
prefix = filename.substr(0,found);
}
printf("PREFIX FOR OUTPUT : [%s]\n",prefix.c_str());
// generate names for all output files
char* filepattern = (char*)calloc(100,sizeof(char));
if( outPrefix )
{
sprintf(filepattern,"%s%%s%%s",outPrefix);
} else {
sprintf(filepattern,"%%s%%s");
}
char* outMapPath = (char*)calloc(100,sizeof(char));
char* outVisCPath = (char*)calloc(100,sizeof(char));
char* outVisXPath = (char*)calloc(100,sizeof(char));
char* outVisYPath = (char*)calloc(100,sizeof(char));
char* outVisDirPath = (char*)calloc(100,sizeof(char));
char* outVisAmbPath = (char*)calloc(100,sizeof(char));
char* outVisChessCamPath = (char*)calloc(100,sizeof(char));
char* outVisChessProPath = (char*)calloc(100,sizeof(char));
char* outPlyPath = (char*)calloc(100,sizeof(char));
sprintf(outMapPath, filepattern, prefix.c_str(), ".yaml");
sprintf(outVisCPath, filepattern, prefix.c_str(), "_rgb.png");
sprintf(outVisXPath, filepattern, prefix.c_str(), "_x.png");
sprintf(outVisYPath, filepattern, prefix.c_str(), "_y.png");
sprintf(outVisDirPath, filepattern, prefix.c_str(), "_direct.png");
sprintf(outVisAmbPath, filepattern, prefix.c_str(), "_indirect.png");
sprintf(outVisChessCamPath,filepattern, prefix.c_str(), "_chesscam.png");
sprintf(outVisChessProPath,filepattern, prefix.c_str(), "_chesspro.png");
sprintf(outPlyPath, filepattern, prefix.c_str(), "_cloud.ply");
cout << "outMapPath\t" << outMapPath << endl;
cout << "outVisCPath\t" << outVisCPath << endl;
cout << "outVisXPath\t" << outVisXPath << endl;
cout << "outVisYPath\t" << outVisYPath << endl;
cout << "outVisDirPath\t" << outVisDirPath << endl;
cout << "outVisAmbPath\t" << outVisAmbPath << endl;
cout << "outVisChessCamPath\t" << outVisChessCamPath << endl;
cout << "outVisChessProPath\t" << outVisChessProPath << endl;
cout << "outPlyPath\t" << outPlyPath << endl;
if(true)
{
outMapFN = outMapPath;
outViscFN = outVisCPath;
outVisxFN = outVisXPath;
outVisyFN = outVisYPath;
outVisDirFN = outVisDirPath;
outVisAmbFN = outVisAmbPath;
outChessCamFN = outVisChessCamPath;
outChessProFN = outVisChessProPath;
outPlyFN = outPlyPath;
}
// touch files
FILE *f_chesscam, *f_chesspro, *f_yaml, *f_ply;
if( enable_chess )
{
f_chesscam = fopen(outChessCamFN,"w"); fclose(f_chesscam);
f_chesspro = fopen(outChessProFN,"w"); fclose(f_chesspro);
}
if( save_yaml )
{
f_yaml = fopen(outMapFN,"w"); fclose(f_yaml);
}
if( save_ply )
{
f_ply = fopen(outPlyFN,"w"); fclose(f_ply);
}
// load file list
if( inImgListFN ){
string fn(inImgListFN);
string fn_auto;
// if passed a directory, check for a list.yaml automatically
if( is_dir(inImgListFN) )
{
if( fn.find_last_of("/") == fn.length()-1 )
{
fn_auto = fn + "sequence.yaml";
}
else
{
fn_auto = fn + "/sequence.yaml";
}
}
printf("checking image list: %s\n", inImgListFN);
bool listLoaded = false;
listLoaded = parseStringList(fn.c_str(), gcbFileList, rgbFileList);
if( listLoaded && ( gcbFileList.size() > 0 || rgbFileList.size() > 0 ) )
{
mode = CAPTURING;
printf("Using image list: %s\n", inImgListFN);
}
else
{
listLoaded = parseStringList( fn_auto.c_str(), gcbFileList, rgbFileList );
if( listLoaded && ( gcbFileList.size() > 0 || rgbFileList.size() > 0 ) )
{
mode = CAPTURING;
printf("Using image list: %s\n", inImgListFN);
inImgListFN = fn_auto.c_str();
}
else
{
// give up
printf("invalid image list specified, exiting..\n");
return 1;
}
}
/*
// try parsing the actual path
if( parseStringList(fn.c_str(), gcbFileList, rgbFileList) ){
mode = CAPTURING;
printf("Using image list: %s\n", inImgListFN);
}
// try parsing an auto-guess of path + "list.yaml"
else if( parseStringList( fn_auto.c_str(), gcbFileList, rgbFileList ) )
{
inImgListFN = fn_auto.c_str();
mode = CAPTURING;
printf("Using image list: %s\n", inImgListFN);
}
// give up
else
{
printf("invalid image list specified, exiting..\n");
return 1;
}
*/
} else {
printf("no file specified, exiting..\n");
return 1;
}
// load exif data
{
printf("loading exif data..\n");
getExifList( gcbFileList, exifList );
printf("done!\n");
}
if( !scanMessage.empty() ){
printf("scan message: \"%s\"\n",scanMessage.c_str());
}
// detect invalid options
// exit if neither x or y data is selected
if( !show_x && !show_y ){
printf("neither x or y axis configured, exiting..\n");
return 1;
}
// calculate # of bitfields
{
mult = 1;