When calibration is done, this example shows how basic 3D augmentation works.
#include <iostream>
#include "cv.h"
#include "highgui.h"
#ifdef HAVE_CONFIG_H
#endif
void usage(
const char *s) {
cerr << "usage:\n" << s
<< "[<cam number>|<video file>] [-m <model image>]\n";
exit(1);
}
int main(
int argc,
char** argv )
{
CvCapture* capture = 0;
const char *captureSrc = "0";
for (int i=1; i<argc; i++) {
if (strcmp(argv[i], "-m") ==0) {
if (i==argc-1)
usage(argv[0]);
i++;
} else if (argv[i][0]=='-') {
} else {
captureSrc = argv[i];
}
}
if(strlen(captureSrc) == 1 && isdigit(captureSrc[0]))
capture = cvCaptureFromCAM( captureSrc[0]-'0');
else
capture = cvCaptureFromAVI( captureSrc );
if( !capture )
{
cerr <<"Could not initialize capturing from " << captureSrc << " ...\n";
return -1;
}
400,
32,
3,
16,
1
))
{
cerr << "Unable to load the model image "
return -1;
}
const char *win = "Bazar";
IplImage* display=0;
IplImage*gray=0;
cvNamedWindow(win, 0);
cerr << "Unable to load calibration data\n";
return -2;
}
for(;;)
{
IplImage *frame = cvQueryFrame( capture );
if( !frame )
break;
if (frame->nChannels >1) {
if( !gray )
gray = cvCreateImage( cvGetSize(frame), IPL_DEPTH_8U, 1 );
cvCvtColor(frame, gray, CV_RGB2GRAY);
} else {
gray = frame;
}
cvShowImage(win,display);
} else {
cvShowImage(win, frame);
}
if( cvWaitKey(10) >= 0 )
break;
}
cvReleaseCapture( &capture );
cvDestroyWindow(win);
return 0;
}
{
if (*dst==0) *dst=cvCloneImage(video);
else cvCopy(video, *dst);
if (!m) return;
double w =video->width/2.0;
double h =video->height/2.0;
double pts[4][4] = {
{w,h,0, 1},
{2*w,h,0, 1},
{w,2*h,0, 1},
{w,h,-w-h, 1}
};
double projected[3][4];
CvMat ptsMat, projectedMat;
cvInitMatHeader(&ptsMat, 4, 4, CV_64FC1, pts);
cvInitMatHeader(&projectedMat, 3, 4, CV_64FC1, projected);
cvGEMM(m, &ptsMat, 1, 0, 0, &projectedMat, CV_GEMM_B_T );
for (int i=0; i<4; i++) {
projected[0][i] /= projected[2][i];
projected[1][i] /= projected[2][i];
}
cvLine(*dst,
cvPoint((
int)projected[0][0], (
int)projected[1][0]),
cvPoint((
int)projected[0][1], (
int)projected[1][1]), CV_RGB(0,255,0));
cvLine(*dst,
cvPoint((
int)projected[0][0], (
int)projected[1][0]),
cvPoint((
int)projected[0][2], (
int)projected[1][2]), CV_RGB(255,0,0));
cvLine(*dst,
cvPoint((
int)projected[0][0], (
int)projected[1][0]),
cvPoint((
int)projected[0][3], (
int)projected[1][3]), CV_RGB(0,0,255));
cvReleaseMat(&m);
}
{
static std::vector<CamCalibration::s_struct_points> pts;
pts.clear();
}
}
return true;
}