Ask Your Question

Revision history [back]

It appears that the double version of Mat::put() you list above allows for casting of the double type data into other types. That would be the root of the difference. In either case, float or double the goal is to write the input data into the output memory locations corresponding to the Mat starting at cell=(row,col).

For the double case, the write operation is performed cell-by-cell with the macro PUT_ITEM() and the consecutive memory locations don't have to be part of a continuous block of memory. This is also where the casting between types is performed. The variable count is converted to the number of bytes that need to be written. There are checks that this count is not larger than the allocated memory. After that there is no need to check it when writing count_number of cells.

For the float case, the memcpy() function is used either for a continuous block of memory or row-by-row. In the row-by-row case, you need to check that the available memory for just that row is sufficient to save the input data for one row. At the very end row, you also need to make sure the remaining input data is going to fill a whole row. So the counting and checking is a little more involved.