c++ - how to obtain undistorted image without interpolation -


i have been trying lot undistorted image without interpolation. when executed below code weird image.i using function initundistortrectifymap gives mapx , mapy of type cv_16sc2 later using convertmaps function converting mapx , mapy type cv_32fc1.i have been trying debug reason couldnot find helpful.

the distorted image image after applying undistort without interpolation

int main() {  mat  cam1matrixparam, cam1distortion;  mat cf1;  cf1=imread("cam1.distort1.jpg", cv_load_image_color);   size imagesize = cf1.size(); filestorage fs1("cameracalibration.xml", filestorage::read);     fs1["camera_matrix"] >> cam1matrixparam;     fs1["distortion_coefficients"] >> cam1distortion;     mat r = mat::eye(3, 3, cv_32f) * 1;     int width = cf1.cols;  int height = cf1.rows; mat undistorted = mat(height, width, cv_8uc3); mat mapx = mat(height, width, cv_32fc1); mat mapy = mat(height, width, cv_32fc1);  initundistortrectifymap(cam1matrixparam, cam1distortion, cam1matrixparam, r, imagesize, cv_16sc2, mapx, mapy); convertmaps(mapx, mapy, mapx, mapy, cv_32fc1, false);      (int j = 0; j < height; j++)     {         ( int = 0; < width; i++)         {         undistorted.at<uchar>(mapy.at<float>(j, i), mapx.at<float>(j, i)) = cf1.at<uchar>(j, i);         }     }     imwrite("cam1.undistortimage.png", undistorted);  } 

image version of code undistorted.at(j, i) = cf1.at(mapy.at(j, i), mapx.at(j, i));

image undistort function(remap nearest interpolation)

it looks instead of undoing distortion applies once more.

mapx , mapy map display coordinates photo coordinates.

undistorted.at<cv::vec3b>(j, i) = distort.at<cv::vec3b>(mapy.at<float>(j, i), mapx.at<float>(j, i)); 

you can interpret code as: each display coordinate {j, i} find corresponding (distorted) coordinate in photo , copy pixel.


Comments

Popular posts from this blog

sequelize.js - Sequelize group by with association includes id -

android - Robolectric "INTERNET permission is required" -

java - Android raising EPERM (Operation not permitted) when attempting to send UDP packet after network connection -