PCL 데이터 PCD 파일을 읽어

--rabbit.pcd 파일 1.pcd

링크 : https://pan.baidu.com/s/1v6mjPjwd7fIqUSjlIGTIGQ
추출 코드 : zspx

새 프로젝트 PCL

같은 디렉토리에 rabbit.pcd 및 pcl.cpp

 

파일을 읽으십시오

(1) 데이터 표시

사용법 #include <iostream> 
사용법 #include <PCL / IO / pcd_io.h> 
사용법 #include <PCL / point_types.h> INT 주 ( INT의 는 argc, 문자 ** argv와) {   // 포인터라는 클라우드 스토리지 XYZ를 만들 포인트 클라우드 데이터의 유형 
    PCL 점 구름 :: <PCL PointXYZ ::> ::의 PTR 구름 ( 새로운 새로운 PCL 점 구름 :: <PCL :: PointXYZ> ); // // * 파일 열기 클라우드 포인트 IF (PCL :: IO :: loadPCDFile <PCL :: PointXYZ> ( " rabbit.pcd " , * 클라우드) == - 1. ) { 
        PCL_ERROR ( " 파일 rabbit.pcd의 \의 N-를 읽을 수 없습니다 " );
        반환 - ( 1


); } 표준 : COUT << " 로드 된 " << cloud-> 폭 * cloud-> 높이 << " 다음 필드 test_pcd.pcd 데이터 포인트 : " << 표준 : ENDL; (size_t와 I = 0 ; I <cloud-> points.size (); ++ I) { 표준 : COUT << " " << cloud-> 포인트 [I] .x를 << " " << cloud- > 포인트 [I] << .Y ' ' << cloud-> 포인트 [I] .Z << " " << 표준 : ENDL;반환 0 ; }

쇼에 파일 데이터 출력

설명 :

  점 구름이 PCL의 기본 클래스입니다, PCL : 점 구름 <PCL :: PointXYZ> ::의 PTR 수있는 공유 포인터 부스트

  데이터 필드 점 구름  

    점 구름 데이터 구조가 있다면, 라인이 점 구름의 데이터 포인트를 나타내는 설정하고, 폭 (INT) 무질서한 경우 비정형 점군 데이터 점군의 수를 나타낸다.

    높이 (INT), 비정형 점군 데이터는, 높이 = 1 인 경우, 점 구름 데이터 구조는 높이 점군 라인의 총 개수를 나타내는 경우가있다.

    점 (표준 : 벡터) 데이터의 동적 배열 PointT 형식으로 저장된다.

  PointXYZ 포인트 만 입체 X, Y, Z 좌표 정보가 포함되어, 가장 일반적인 데이터 형식

    X : 포인트 [I] .x를

  size_t로 정수 저장 정수 레코드 사이즈 (크기)

  points.size ()는 점 구름의 데이터 사이즈를 나타낸다

 (2) 데이터 시각화

사용법 #include <iostream> 
#INCLUDE <PCL / IO / pcd_io.h> 
#INCLUDE <PCL / point_types.h> 
#INCLUDE <PCL / 시각화 / cloud_viewer.h> INT 본체 ( 의 INT 는 argc, 문자 ** ARGV) { 
    PCL : : 점 구름 <PCL :: PointXYZ> ::의 PTR 구름 (  PCL : 점 구름 <PCL :: PointXYZ> ); // // *打开点云文件경우 (PCL :: IO :: loadPCDFile <PCL :: PointXYZ> ( " rabbit.pcd " , * 구름) == - 1 ) { 
        PCL_ERROR ( " 파일 토끼를 읽을 수 없습니다. PCD \ n " );
        



    
    
    (- 1 ); 
    } 
    표준 : COUT << cloud-> points.size () << 표준 : ENDL; 
    PCL :: 시각화 :: CloudViewer 뷰어 ( " 클라우드 뷰어 " ); 
    viewer.showCloud (구름); 
    동안 (! viewer.wasStopped ()) { 

    } 
    시스템 ( " 일시 중지 " );
    반환  0 ; 
}

영업 실적

 바퀴에서 우회전

 배경 색상을 수정

#include<iostream>
#include<pcl/io/pcd_io.h>
#include<pcl/point_types.h>
#include <pcl/visualization/cloud_viewer.h>
void viewerOneOff(pcl::visualization::PCLVisualizer& viewer) {
    viewer.setBackgroundColor(1.0f, 0.5f, 1.0f);
}

int main(int argc, char** argv) {
    pcl::PointCloud<pcl::PointXYZ>::Ptr cloud(new pcl::PointCloud<pcl::PointXYZ>);

    //*打开点云文件
    if (pcl::io::loadPCDFile<pcl::PointXYZ>("rabbit.pcd", *cloud) == -1) {
        PCL_ERROR("Couldn't read file rabbit.pcd\n");
        return(-1);
    }
    std::cout << cloud->points.size() << std::endl;
    pcl::visualization::CloudViewer viewer("cloud viewer");
    viewer.showCloud(cloud);
    viewer.runOnVisualizationThreadOnce(viewerOneOff);
    
    system("pause");
    return 0;
}

 输出文字

#include<iostream>
#include<pcl/io/pcd_io.h>
#include<pcl/point_types.h>
#include <pcl/visualization/cloud_viewer.h>

int user_data;
void viewerOneOff(pcl::visualization::PCLVisualizer& viewer) {
    viewer.setBackgroundColor(1.0f, 0.5f, 1.0f);
}
void
viewerPsycho(pcl::visualization::PCLVisualizer& viewer)
{
    static unsigned count = 0;
    std::stringstream ss;
    ss << "Once per viewer loop: " << count++;
    viewer.removeShape("text", 0);
    viewer.addText(ss.str(), 20, 100, "text", 0);//this is to set the coordination of text "Once per viewer loop:"
    user_data++;
}
int main(int argc, char** argv) {
    pcl::PointCloud<pcl::PointXYZ>::Ptr cloud(new pcl::PointCloud<pcl::PointXYZ>);

    //*打开点云文件
    if (pcl::io::loadPCDFile<pcl::PointXYZ>("rabbit.pcd", *cloud) == -1) {
        PCL_ERROR("Couldn't read file rabbit.pcd\n");
        return(-1);
    }
    std::cout << cloud->points.size() << std::endl;
    pcl::visualization::CloudViewer viewer("cloud viewer");
    viewer.showCloud(cloud);
    viewer.runOnVisualizationThreadOnce(viewerOneOff);
    viewer.runOnVisualizationThread(viewerPsycho);
    system("pause");
    return 0;
}

 

추천

출처www.cnblogs.com/baby123/p/10950907.html