简体   繁体   中英

assignment error with Mat OpenCv

I am working with OpenCV and C++ for a project and I found the following problem: after initializing a mat with the following statement

Mat or_mat=Mat(img->height,img->width,CV_32FC1);

check the following value

or_mat.at <float> (i, j) = atan (fy / fx) / 2 +1.5707963;

After completing returning the mat for the output of the function but when I go to read there are many values ​​that do not correspond to the output. Precise in incorrect values ​​for the I-4.31602e +008 is inserted and if I make a cout the value of the expression is correct. What could be the error??

relevant Code:

Mat or_mat=Mat(img->height,img->width,CV_32FC1);

to angle
if(fx > 0){   
    or_mat.at<float>(i,j) = atan(fy/fx)/2+1.5707963;
}
else if(fx<0 && fy >0){   
    or_mat.at<float>(i,j) = atan(fy/fx)/2+3.1415926;
}
else if(fx<0 && fy <0){   
    or_mat.at<float>(i,j) = atan(fy/fx)/2;
}
else if(fy!=0 && fx==0){   
    or_mat.at<float>(i,j) = 1.5707963;
}

I have to calculate the local orientation of the fingerprint image, the following code I have omitted several statements and calculations that do not have errors.

I would triple check that you are indexing correctly. The following code shows my initialising a matrix full of zeros, and then filling it with some float using at .at operator. It compiles and runs nicely:

int main()
{

    int height = 10;
    int width = 3;

    // Initialise or_mat to with every element set to zero
    cv::Mat or_mat = cv::Mat::zeros(height, width, CV_32FC1);
    std::cout << "Original or_mat:\n" << or_mat << std::endl;

    // Loop through and set each element equal to some float
    float value = 10.254;
    for (int i = 0; i < or_mat.rows; ++i)
    {
        for (int j = 0; j < or_mat.cols; ++j)
        {
            or_mat.at<float>(i,j) = value;
        }
    }

    std::cout << "Final or_mat:\n" << or_mat << std::endl;

    return 0;
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM