#include <pcl/visualization/cloud_viewer.h>
#include <iostream>
#include <pcl/io/io.h>
#include <pcl/io/pcd_io.h>
#include<opencv2\highgui\highgui.hpp>
#include<opencv2\imgproc\imgproc.hpp>
int user_data;
void viewerOneOff (pcl::visualization::PCLVisualizer& viewer)
{
viewer.setBackgroundColor (0.0, 0.0, 0.0);
}
void viewerPsycho (pcl::visualization::PCLVisualizer& viewer)
{
user_data = 9;
}
int main ()
{
pcl::PointCloud<pcl::PointXYZRGB> cloud_a;
pcl::PointCloud<pcl::PointXYZRGB>::Ptr cloud (new pcl::PointCloud<pcl::PointXYZRGB>);
cv::Mat image = cv::imread("1.jpg");
cv::imshow("1", image);
cv::waitKey(0);
if (image.empty())
{
return 0;
}
int rowNumber = image.rows;
int colNumber = image.cols;
cloud_a.width = rowNumber;
cloud_a.height = colNumber;
cloud_a.points.resize(cloud_a.width*cloud_a.height);
cv::Mat_<cv::Vec3b>::iterator it = image.begin<cv::Vec3b>();
cv::Mat_<cv::Vec3b>::iterator itend = image.end<cv::Vec3b>();
for(unsigned int i=0; i<cloud_a.points.size(); ++i)
{
cloud_a.points[i].x = 1024*rand()/(RAND_MAX+1.0f);
cloud_a.points[i].y = 1024*rand()/(RAND_MAX+1.0f);
cloud_a.points[i].z = 1024*rand()/(RAND_MAX+1.0f);
cloud_a.points[i].r = (int) (*it)[2];
cloud_a.points[i].g = (int) (*it)[1];
cloud_a.points[i].b = (int) (*it)[0];
++it;
}
*cloud = cloud_a;
pcl::visualization::CloudViewer viewer("Cloud Viewer");
viewer.showCloud(cloud);
viewer.runOnVisualizationThreadOnce (viewerOneOff);
viewer.runOnVisualizationThread (viewerPsycho);
while (!viewer.wasStopped ())
{
user_data = 9;
}
return 0;
}
//release 的依赖项也被添加进去了,造成了imread读不进去图片,一直报错
cv::Mat_<cv::Vec3b>::iterator it = image.begin<cv::Vec3b>();
cv::Mat_<cv::Vec3b>::iterator itend = image.end<cv::Vec3b>(); 这两句出错的地方