0

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.

1
  • First, specify the channel: CV_32FC1 or CV_32FC3. And post the relevant code. Commented Dec 19, 2011 at 10:46

1 Answer 1

2

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; } 
Sign up to request clarification or add additional context in comments.

8 Comments

I tried using only Mat initializing the structure with the following statement: Mat or_mat = Mat(img-> height, img-> width, CV_32F); and assign the value as above. The error persists.
You seem to be mixing between using CvMat * and cv::Mat - these are different structures and you should probably choose one or the other.
Note that in the latest documentation CvMat is considered obsolete...
I chose to use cv:: Mat and the code you see. The problem is not when the value is calculated and assigned to the position (i, j ).... causes some problems and does not assign the correct value.
i have correct the post with new code. i use only cv::mat and not Cvmat*
|

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.