-
Notifications
You must be signed in to change notification settings - Fork 0
/
stereovisiontest.cpp
71 lines (57 loc) · 2.44 KB
/
stereovisiontest.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
#include "mainwindow.h"
#include "stereovision.h"
void MainWindow::stereoVisionTest(QString image_path,int cornersX,int cornersY){
trace("stereoVisionTest ... ");
StereoVision* sv = new StereoVision(640,480);
IplImage* images[2];
//perform calibration based on sets of 2 images (chessboard)
sv->calibrationStart(cornersX,cornersY);
// READ IN THE LIST OF CHESSBOARDS:
QString file_name;
for(int i=0;;i++){
for(int lr=0;lr<2;lr++){
file_name = tr("%1%2%3.jpg").arg(image_path).arg(i).arg(lr ? 'L' : 'R');
trace(file_name);
images[lr] = cvLoadImage( file_name.toAscii(), 0 );
}
if(images[0] && images[1]){
trace(file_name);
sv->calibrationAddSample(images[0],images[1]);
for(int lr=0;lr<2;lr++)
cvReleaseImage(&images[lr]);
}else{
break;
}
}
sv->calibrationEnd();
sv->calibrationSave("stereovisiontest.dat");
//Once saved calibartion data can be loaded later with:
//sv->calibrationLoad("stereovisiontest.dat");
//test our calibartion with first image set:
CvSize imageSize = sv->getImageSize();
for(int lr=0;lr<2;lr++){
QString file_name = tr("%1%2%3.jpg").arg(image_path).arg(0).arg(lr ? 'L' : 'R');
images[lr] = cvLoadImage( file_name.toAscii(), 0 );
}
//this method will compute sv->imagesRectified[0],sv->imagesRectified[1],sv->imageDepth,sv->imageDepthNormalized
sv->stereoProcess(images[0],images[1]);
//merge 2 rectified images in one image (pair) and display horizontal lines
//to evaluate rectification.
CvMat* pair = cvCreateMat( imageSize.height, imageSize.width*2,CV_8UC3 );
CvMat part;
cvGetCols( pair, &part, 0, imageSize.width );
cvCvtColor( sv->imagesRectified[0], &part, CV_GRAY2BGR );
cvGetCols( pair, &part, imageSize.width,imageSize.width*2 );
cvCvtColor( sv->imagesRectified[1], &part, CV_GRAY2BGR );
for(int j = 0; j < imageSize.height; j += 16 )
cvLine( pair, cvPoint(0,j),cvPoint(imageSize.width*2,j),CV_RGB(0,255,0));
//display the results
cvNamedWindow( "rectified", 1 );
cvShowImage( "rectified", pair );
cvNamedWindow( "depth", 1 );
cvShowImage( "depth", sv->imageDepthNormalized);
//free up memory
cvReleaseImage(&images[0]);
cvReleaseImage(&images[1]);
cvReleaseMat(&pair);
}