简体   繁体   中英

Structure from Motion Visualizer

I am working on Structure from Motion. I think when it come to structure from motion, people would have came across MultiView Geometry book. It is a very good book but I found something confusing data in that book. In the below following code, there is function called Populate point cloud, which has two parameter pointcloud and pointcloud_RGB. I have point3d type values in pointcloud but I didn't find anything about pointcloud_RGB in that book and it suddenly appears in this function, which is used to fill the VEC3d rgbv. Can some one please help who came across this book.

void PopulatePCLPointCloud(const vector<cv::Point3d>& pointcloud, 
  const std::vector<cv::Vec3b>& pointcloud_RGB = std::vector<cv::Vec3b>() 
) 

{ 
cout<<"Creating point cloud..."; 
cloud.reset(new pcl::PointCloud<pcl::PointXYZRGB>); 

for (unsigned int i=0; i<pointcloud.size(); i++) { 
// get the RGB color value for the point 
        cv::Vec3b rgbv(255,255,255); 

if (i < pointcloud_RGB.size()) { 
rgbv = pointcloud_RGB[i]; 
} 

        // check for erroneous coordinates (NaN, Inf, etc.) 
                if (pointcloud[i].x != pointcloud[i].x || 
                        pointcloud[i].y != pointcloud[i].y || 
                        pointcloud[i].z != pointcloud[i].z || 
#ifndef WIN32 
                        isnan(pointcloud[i].x) || 
                        isnan(pointcloud[i].y) || 
                        isnan(pointcloud[i].z) || 
#else 
                        _isnan(pointcloud[i].x) || 
                        _isnan(pointcloud[i].y) || 
                        _isnan(pointcloud[i].z) || 
                        false 
                        ) 
                { 
                        continue; 
                } 
pcl::PointXYZRGB pclp; 
pclp.x = pointcloud[i].x; 
pclp.y = pointcloud[i].y; 
pclp.z = pointcloud[i].z; 
// RGB color, needs to be represented as an integer 
uint32_t rgb = ((uint32_t)rgbv[2] << 16 | (uint32_t)rgbv[1] << 8 | 
(uint32_t)rgbv[0]); 
pclp.rgb = *reinterpret_cast<float*>(&rgb); 
cloud->push_back(pclp); 
} 
cloud->width = (uint32_t) cloud->points.size(); // number of points 
cloud->height = 1; // a list of points, one row of data 

//Create visualizer 

pcl::visualization::CloudViewer viewer ("Simple Cloud Viewer"); 
viewer.showCloud (cloud); 

                 cv::waitKey(0); 
                 return; 
}

I believe this is the code snippet from MasteringOpenCV - Chapter 4. I've checked the whole project and it appears that this is some sort of a bug pointcloud_RGB is defined at

const std::vector<cv::Vec3b>& pointcloud_RGB = std::vector<cv::Vec3b>()

and no value is assigned except here;

rgbv = pointcloud_RGB[i];

and this is under the condition of

if (i < pointcloud_RGB.size())

the program would never go into this if since pointcloud_RGB is empty and therefore cannot be bigger than i. That's why it should run without any problems.

The real point cloud is pcl::PointXYZRGB pclp; and it is filled in here with XYZ coordinates + RGB values;

pcl::PointXYZRGB pclp; 
pclp.x = pointcloud[i].x; 
pclp.y = pointcloud[i].y; 
pclp.z = pointcloud[i].z; 
// RGB color, needs to be represented as an integer 
uint32_t rgb = ((uint32_t)rgbv[2] << 16 | (uint32_t)rgbv[1] << 8 | 
(uint32_t)rgbv[0]); 

Of course there's always the possibility of sending an e-mail to the author and ask for a clarification.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM