Ask Your Question

Revision history [back]

Hey Carlos, I'm using your code but I want to compare the results with the ones I obtained using MATLAB. In my main function, I have:

int i, k;
Mat img;
pair<Mat,Mat> grad;
img = imread("path_to_folder", CV_LOAD_IMAGE_COLOR);
img.convertTo(img, CV_64F); //Convert image to double precision
grad = gradient(img, 1.0, 1.0);
Mat_<double> gradX = grad.first;
for(i=0; i<gradX.rows; i++) {
    for(k=0; k<gradX.cols; k++) {
       cout << gradX[i][k] << " ";
    }
    cout << endl;
}

But I get an error when I run the code (when I try to print the values). What am I doing wrong? I know this is an easy question but I just started to develop code in c++ a few days ago. Thanks for your help.

Hey Carlos, I'm using your code but I want to compare the results with the ones I obtained using MATLAB. In my main function, I have:

int i, k;
Mat img;
pair<Mat,Mat> grad;
img = imread("path_to_folder", CV_LOAD_IMAGE_COLOR);
img.convertTo(img, CV_64F); //Convert image to double precision
precision (in MATLAB we have to use im2double before calling the gradient function)
grad = gradient(img, 1.0, 1.0);
Mat_<double> gradX = grad.first;
for(i=0; i<gradX.rows; i++) {
    for(k=0; k<gradX.cols; k++) {
       cout << gradX[i][k] << " ";
    }
    cout << endl;
}

But I get an error when I run the code (when I try to print the values). What am I doing wrong? I know this is an easy question but I just started to develop code in c++ a few days ago. Thanks for your help.