-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProjectorPattern.cpp
More file actions
54 lines (49 loc) · 1.5 KB
/
Copy pathProjectorPattern.cpp
File metadata and controls
54 lines (49 loc) · 1.5 KB
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
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <iostream>
#include <stdlib.h>
#include <cstdlib>
#include <math.h>
#include <vector>
#define WINDOW "Pattern"
using namespace cv;
using namespace std;
Mat randomPattern(int width, int height, int patch, int neighbor);
uchar randomTwoStage(int stage);
int main(){
int width = 1080;
int height= 810;
int patch = 9;
int neighbor = 10;
char keypress;
Mat pattern = randomPattern(width,height,patch,neighbor);
namedWindow(WINDOW, WINDOW_AUTOSIZE);
imshow(WINDOW, pattern);
imwrite("projector_pattern.jpg",pattern);
waitKey(0);
return 0;
}
Mat randomPattern(int width, int height,int patch, int neighbor){
Mat img(height,width, CV_8UC1);
for(int r = 0; r < height; r+=patch){
int row_offset = ((int)((int)r/patch)/neighbor)%2;
for(int c = 0; c < width; c+=patch){
int bi_state = (((int)((int)c/patch)/neighbor) + row_offset)%2 ;
int sr_l = min(height-r,patch);
int sc_l = min(width-c,patch);
// int pat_val = randomTwoStage(bi_state);
int pat_val = rand()%255;
for(int sr = 0; sr < sr_l; sr++){
for(int sc = 0; sc < sc_l; sc++){
img.at<uchar>(r+sr, c+sc) = pat_val;
}
}
}
}
cout << "Pattern complete generation" << endl;
return img;
}
uchar randomTwoStage(int stage){
int val = rand()%127 + stage * 128;
return (uchar)val;
}