I work with a depth map obtained from two images (I took it from opencv StereoBM), and now I need to find clusters in them. I decided to use segment segmentation pcl http://www.pointclouds.org/documentation/tutorials/region_growing_segmentation.php . I converted cv :: Mat to a point cloud after reading this article http://blog.martinperis.com/2012/01/3d-reconstruction-with-opencv-and-point.html and now I have cluster indexes. These are functions here https://gist.github.com/Daiver/5586252 Now I want to use these indices to display clusters on a depth map with StereoBM (cv :: Mat)
I am trying to do this, but I am not satisfied with the results
pcl::PointCloud<pcl::PointXYZRGB>::Ptr cloud; //cloud from depth map and rgb image std::vector <pcl::PointIndices> clusters;// clusters inices, extracted before for(int j = 0; j < clusters.size(); j++) { cv::Mat to_show = cv::Mat::zeros(288, 384, cv::DataType<uchar>::type);//image has size that equal size of rgb image and depth map for(int i = 0; i < clusters[j].indices.size(); i++) { to_show.data[clusters[j].indices[i]] = 200;// regions in this Mat must be equal with regions from depth map } cv::imshow("", to_show); cv::waitKey(); }
Result Some Clusters
Another cluster 
Visualized cloud 
How can I design clusters in cv :: Mat? PS sorry for my written mistakes. English in my native language
UPD I tried to βrestoreβ the depth map using loops similar to loops in the mat_to_cloud function.
int counter = 0; cv::Mat to_show = cv::Mat::zeros(288, 384, cv::DataType<uchar>::type); for(int i = 0; i < cloud->height; i++) { for(int j = 0; j < cloud->width; j++) { to_show.at<uchar>(i, j) = cloud->at(counter).z; counter++; } }

And one more order of cycles int counter = 0; cv :: Mat to_show = cv :: Mat :: zeros (288, 384, cv :: DataType :: type); for (int j = 0; j <cloud-> width; j ++) {for (int i = 0; i <cloud-> height; i ++) {to_show.at (i, j) = cloud-> at (counter) .z; Counter ++; }}

I do not know why this image looks like
source share