-
Notifications
You must be signed in to change notification settings - Fork 84
/
Copy paththree_step_phase_shift_test.cpp
127 lines (93 loc) · 2.78 KB
/
three_step_phase_shift_test.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
#include "three_step_phase_shift.h"
#include <cstdio>
float printMinMax(IplImage *img) {
int w = img->width;
int h = img->height;
int step = w;
float *ptr = (float *)img->imageData;
int i;
float min,max;
min = 1e6;
max = 1e-6;
for (i = 0; i < h ; i++) {
for (int j = 0; j < w; j++) {
float val = (float)ptr[i*step+j*4];
if(val<min) min = val;
if(val>max) max = val;
}
}
cout << "min: " << min << "\nmax: "<<max << endl;
return max;
}
IplImage *boolarr2img(bool* barr, CvSize s) {
IplImage *img = cvCreateImageHeader(s,IPL_DEPTH_8U,1);
img->imageData = (char *)barr;
cvConvertScale(img,img,255);
return img;
}
void scale(IplImage *img) {
int w = img->width;
int h = img->height;
int step = w;
float *ptr = (float *)img->imageData;
int i;
float min,max;
min = 1e6;
max = 1e-6;
for (i = 0; i < h ; i++) {
for (int j = 0; j < w; j++) {
float val = (float)ptr[i*step+j*4];
if(val<min) min = val;
if(val>max) max = val;
}
}
cout << "min: " << min << "\nmax: "<<max << endl;
cvScale(img,img, 1/(max-min), -min/(max-min));
}
void makeimg() {
IplImage *img = cvCreateImage(cvSize(480,640),IPL_DEPTH_32F,1);
int w = img->width;
int h = img->height;
int step = img->widthStep;
uchar *ptr = (uchar *)img->imageData;
for (int i = 0; i < h; i++) {
for (int j = 0; j< w; j++) {
ptr[i*step+j*4] = 0.4;
}
}
cvScale(img, img, 2, 0.5);
cvShowImage("white",img);
cvWaitKey(0);
}
int main(int argc, const char *argv[])
{
if(argc<4) {
printf("too fewer arguments!");
return -1;
}
// makeimg();
IplImage *phase1 = cvLoadImage(argv[1]);
IplImage *phase2 = cvLoadImage(argv[2]);
IplImage *phase3 = cvLoadImage(argv[3]);
ThreeStepPhaseShift decoder(phase1,phase2,phase3);
decoder.phaseDecode();
IplImage* wrappedPhase = decoder.getWrappedPhase();
//IplImage* imgColor = decoder.getColorImage();
printMinMax(wrappedPhase);
cvScale(wrappedPhase, wrappedPhase, 1, 0.5);
decoder.compute();
IplImage* unwrappedPhase = decoder.getUnwrappedPhase();
scale(unwrappedPhase);
//printMinMax(unwrappedPhase);
IplImage *imgDepth = cvCreateImageHeader(cvGetSize(unwrappedPhase),IPL_DEPTH_32F,1);
imgDepth->imageData = (char *)decoder.getDepth();
scale(imgDepth);
printMinMax(imgDepth);
//printMinMax(unwrappedPhase);
cvShowImage("depth",imgDepth);
cvShowImage("wrapped phase",wrappedPhase);
cvShowImage("unwrapped phase",unwrappedPhase);
cvShowImage("mask",boolarr2img(decoder.getMask(),cvGetSize(wrappedPhase)));
cvWaitKey(0);
return 0;
}