Is it similar to the cv::remap reprojection mapping function in opencv in matlab?
11 views (last 30 days)
Show older comments
cui,xingxing
on 24 Jun 2022
Answered: cui,xingxing
on 14 Oct 2022
As far as I know, I know interp2,interp,griddata,scatteredInterpolant and other functions can achieve my non-aligned regular grid data for mapping, but the efficiency is very low, on the contrary, the remap function in opencv is very fast and only does mapping projection. For example, I have the following non-gridded data points, known v = F(x,y), where x,y are non-regular data, I try to use scatteredInterpolant function for interpolation, but the computation time is up to several seconds.
My (x,y) coordinates data is in the following form:
load data.mat
validPtsX = double(validPtsX);
validPtsY = double(validPtsY);
[qX,qY] = meshgrid(1:W,1:H);
F = scatteredInterpolant(validPtsX(:),validPtsY(:),oriImg(:));
tic
undistortImg1 = F(qX,qY); % took too long !
toc
undistortImg2 = interp2(validPtsX,validPtsY,oriImg,qX,qY,"linear",0);% error: Grid arrays must have NDGRID structure.
However, I can quickly get my interpolated mapped image in OpenCV by using the following statement:
cv::Mat undistortImg;
cv::remap(oriImg, undistortImg, mapX, mapY, cv::INTER_LINEAR); // Supports both grid and non-grid data mapping
update:
It is verified that the interp2 function has equivalent mapping power and execution speed to the cv::remap function when the mapping matrix mapX,mapY (or called queryX,queryY) is computed in advance!
undistortImg = interp2(img,mapX,mapY,"linear",0);% 等价OpenCV的cv::remap函数,速度在各自环境下等价一致!
1 Comment
Walter Roberson
on 24 Jun 2022
https://www.mathworks.com/discovery/matlab-opencv.html allows calling into OpenCV .
Accepted Answer
More Answers (1)
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!