4 |
jakw |
1 |
#include <iostream>
|
|
|
2 |
#include <unistd.h>
|
|
|
3 |
#include "Codec.h"
|
|
|
4 |
#include "CodecGrayCode.h"
|
|
|
5 |
#include "CodecPhaseShift.h"
|
|
|
6 |
|
|
|
7 |
#include "Projector.h"
|
|
|
8 |
|
|
|
9 |
#include <opencv2/opencv.hpp>
|
|
|
10 |
|
|
|
11 |
int main(){
|
|
|
12 |
|
|
|
13 |
Projector projector(1);
|
|
|
14 |
unsigned int screenResX, screenResY;
|
|
|
15 |
projector.getScreenRes(&screenResX, &screenResY);
|
|
|
16 |
//unsigned int screenResX = 608, screenResY = 684;
|
|
|
17 |
|
|
|
18 |
bool diamondPattern = true;
|
|
|
19 |
|
|
|
20 |
// Codec for horizontal direction
|
|
|
21 |
CodecGrayCode codecHorz(screenResX, screenResY, diamondPattern);
|
|
|
22 |
|
|
|
23 |
// Codec for vertical direction (slight misuse of code)
|
|
|
24 |
CodecGrayCode codecVert(screenResY, screenResX, diamondPattern);
|
|
|
25 |
|
|
|
26 |
int NHorz = codecHorz.getNPatterns();
|
|
|
27 |
int NVert = codecVert.getNPatterns();
|
|
|
28 |
|
|
|
29 |
cv::namedWindow("Pattern");
|
|
|
30 |
|
|
|
31 |
for(int i=0; i<NHorz; i++){
|
|
|
32 |
cv::Mat pattern = codecHorz.getEncodingPattern(i);
|
|
|
33 |
pattern = cv::repeat(pattern, screenResY/pattern.rows, screenResX/pattern.cols);
|
|
|
34 |
cv::imshow("Pattern", pattern);
|
|
|
35 |
projector.displayTexture(pattern.ptr(), pattern.cols, pattern.rows);
|
|
|
36 |
// Treat pattern as a pseudo captured frame
|
|
|
37 |
std::vector<cv::Mat> channels;
|
|
|
38 |
cv::split(pattern, channels);
|
|
|
39 |
codecHorz.setFrame(i, channels[0]);
|
|
|
40 |
std::cout << "Horizontal Pattern " << i+1 << "/" << NHorz << std::endl << std::flush;
|
|
|
41 |
cv::waitKey(10);
|
|
|
42 |
}
|
|
|
43 |
for(int i=0; i<NVert; i++){
|
|
|
44 |
cv::Mat pattern = codecVert.getEncodingPattern(i);
|
|
|
45 |
pattern = pattern.t();
|
|
|
46 |
pattern = cv::repeat(pattern, screenResY/pattern.rows, screenResX/pattern.cols);
|
|
|
47 |
cv::imshow("Pattern", pattern);
|
|
|
48 |
projector.displayTexture(pattern.ptr(), pattern.cols, pattern.rows);
|
|
|
49 |
// Treat pattern as a pseudo captured frame
|
|
|
50 |
std::vector<cv::Mat> channels;
|
|
|
51 |
cv::split(pattern, channels);
|
|
|
52 |
codecVert.setFrame(i, channels[0]);
|
|
|
53 |
std::cout << "Horizontal Pattern " << i+1 << "/" << NVert << std::endl << std::flush;
|
|
|
54 |
cv::waitKey(10);
|
|
|
55 |
}
|
|
|
56 |
|
|
|
57 |
// Reconstruct up image
|
|
|
58 |
cv::Mat up, mask, shading;
|
|
|
59 |
codecHorz.decodeFrames(up, mask, shading);
|
|
|
60 |
|
|
|
61 |
// Reconstruct vp image
|
|
|
62 |
cv::Mat vp;
|
|
|
63 |
codecVert.decodeFrames(vp, mask, shading);
|
|
|
64 |
|
|
|
65 |
cv::namedWindow("up");
|
|
|
66 |
cv::imshow("up", up/screenResX);
|
|
|
67 |
cv::namedWindow("vp");
|
|
|
68 |
cv::imshow("vp", vp/screenResY);
|
|
|
69 |
cv::namedWindow("mask");
|
|
|
70 |
cv::imshow("mask", mask);
|
|
|
71 |
cv::namedWindow("shading");
|
|
|
72 |
cv::imshow("shading", shading);
|
|
|
73 |
|
|
|
74 |
cv::waitKey(0);
|
|
|
75 |
}
|
|
|
76 |
|