在加速一些进程(无法命名,抱歉)的过程中,我尝试创建一个
cv::Mat_<uchar> discretization;现在,当我在float中获得深度图时
cv::Mat_<float> depth_map;
discretization = depth_map / resolution_mtr;其中resolution_mtr是一个浮点数。目前取值为0.1。当我这样做时,对于深度图中的一个值,比如说0.48,我得到的离散化值是5,我的理解是它应该是4。我猜它是四舍五入到最近的uchar。有没有办法在不进入for循环的情况下解决这个问题?基本上,我希望在离散化中使用下限值,而不是舍入。
发布于 2013-03-12 23:36:22
为什么不定义一个继承的类CvNoRoundMat并覆盖它的operator+呢?
发布于 2013-03-13 05:12:01
你可以从结果中减去0.5。
这段代码
float resolution_mtr = 0.1;
float vals[] = {0.48, 0.4, 0.38, 0.31};
cv::Mat_<float> depth_map(1,4,vals);
cv::Mat_<uchar> discretization( depth_map / resolution_mtr - 0.5);
std::cout << "depth_map: " << depth_map << std::endl;
std::cout << "discretization: " << discretization << std::endl; 将为您提供以下结果:
depth_map: [0.47999999, 0.40000001, 0.38, 0.31]
discretization: [4, 4, 3, 3]https://stackoverflow.com/questions/15363762
复制相似问题