Is there a meshgrid function in OpenCV?
Is there a function in OpenCV that is analogous to the meshgrid function in matlab? If not, what would be the best way of attaining similar functionality?
Is there a function in OpenCV that is analogous to the meshgrid function in matlab? If not, what would be the best way of attaining similar functionality?
Afaik this method doesn't exist, but I guess cv::repeat
(http://docs.opencv.org/modules/core/doc/operations_on_arrays.html?highlight=repeat#repeat)
is what you are searching.
I don't know much about matlab, so maybe I got the function wrong, but I tried to kinda re-build the example shown at http://www.mathworks.de/de/help/matlab/ref/meshgrid.html:
#include <opencv2/core/core.hpp>
#include <iostream>
static void meshgrid(const cv::Mat &xgv, const cv::Mat &ygv,
cv::Mat1i &X, cv::Mat1i &Y)
{
cv::repeat(xgv.reshape(1,1), ygv.total(), 1, X);
cv::repeat(ygv.reshape(1,1).t(), 1, xgv.total(), Y);
}
// helper function (maybe that goes somehow easier)
static void meshgridTest(const cv::Range &xgv, const cv::Range &ygv,
cv::Mat1i &X, cv::Mat1i &Y)
{
std::vector<int> t_x, t_y;
for (int i = xgv.start; i <= xgv.end; i++) t_x.push_back(i);
for (int i = ygv.start; i <= ygv.end; i++) t_y.push_back(i);
meshgrid(cv::Mat(t_x), cv::Mat(t_y), X, Y);
}
// Small test-main
int main(int argc, char** argv) {
cv::Mat1i X, Y;
meshgridTest(cv::Range(1,3), cv::Range(10, 14), X, Y);
std::cerr << X << std::endl;
std::cerr << Y << std::endl;
return 0;
}
Output
[1, 2, 3;
1, 2, 3;
1, 2, 3;
1, 2, 3;
1, 2, 3]
[10, 10, 10;
11, 11, 11;
12, 12, 12;
13, 13, 13;
14, 14, 14]
Asked: 2013-04-16 15:31:22 -0600
Seen: 14,163 times
Last updated: Apr 16 '13
Is stereoRectifyUncalibrated efficient?
Conversion between IplImage and MxArray
OpenCV and Latent SVM Detector
implementation of feature selection using adaboost
image registration using fft [closed]
compiling openCV cpp files in matlab with mex
missing cv::Mat::zeros(int ndims, const int* sz, int type)