Ask Your Question

Problem converting Mat values to float

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

Albert123 gravatar image


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]=<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

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

berak gravatar image

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

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



Thanks :).

Albert123 gravatar imageAlbert123 ( 2013-05-27 15:17:57 -0500 )edit
Login/Signup to Answer

Question Tools


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

Seen: 112 times

Last updated: May 27 '13