opencv pcl 测试代码
python opencv
1 import cv2 2 import numpy as np 3 4 img = cv2.imread("d:\\2.jpg") 5 cv2.imshow("1",img) 6 cv2.waitKey(0) 7 cv2.destroyAllWindows()
Pcl测试代码
1 #include<pcl/visualization/cloud_viewer.h> 2 #include<iostream>//标准C++库中的输入输出类相关头文件。 3 #include<pcl/io/io.h> 4 #include<pcl/io/pcd_io.h>//pcd 读写类相关的头文件。 5 #include<pcl/io/ply_io.h> 6 #include<pcl/point_types.h> //PCL中支持的点类型头文件。 7 int user_data; 8 using std::cout; 9 10 void viewerOneOff(pcl::visualization::PCLVisualizer& viewer) 11 { 12 viewer.setBackgroundColor(1.0, 0.5, 1.0); //设置背景颜色 13 } 14 15 int main() { 16 pcl::PointCloud<pcl::PointXYZ>::Ptr cloud(new pcl::PointCloud<pcl::PointXYZ>); 17 18 char strfilepath[256] = "d:\\rabbit.pcd"; 19 if (-1 == pcl::io::loadPCDFile(strfilepath, *cloud)) { 20 cout << "error input!" << endl; 21 return -1; 22 } 23 24 cout << cloud->points.size() << endl; 25 pcl::visualization::CloudViewer viewer("Cloud Viewer"); //创建viewer对象 26 27 viewer.showCloud(cloud); 28 viewer.runOnVisualizationThreadOnce(viewerOneOff); 29 system("pause"); 30 return 0; 31 }
pcl测试代码2 (不用pcd文件)
1 #include <iostream> 2 #include <pcl/common/common_headers.h> 3 #include <pcl/io/pcd_io.h> 4 #include <pcl/visualization/pcl_visualizer.h> 5 #include <pcl/visualization/cloud_viewer.h> 6 #include <pcl/console/parse.h> 7 8 9 int main(int argc, char **argv) { 10 std::cout << "Test PCL !!!" << std::endl; 11 12 pcl::PointCloud<pcl::PointXYZRGB>::Ptr point_cloud_ptr (new pcl::PointCloud<pcl::PointXYZRGB>); 13 uint8_t r(255), g(15), b(15); 14 for (float z(-1.0); z <= 1.0; z += 0.05) 15 { 16 for (float angle(0.0); angle <= 360.0; angle += 5.0) 17 { 18 pcl::PointXYZRGB point; 19 point.x = 0.5 * cosf (pcl::deg2rad(angle)); 20 point.y = sinf (pcl::deg2rad(angle)); 21 point.z = z; 22 uint32_t rgb = (static_cast<uint32_t>(r) << 16 | 23 static_cast<uint32_t>(g) << 8 | static_cast<uint32_t>(b)); 24 point.rgb = *reinterpret_cast<float*>(&rgb); 25 point_cloud_ptr->points.push_back (point); 26 } 27 if (z < 0.0) 28 { 29 r -= 12; 30 g += 12; 31 } 32 else 33 { 34 g -= 12; 35 b += 12; 36 } 37 } 38 point_cloud_ptr->width = (int) point_cloud_ptr->points.size (); 39 point_cloud_ptr->height = 1; 40 41 pcl::visualization::CloudViewer viewer ("test"); 42 viewer.showCloud(point_cloud_ptr); 43 while (!viewer.wasStopped()){ }; 44 return 0; 45 }
c++ opencv读取一张图片
1 #include<iostream> 2 #include <opencv2/core/core.hpp> 3 #include <opencv2/highgui/highgui.hpp> 4 5 using namespace cv; 6 7 int main() 8 { 9 // 读入一张图片(游戏原画) 10 Mat img=imread("D:\\2.jpg"); 11 // 创建一个名为 "游戏原画"窗口 12 namedWindow("游戏原画"); 13 // 在窗口中显示游戏原画 14 imshow("游戏原画",img); 15 // 等待6000 ms后窗口自动关闭 16 waitKey(0); 17 }