1 | initial version |
you should use remap to model arbitrary distortions. it will also give you the interpolation for free.
Mat img = imread("img/grid.jpg");
int width = img.cols;
int height = img.rows;
// setup distortion mapping:
Mat_<Vec2f> prjMap(height, width);
for (int x=0; x<width; x++) {
for (int y=0; y<height; y++) {
float u = x + sin(float(y)/100)*15; // some funny formula ..
float v = y + cos(float(x)/100)*20;
prjMap(y, x) = Vec2f(u,v);
}
}
// apply distortion to image:
Mat projected;
remap(img, projected, prjMap, cv::Mat(), INTER_LINEAR);
imshow("P", projected);
waitKey();
2 | No.2 Revision |
you should use remap to model arbitrary distortions. it will also give you the handle interpolation and borders for free.
Mat img = imread("img/grid.jpg");
int width = img.cols;
int height = img.rows;
// setup distortion mapping:
Mat_<Vec2f> prjMap(height, width);
for (int x=0; x<width; x++) {
for (int y=0; y<height; y++) {
float u = x + sin(float(y)/100)*15; // some funny formula ..
float v = y + cos(float(x)/100)*20;
prjMap(y, x) = Vec2f(u,v);
}
}
// apply distortion to image:
Mat projected;
remap(img, projected, prjMap, cv::Mat(), INTER_LINEAR);
imshow("P", projected);
waitKey();
3 | No.3 Revision |
you should use remap to model arbitrary distortions. it will also handle interpolation and borders for free.
Mat img = imread("img/grid.jpg");
int width = img.cols;
int height = img.rows;
// setup distortion mapping:
Mat_<Vec2f> prjMap(height, width);
for (int x=0; x<width; x++) {
for (int y=0; y<height; y++) {
float u = x + sin(float(y)/100)*15; // some funny formula ..
float v = y + cos(float(x)/100)*20;
prjMap(y, x) = Vec2f(u,v);
}
}
// apply distortion to image:
Mat projected;
remap(img, projected, prjMap, cv::Mat(), INTER_LINEAR);
INTER_LINEAR, BORDER_CONSTANT); // play with flags !
imshow("P", projected);
waitKey();