[英]offset converting float to uchar in cv::Mat
In process of speeding up some processes (can't name them, sorry), I tried to create a 在加快某些流程的过程中(无法命名,抱歉),我尝试创建一个
cv::Mat_<uchar> discretization;
Now when I get a depth map in float 现在当我在浮动中获得深度图时
cv::Mat_<float> depth_map;
discretization = depth_map / resolution_mtr;
where resolution_mtr is a float. 其中resolution_mtr是浮点数。 Its value is 0.1 currently.
当前值为0.1。 When I do this, for a value say, 0.48 in depth map , I get the discretization value of 5. My understanding says it should be 4 .
当我执行此操作时,对于深度图为0.48的值,我得到的离散化值为5。我的理解是应该为4。 I guess it is round off to nearest uchar.
我想这是四舍五入到最近的uchar。 Is there a way out of this without getting into for loop ?
有没有办法解决这个问题而无需进入for循环? Basically I want to use floor values in discretization and not round off .
基本上我想在离散化中使用下限值,而不是四舍五入。
为什么不定义继承的类CvNoRoundMat并覆盖其operator +?
You can just subtract 0.5 from the result. 您可以从结果中减去0.5。
This code 这段代码
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;
will give you following results: 将为您提供以下结果:
depth_map: [0.47999999, 0.40000001, 0.38, 0.31]
discretization: [4, 4, 3, 3]
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.