Is there a reason to go from 32F to 8U? We are loosing data this way. Also, I would rather than checking for cv_ptr->encoding == "32FC1" have an additional parameter depth=true or a separate function to handle depth images.