본문 바로가기
Programming Language/Kinect & PCL

PCL 예제 프로그램 짜보기

by 민트초코맛꼬깔콘 2014. 7. 4.

CMakeLists.txt


// cmake의 최소 버젼
cmake_minimum_required(VERSION 2.8 FATAL_ERROR)   

// 프로젝트 이름과 소스 디렉토리의 변수명으로 사용된다.
project(exam)

// PCL의 최소 버젼
find_package(PCL 1.6 REQUIRED)

include_directories(${PCL_INCLUDE_DIRS})
link_directories(${PCL_LIBRARY_DIRS})
add_definitions(${PCL_DEFINITIONS})

// 생성되는 실행 파일 명과 컴파일될 파일 명
add_executable(exam exam.cpp)
target_link_libraries(exam ${PCL_LIBRARIES})




exam.cpp

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

#include <pcl/point_cloud.h>
#include <pcl/io/openni_grabber.h>
#include <pcl/common/time.h>

#include <pcl/visualization/cloud_viewer.h>

using namespace std;
using namespace pcl;
using namespace io;

#ifdef WIN32
# define sleep(x) Sleep((x)*1000)
#endif

class SimpleOpenNIViewer
{
    public:
        SimpleOpenNIViewer () : viewer ("PCL OpenNI Viewer") {}

        void cloud_cb_ (const pcl::PointCloud<pcl::PointXYZ>::ConstPtr &cloud)
        {
            if (!viewer.wasStopped())
                viewer.showCloud (cloud);
        }
        void run ()
        {
            pcl::Grabber* interface = new pcl::OpenNIGrabber();
            boost::function<void (const pcl::PointCloud<pcl::PointXYZ>::ConstPtr&)> f =
                boost::bind (&SimpleOpenNIViewer::cloud_cb_, this, _1);

            interface->registerCallback (f);
            interface->start ();
            while (!viewer.wasStopped())
            {
                sleep (1);
            }

            interface->stop ();
        }
        pcl::visualization::CloudViewer viewer;
};

int main ()
{
    SimpleOpenNIViewer v;
    v.run ();
    return 0;
}

'Programming Language > Kinect & PCL' 카테고리의 다른 글

Trouble Shooting  (0) 2014.09.28
PCL 1.7 설치  (0) 2014.09.15
PCL-1.7 설치 참고 사이트  (0) 2014.09.05
TROUBLE SHOOTING  (0) 2014.08.25
OpenNI, SensorKinect, NITE, PCL 설치  (0) 2014.06.27