song
song

Reputation: 163

change CV_32FC1 to CV_64FC1 result incorrect data conversion

I attempted to initialise an Mat object in OpenCV with a 2D float array. I set the data type of the Mat as CV_64FC1 and then print out the Mat. The print out result is different to the initialisation 2D array.

void testConversion()
{  float data[10][2] = 
 {
    {2.5,   2.4},
    {0.5,   0.7},
    {2.2,   2.9},
    {1.9,   2.2},
    {3.1,   3.0},
    {2.3,   2.7},
    {2,     1.6},
    {1,     1.1},
    {1.5,   1.6},
    {1.1,   0.9}
 };


  Mat
     mData(10,2,CV_64FC1,&data);
   cout<<"mData\n"<< mData <<endl;

  return;
 }

The result print out display as:

[6.400002481415868, 0.0002929687607320375;
 25.60000992119312, 3.600000857934356;
 32.00000766217708, 14.40000343546271;
 0.2250000536441803, 0.01406250333820935;
 0.225000053527765, 0.002734374717329047;
 2.541574442831658e-173, 1.956130224762901e-304;
2.779084519612415e-308, 7.165336730703368e-317;
 1.#QNAN, -9.255963134931783e+061;
 -9.255963134931783e+061, -9.255963134931783e+061;
 -9.255963134931783e+061, -9.255963134931783e+061] 

It only works if I change

Mat
 mData(10,2,CV_64FC1,&data);

to

Mat
 mData(10,2,CV_32FC1,&data);

Could someone explains why? Thanks in advance.

Upvotes: 0

Views: 325

Answers (1)

ibezito
ibezito

Reputation: 5822

The reason for your problem is a mismatch between the type of your array (float), and the OpenCV's type parameter CV_64FC1.

The parameter CV_64FC1 determines that the data array should be treated as an array of doubles, 64 bits per value.

Youir array however, has a type of float, which has 32 bits per value. Therefore, using CV_32FC1 is the proper usage in this case.

Upvotes: 1

Related Questions