laxnpander / OpenREALM

OpenREALM is a pipeline for real-time aerial mapping utilizing visual SLAM and 3D reconstruction frameworks.
GNU Lesser General Public License v2.1
443 stars 114 forks source link

What's the mean of this code? #77

Closed GY56723-debug closed 1 year ago

GY56723-debug commented 1 year ago

I’m a novice of slam. when i read the this code, I can't realize what it means:

cv::Mat mask; if (to.type() == CV_32F || to.type() == CV_64F) mask = (to != to) & (from == from); else mask = (to == 0) & (from > 0);

This segment appear in this function:

void CvGridMap::mergeMatrices(const cv::Mat &from, cv::Mat &to, int flag_merge_handling) { switch(flag_merge_handling) { case REALM_OVERWRITE_ALL: to = from; break; case REALM_OVERWRITE_ZERO: cv::Mat mask; if (to.type() == CV_32F || to.type() == CV_64F) mask = (to != to) & (from == from); else mask = (to == 0) & (from > 0); from.copyTo(to, mask); break; } }

If you responce, i would appreciate it

laxnpander commented 1 year ago

@GY56723-debug Hey, this is not SLAM related. This is just logical operators with one speciality: to != to checks if the matrix "to" is not equal to matrix "to". So it is basically a comparison with itself. The speciality here is: We check for NaNs. As per C++ standard definition comparing a NaN with itself gives false in the logical world.

The whole purpose of this function is to merge two layers (matrices) in a grid map.

A grid map is the result of the mapping process, one layer could be RGB for example. Another one contains the elevation etc.

GY56723-debug commented 1 year ago

Thanks, I understand now

laxnpander commented 1 year ago

@GY56723-debug You are welcome! Reopen if questions persist.