Ask Your Question
0

Problem converting Mat values to float

asked 2013-05-27 14:49:12 -0600

Albert123 gravatar image

Hello,

after i used the SURF-Extractor i got a Mat with all the feature-vectors (one per row). I want to convert thoose vectors (rows of the Mat) into separate float-Attays.

I do this with the following code:

float vec[64];
for(int i=0;i<64;i++)
vec[i]= mat.at<float>(n,i);//the n`th row is written in vec

it works fine so far, but when i look at the original values in mat, using cout << "M = "<< endl << " " << mat << endl << endl; i see floats such as "3.5637853e-005" wich is good.

when i now look at the content of vec, the floats are "shorter", for example "3.5637853e-005" becomes "3.56379e-005".

How can i copy the values form mat to vec without them loosing accuracy?

Thank you.

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
4

answered 2013-05-27 15:01:43 -0600

berak gravatar image

updated 2013-05-27 15:07:48 -0600

don't worry, you're not loosing accuracy that way, it's just a matter of printing

(ie, the << operator for Mat's prints out with a higher precision than usual)


[afterthought: never trust a float beyond the 6'th digit ..]

edit flag offensive delete link more

Comments

1

Thanks :).

Albert123 gravatar imageAlbert123 ( 2013-05-27 15:17:57 -0600 )edit

Question Tools

Stats

Asked: 2013-05-27 14:49:12 -0600

Seen: 429 times

Last updated: May 27 '13