开发者

How would I map a camera image to create a live funhouse mirror using opencv?

Using Opencv and Linux I would like to create a fun-house mirror effect, short and squat, tall and thin effect using a live webcamera. My daughter loves those things and I would like to create one using a camera. I am not quite sure about the transforms necessary for 开发者_高级运维these effects. Any help would be appreciated. I have much of the framework running, live video playing and such, just not the transforms.

thanx


I think that you need to use 'radial' transforms and 'pin cushion' which is inverse radial. In order to braker the symmetry of the transforms you can strech the image before and after:

  1. Suppose your image is 300x300 pixels.
  2. Strech it to 300x600 or 600x300 using cvResize()
  3. Apply transform: radial, pincushion or sinusoidal
  4. Strech back to 300x300

I never used radial or sinusoidal transforms in openCV so I dont have a piece of code to attach. But you can use cvUndistort2() and see if it is OK. Create window with trackbars with range 0..100. Each trackbar controls parameter of distortion:

static IplImage* srcImage;
static IplImage* dstImage;

static double _camera[9];
static double _dist4Coeff[4];        // This is the transformation matrix
static int _r = 50;   // Radial transform. 50 in range 0..100
static int _tX = 50;  // Tangetial coef in X directio
static int _tY = 50;  // Tangetial coef in Y directio
static int allRange = 50;

// Open windows
cvNamedWindow(winName, 1);

// Add track bars.
cvShowImage(winName, srcImage );
cvCreateTrackbar("Radial", winName, &_r         , 2*allRange, callBackFun);
cvCreateTrackbar("Tang X", winName, &_tX        , 2*allRange, callBackFun);
cvCreateTrackbar("Tang Y", winName, &_tY        , 2*allRange, callBackFun);
callBackFun(0);

// The distortion call back
void callBackFun(int arg){
 CvMat intrCamParamsMat = cvMat( 3, 3, CV_64F, _camera );
 CvMat dist4Coeff       = cvMat( 1, 4, CV_64F, _dist4Coeff );

 // Build distortion coefficients matrix.
 dist4Coeff.data.db[0] = (_r-allRange*1.0)/allRange*1.0;
 dist4Coeff.data.db[1] = (_r-allRange*1.0)/allRange*1.0;
 dist4Coeff.data.db[2] = (_tY-allRange*1.0)/allRange*1.0;
 dist4Coeff.data.db[3] = (_tX-allRange*1.0)/allRange*1.0;

 // Build intrinsic camera parameters matrix.
 intrCamParamsMat.data.db[0] = 587.1769751432448200/2.0;
 intrCamParamsMat.data.db[1] = 0.;
 intrCamParamsMat.data.db[2] = 319.5000000000000000/2.0+0;
 intrCamParamsMat.data.db[3] = 0.;
 intrCamParamsMat.data.db[4] = 591.3189722549362800/2.0;
 intrCamParamsMat.data.db[5] = 239.5000000000000000/2.0+0;
 intrCamParamsMat.data.db[6] = 0.;
 intrCamParamsMat.data.db[7] = 0.;
 intrCamParamsMat.data.db[8] = 1.;

 // Apply transformation
 cvUndistort2( srcImage, dstImage, &intrCamParamsMat, &dist4Coeff );
 cvShowImage( winName, dstImage );
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜