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
| const int numCorrespondingFeatures = 8;
IplImage *morphedImage=0;
IplImage *leftImage = cvLoadImage("gauche.png",CV_LOAD_IMAGE_COLOR);
IplImage *rightImage = cvLoadImage("droite.png",CV_LOAD_IMAGE_COLOR);
const int DST_WIDTH = max(leftImage->width, rightImage->width);
const int DST_HEIGHT = max(leftImage->height, rightImage->height);
//1 compute fundamental matrix
CvMat * fundamentalMatrix = cvCreateMat(3,3,CV_32F);
CvMat * status = cvCreateMat(1,numCorrespondingFeatures,CV_8UC1);
//fill point
//TODO
CvMat points1;
double a[] = {
199, 170,
278, 165,
240, 177,
210, 209,
271, 203,
212, 284,
253, 284,
236, 266
};
points1 = cvMat(8, 2, CV_64FC1, a);
CvMat points2;
double b[] = {
184, 174,
265, 168,
212, 182,
190, 212,
247, 208,
188, 287,
227, 287,
213, 267
};
points2 = cvMat(8, 2, CV_64FC1, b);
int res = cvFindFundamentalMat(&points1, &points2, fundamentalMatrix, CV_FM_RANSAC, 1.0, 0.99, status);
if(!res){return -1;}
//2 compute corresponding epilines
CvMat * epilines1 = cvCreateMat(3, numCorrespondingFeatures, CV_32F);
CvMat * epilines2 = cvCreateMat(3, numCorrespondingFeatures, CV_32F);
cvComputeCorrespondEpilines(&points1, 1, fundamentalMatrix, epilines1);
cvComputeCorrespondEpilines(&points2, 2, fundamentalMatrix, epilines2);
//3 compute number and length of the epilines
int lineCount;
CvMatrix3 FMAT; //f_mat is CvMat fundamental matrix already calculated.
for (int i=0;i<3;i++)
{
FMAT.m[i][0]=fundamentalMatrix->data.fl[i*3];
FMAT.m[i][1]=fundamentalMatrix->data.fl[i*3+1];
FMAT.m[i][2]=fundamentalMatrix->data.fl[i*3+2];
}
cvMakeScanlines(&FMAT , cvSize(DST_WIDTH, DST_HEIGHT), 0,0,0,0, &lineCount);
int *lengthEpilines1 = new int[lineCount];
int *lengthEpilines2 = new int[lineCount];
int *epilinesInt1 = new int[4*lineCount];
int *epilinesInt2 = new int[4*lineCount];
cvMakeScanlines(&FMAT, cvSize(DST_WIDTH, DST_HEIGHT), epilinesInt1, epilinesInt2, lengthEpilines1, lengthEpilines2, &lineCount);
//4 prewarp the source images
uchar *preWarpData1 = new uchar[max(DST_WIDTH, DST_HEIGHT)*lineCount*3];
uchar *preWarpData2 = new uchar[max(DST_WIDTH, DST_HEIGHT)*lineCount*3];
cvPreWarpImage(lineCount, leftImage, preWarpData1, lengthEpilines1, epilinesInt1);
cvPreWarpImage(lineCount, rightImage, preWarpData2, lengthEpilines2, epilinesInt2); |
Partager