-
Notifications
You must be signed in to change notification settings - Fork 0
/
main_gpu.cu
111 lines (90 loc) · 3.29 KB
/
main_gpu.cu
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
#include <iostream>
#include "elas.h"
#include "elas_gpu.h"
#include "image.h"
#include "cuda_runtime.h"
using namespace std;
// Global functions
void process (const char* file_1,const char* file_2);
// Enable profiling
#define PROFILE
int main(int argc, char** argv) {
// Startup the GPU device
// https://devtalk.nvidia.com/default/topic/895513/cuda-programming-and-performance/cudamalloc-slow/post/4724457/#4724457
cudaFree(0);
// Process example frames
process("./libelas-gpu-master/input/cones_left.pgm", "./libelas-gpu-master/input/cones_right.pgm");
/* process("../input/aloe_left.pgm", "../input/aloe_right.pgm");
process("../input/raindeer_left.pgm","../input/raindeer_right.pgm");
process("../input/urban1_left.pgm", "../input/urban1_right.pgm");
process("../input/urban2_left.pgm", "../input/urban2_right.pgm");
process("../input/urban3_left.pgm", "../input/urban3_right.pgm");
process("../input/urban4_left.pgm", "../input/urban4_right.pgm");*/
cout << "... done!" << endl;
// Done!
return EXIT_SUCCESS;
}
/**
* Compute disparities of pgm image input pair file_1, file_2
*/
void process (const char* file_1,const char* file_2) {
cout << "Processing: " << file_1 << ", " << file_2 << endl;
// load images
image<uchar> *I1,*I2;
I1 = loadPGM(file_1);
I2 = loadPGM(file_2);
// check for correct size
if (I1->width()<=0 || I1->height() <=0 || I2->width()<=0 || I2->height() <=0 ||
I1->width()!=I2->width() || I1->height()!=I2->height()) {
cout << "ERROR: Images must be of same size, but" << endl;
cout << " I1: " << I1->width() << " x " << I1->height() <<
", I2: " << I2->width() << " x " << I2->height() << endl;
delete I1;
delete I2;
return;
}
// get image width and height
int32_t width = I1->width();
int32_t height = I1->height();
// allocate memory for disparity images
const int32_t dims[3] = {width,height,width}; // bytes per line = width
float* D1_data = (float*)malloc(width*height*sizeof(float));
float* D2_data = (float*)malloc(width*height*sizeof(float));
// process
Elas::parameters param;
param.postprocess_only_left = false;
//param.subsampling = true;
ElasGPU elas(param);
elas.process(I1->data,I2->data,D1_data,D2_data,dims);
// find maximum disparity for scaling output disparity images to [0..255]
//float disp_max = 0;
//for (int32_t i=0; i<width*height; i++) {
// if (D1_data[i]>disp_max) disp_max = D1_data[i];
// if (D2_data[i]>disp_max) disp_max = D2_data[i];
//}
// copy float to uchar
//image<uchar> *D1 = new image<uchar>(width,height);
//image<uchar> *D2 = new image<uchar>(width,height);
//for (int32_t i=0; i<width*height; i++) {
// D1->data[i] = (uint8_t)max(255.0*D1_data[i]/disp_max,0.0);
// D2->data[i] = (uint8_t)max(255.0*D2_data[i]/disp_max,0.0);
//}
//// save disparity images
//char output_1[1024];
//char output_2[1024];
//strncpy(output_1,file_1,strlen(file_1)-4);
//strncpy(output_2,file_2,strlen(file_2)-4);
//output_1[strlen(file_1)-4] = '\0';
//output_2[strlen(file_2)-4] = '\0';
//strcat(output_1,"_disp.pgm");
//strcat(output_2,"_disp.pgm");
//savePGM(D1,output_1);
//savePGM(D2,output_2);
// free memory
delete I1;
delete I2;
//delete D1;
//delete D2;
free(D1_data);
free(D2_data);
}