Ask Your Question

pmendozav's profile - activity

2017-07-11 16:15:07 -0500 commented answer How to compile nonfree module in opencv 3.0 beta ?

you should check the flag OPENCV_ENABLE_NON_FREE before generate the solution in cmake

2014-02-11 15:26:20 -0500 asked a question Assign bytes within of Mat with float values

I need assign values in M (a variable type Mat) with values CV_32FC1 (float), but is long time at size of 10000x10000. i.e:

for (i=0 ; i < rows; i++)  
   for (j=0 ; j < cols; j++)
   ...build variable NEW_VALUE for indexes i, j
      M.at<float>(i,j) = NEW_VALUE
   }

the code above required 1 second aprox. Other form I see, is defining a union (copy bytes):

typedef union{float _float;  uchar _uchar[4];} Bits;
...
Bits bits;
float new_value;
for (i=0 ; i<rows; i++)
  for (j=0 ; j<cols; j+=4){
     ...//build variable new_value for indexes i, j
     bits._float = new_value;
     M.data[i ** cols + j] = bits._uchar[0];
     M.data[i ** cols + j+1] = bits._uchar[1];
     M.data[i ** cols + j+2] = bits._uchar[2];
     M.data[i ** cols + j+3] = bits._uchar[3];
  }

That is much faster that first. But not working. I tried doing:

memcpy(&M.data[i ** cols + j], bits._uchar[0], 1);
memcpy(&M.data[i ** cols + j+1], bits._uchar[1], 1);
...

But not working. And:

memcpy(&M.at<float>(i,j), bits._uchar, 4);

is very slow also. I need to know how to copy the bytes of the new_value correctly within of M.