Debug

debug:
函数重载(overload)时,注意在头文件中,不要加大括号,加大括号意味着函数已经被定义过。
功能复杂时,并且有很多类似功能时,注意定义清楚名字并理清相互关系,建议先在纸上把关系罗列清楚再写代码。

One article on google said that for cv::Mat, raw pointer access is the fastest access to pixels, and using of .ptr() will give it more safety for we do not have to ensure the segment is continous. But I tried on ubuntu, it may not be correct. for using .ptr() like :

for (int i = 0; i < map_height; ++i) {
uchar* image_pointer = image_yutian_probablity.ptr(i);
for (int j = 0; j < map_length; ++j) {
uchar* pixel_pointer = image_pointer;
if (ros_map[i][j] == -1) {
// pixel_pointer[0] = 255;
image_yutian_probablity.atcv::Vec3b(i, j)[0] = 0;
} else if (ros_map[i][j] == 1) {
// pixel_pointer[1] = 0;
image_yutian_probablity.atcv::Vec3b(i, j)[1] = 255;
} else if (ros_map[i][j] == 0) {
// pixel_pointer[2] = 0;
image_yutian_probablity.atcv::Vec3b(i, j)[2] = 255;
}
image_pointer += 3;
}
}
errors like:
Segmentation fault (core dumped)
terminate called after throwing an instance of ‘std::bad_alloc’
what(): std::bad_alloc
Aborted (core dumped)
will appear

I do not know why, but I tried to use .at method. It appears to be faster than the raw pointer and doesn’t encounter any errors anymore.
I do not know why, it’s a problem to be solved.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值