Meshgrid of Matlab to OpenCV [closed]

asked 2013-06-26 08:31:45 -0600

residentelvio gravatar image

updated 2013-06-26 08:33:54 -0600


translating this code from Matlab to C. Code of Matlab:

x = (-cols/2 : (cols/2 - 1))/(cols/2);
y = -(-rows/2 : (rows/2 - 1))/(rows/2);
[x,y] = meshgrid(x,y);

What I did in C/C++ is :

double x[cols],y[rows];
double X[cols][rows], Y[cols][rows];
double epsilon=0.0001;

for(int j=0;j<cols;j++){
 for(int i=-(cols/2);i<=(cols/2)-1;i++){
  x[j]= i/(cols/2);
for(int k=0;k<rows;k++){
  for(int z=-(rows/2);z<=(rows/2)-1;z++){
        y[k]= -z/(rows/2);

for(int i=0;i<cols;i++){
  for(int z=0;z<rows;z++){

Is it right?

edit retag flag offensive reopen merge delete

Closed for the following reason question is not relevant or outdated by sturkmen
close date 2020-11-13 03:51:44.867045


Trying printing first elements of X (X[0][0],X[1][0]...) I have 0 ever. SO it s wrong. Someone know why? X[0][0] must be -1

residentelvio gravatar imageresidentelvio ( 2013-06-26 11:17:31 -0600 )edit

You have posted quite a number of similar questions here - 20, more precisely. Instead of trying to use this forum as a means to find cheap labor for your project, why don't you simply learn C++?

sammy gravatar imagesammy ( 2013-06-27 02:06:08 -0600 )edit

And also use the search function of this Q&A forum, I have answered a similar question a while ago:

Guanta gravatar imageGuanta ( 2013-06-27 02:53:15 -0600 )edit