cv::Mat to nav_msgs::OccupancyGrid by vector assign
Currently converting cv::Mat to OccupancyGrid by for loop
occupancy_grid->data.reserve(cv_image.rows * cv_image.cols);
for (int x = cv_image.cols - 1; x >= 0; x--) {
for (int y = cv_image.rows - 1; y >= 0; y--) {
const unsigned char intensity = cv_image.at<unsigned char>(y, x);
occupancy_grid->data.push_back(intensity);
}
}
According to this post in stackoverflow , it could be written in this way
if(cv_image.isContinuous()){
occupancy_grid->data.assign(cv_image.data, cv_image.data + cv_image.total());
}
However, occupancy_grid data converted by assign
is not the same one I got from for loop
method.
Anybody know what went wrong here?