Structure from Motion Visualizer
Asked Answered
M

1

0

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; 
}
Matsuyama answered 2/7, 2015 at 14:5 Comment(2)
Literally the first link when I searched "pcl::PointXYZRGB"African
Thank you very much for the replay. I have pointcloud of type point3d and in that function they also used pointcloud_RGB of type vec3d, so I am asking what is there in pointcloud_RGB because they did say anything about it, so I am confused. Sorry If i didn't understand you ( I am not good in PCL).Matsuyama
H
0

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.

Hardened answered 3/7, 2015 at 12:5 Comment(3)
Thank you very much for the comment. I am getting 7.0e008 re-projection error of 3d point cloud, do you think it is very huge ?Matsuyama
It seems quite big. You can examine your point cloud; you're supposed to obtain a 3D model of your object of interest after all.Hardened
Thank you very much for the replay, My visualized pointcloud is weird. Can you send your email ? I would like to discuss more with you.Matsuyama

© 2022 - 2024 — McMap. All rights reserved.