åºå ž http://robotica.unileon.es/index.php/PCL/OpenNI_tutorial_1:_Installing_and_testing
ãã®äžé£ã®ãã¥ãŒããªã¢ã«ã§ã¯ããçå£ãªãç 究ç®çã®ããã«ãKinectã®ãããªæ·±åºŠã«ã¡ã©ã®äœ¿ãæ¹ã«ã€ããŠèª¬æããããåãã®ããã«ãKinectã¯å®éã«ã¯èµ€å€å ãã¿ãŒã³ç §å°æ¹åŒ(Infraarred Structured Light Method)ã«åºã¥ããŠPrimeSenseã®æè¡ã§éçºãããæé ãªäŸ¡æ Œã®æ·±åºŠã»ã³ãµãŒã§ããããŸããæ®éã®ã«ã¡ã©ãä»éããŠããïŒããã«ããKinectã¯RGB-Dããã€ã¹ã«ãªãïŒããã€ã¯ãé»åå転軞(ãããã)ãåããŠããããã®äœ¿çšã¯Xbox360ã³ã³ãœãŒã«ã§ã®ãã¬ã€ã«éå®ããããã³ã³ãã¥ãŒã¿ã«æ¥ç¶ããŠä»ã®ã»ã³ãµãŒãšåæ§ã«äœ¿çšã§ãããå€ãã®ãªãŒãã³ãœãŒã¹ã®ãã©ã€ããšãã¬ãŒã ã¯ãŒã¯ãå©çšå¯èœã§ããã
2010幎11æã«ãªãªãŒã¹ãããŠä»¥æ¥ãç¹ã«ç§åŠç 究ã®éã§å€ãã®äººæ°ãåŸãŠãããäœã³ã¹ãïŒçŽ1äžåïŒã«ããããããã深床æç¥ãããžã§ã¯ãã®ããã®åŒ·åãªè§£æ±ºçã§ããããšã蚌æãããŠãããããå€ãã®ç 究ã§äœ¿ãããŠããã調æ»ã«ããã°ããªã¢ã«ã¿ã€ã ã®ãµãŒãã§ã¹ãããã³ã°ãç©äœèªèãšè¿œè·¡ãäœçœ®æšå®ã«çŠç¹ãåœãŠãããŠããã ïŒMicrosoftã®KinectFusionãããžã§ã¯ãã®ãããªïŒå°è±¡çãªçµæãåŸãããŠããã
æ°ããXbox Oneã«ã¯ãé¡ã®è¡šæ ãæ€åºããå¿ææ°ã枬å®ããæã®ãã¹ãŠã远跡ããããšãã§ããé«åºŠãªè§£å床ãåããã¢ããã°ã¬ãŒãçKinect v2ãä»å±ããŠããã 2014幎7æã«PCéçºå¯Ÿå¿çïŒKinect for Windows v2ïŒããªãªãŒã¹ãããããå ¬åŒã®Windows SDKïŒãªãŒãã³ãœãŒã¹ã®ãµããŒãã¯ããããŸã æªçã§ããïŒã§ã®ã¿äœ¿çšã§ããã 2014幎10æã«æšæºã®Kinect v2ãPCã«æ¥ç¶ã§ããã¢ããã¿ããªãªãŒã¹ãããã®ã§ã2015幎4æã«éçºããŒãžã§ã³ã®ã»ã³ãµãå»æ¢ããããã³ã³ãœãŒã«ãšã¢ããã¿ã®æšæºåãè³Œå ¥ã§ããã
ããã§ã¯ãæ®éã®PCã«ãã¬ã¬ã·ãŒãKinect 1.0ããã€ã¹ãã€ã³ã¹ããŒã«ããæ¹æ³ãšäœ¿çšæ³ãããã³ãã®å¯èœæ§ã«ã€ããŠèª¬æããããããè²·ã£ãã°ããã®åŠçã察象ãšããŠãããããããåºç€ãã説æããã
䜿çšããäºå®ã®ãœãããŠã§ã¢ïŒPoint Cloud LibraryãšOpenNIãã©ã€ãïŒã¯ãäžè¡ã®å€æŽãå¿ èŠãªããASUSã®Xtion PROãXtion PRO LIVEã®ãããªä»ã®ããã€ã¹ã§ã䜿çšã§ããããšãèŠããŠãããïŒPROã«ã¯æ·±åºŠã»ã³ãµãŒãPRO LIVE RGB-Dã«ã¡ã©ã§ããïŒã
泚ïŒãã¥ãŒããªã¢ã«ã¯Linuxãã©ãããã©ãŒã çšã§ããããŸãã64ãããçã¯32ãããçãããåªããŠããããã§ããã
次ã®ãã®ãå¿ èŠã«ãªãïŒ
泚æïŒKinect for Windowsã¯ãLinuxäžã®ãªãŒãã³ãœãŒã¹ãã©ã€ãã§åäœããéã«ãåé¡ãèµ·ããããšãããã
Kinectã¯äžè¬çãªUSBããŒãã§ã¯åäœããªãã ã¢ãŒã¿ãŒãããã®ã§ãã®æ¶è²»é»åã¯å°ã倧ãããããMicrosoftã¯USBãšé»æºãçµã¿åãããã³ãã¯ã¿ã䜿çšããŠããã å€ãXbox 360ã¢ãã«ã«ã¯ç¹å¥ãªã¢ããã¿ãå¿ èŠã ã£ãããæ°ããSã¢ãã«ã®ãã®ã«ã¯æ¢ã«ãã®æ°ããããŒããããã 幞ããªããšã«ãKinectã«ã¯å ¬åŒã®ã¢ããã¿ãä»å±ããŠããïŒããããªããªãè³Œå ¥ããå¿ èŠãããïŒã
ã¢ããã¿ãé»æºãœã±ããã«å·®ã蟌ã¿ãUSBãã³ã³ãã¥ãŒã¿ã«æ¥ç¶ãããã ãããŠã¿ãŒããã«ã§ä»¥äžãå ¥åããŠã¿ãŸãããïŒ
% lsusb
ãããšæ¬¡ã®ãããªããã€ã¹ããªã¹ããããã§ããã:
Bus 001 Device 005: ID 045e:02b0 Microsoft Corp. Xbox NUI Motor
Bus 001 Device 006: ID 045e:02ad Microsoft Corp. Xbox NUI Audio
Bus 001 Device 007: ID 045e:02ae Microsoft Corp. Xbox NUI Camera
Xtionã䜿ã£ãŠããå Žåã¯ã次ã®ãããªã¡ãã»ãŒãžã衚瀺ããã:
Bus 001 Device 004: ID 1d27:0601 ASUS
æ°ããXtionã¢ãã«ãªã"0601"ãèå¥åãšããŠè¡šç€ºãããå€ãã¢ãã«ãªã "0600"ã衚瀺ãããã ãããã«ãããã©ã¡ããåãããã«åäœããã¯ãã§ããã ãã ããUSB 3.0ããŒãã¯äœ¿ããªãããšïŒ
KinectãPCäžã§åäœãããã«ã¯è€æ°ã®æ¹æ³ããããããããã¢ããªã±ãŒã·ã§ã³éçºãå¿ èŠ:
ãã®ãã¥ãŒããªã¢ã«ã§ã¯ãPCLãOpenNIãã©ã€ããšäœµçšããäºå®ã§ãããããXtionã®ææè ããããåäœãããããšãã§ããã
sudo apt-get install libpcl1.7 libopenni-dev libopenni-sensor-primesense-dev
ãã®ã³ãã³ãã§ã¯ããã¹ãŠã®ããã±ãŒãžããã§ã«ã€ã³ã¹ããŒã«ãããŠããããšïŒå¿
èŠã«å¿ããŠPCLã®ããŒãžã§ã³çªå·ãå€æŽããïŒã瀺ããããã§ãªãå Žåã¯ã€ã³ã¹ããŒã«ããããã¡ã€ã«ã®äžæžãã«é¢ãããšã©ãŒãçºçããå Žåã¯ãããã確èªããããROSã䜿ããªãå Žåã¯ãå¿ èŠãªãã®ãã¹ãŠãåããPPAïŒå人çšããã±ãŒãžã¢ãŒã«ã€ãããã©ã€ããŒããªããžããªïŒãããããœãŒã¹ã«è¿œå ãããã¹ãŠãã€ã³ã¹ããŒã«ãããïŒ
sudo add-apt-repository ppa:v-launchpad-jochen-sprickerhof-de/pcl
sudo apt-get update
sudo apt-get install build-essential cmake libpcl1.7 libpcl-dev pcl-tools
ROSãšPCLã®ãªããžããªãšããã±ãŒãžãæ··åšããããšãšã©ãŒãçºçããå¯èœæ§ãããã®ã§ãã©ã¡ãã1ã€ãéžæããŠããã䜿ãç¶ããããã«ãããã Kinectã¯ããã©ã«ãã§ã¯32ãããã§åäœããªãå¯èœæ§ããããããPCL / OpenNIã®ãã©ãã«ã·ã¥ãŒãã£ã³ã°ããŒãžã確èªããããšã
sudo mkdir -p /usr/lib/jvm/
sudo cp -r jdk1.8.0_66 /usr/lib/jvm/
次ã«ãJavaããã°ã©ã ãã³ã³ãã€ã«ããŠå®è¡ããããã®ããã©ã«ãã®éžæè¢ã«ããã å¿
èŠã«å¿ããŠããŒãžã§ã³çªå·ãå€æŽããããšãå¿ããªãããã«ïŒsudo update-alternatives --install "/usr/bin/java" "java" "/usr/lib/jvm/jdk1.8.0_66/bin/java" 1
sudo update-alternatives --install "/usr/bin/javac" "javac" "/usr/lib/jvm/jdk1.8.0_66/bin/javac" 1
sudo update-alternatives --install "/usr/bin/jar" "jar" "/usr/lib/jvm/jdk1.8.0_66/bin/jar" 1
è€æ°ã®éžæè¢ãããå Žåã¯ã次ã®ã³ãã³ãã䜿çšããŠæ£ãããªãã·ã§ã³ãæåã§éžæããã
sudo update-alternatives --config java
sudo update-alternatives --config javac
sudo update-alternatives --config jar
確èªã®ããã以äžãå®è¡ããŠããŒãžã§ã³ã衚瀺ããã€ã³ã¹ããŒã«ããããŒãžã§ã³ã§ããããšã確èªãããã
java -version
javac -version
ããã§Sunã®JDKãã€ã³ã¹ããŒã«ãããã
sudo apt-get install python libusb-1.0-0-dev freeglut3-dev doxygen graphviz
OpenNIã解åãããã£ã¬ã¯ããªïŒç§ã®å ŽåãOpenNI-master/ïŒã«ç§»åããPlatform/Linux/CreateRedist/ãµããã£ã¬ã¯ããªã«ãã端æ«ãéãã
./RedistMaker
äžã®ã³ãã³ããå®è¡ãããšã©ãŒããªããã°ïŒãšã©ãŒãåºãå Žåã¯PCL/OpenNIã®ãã©ãã«ã·ã¥ãŒãã£ã³ã°ã®ããŒãžããã§ãã¯ãããïŒãPlatform/Linux/Redist/OpenNI-Bin-Dev-Linux-x64-v1.5.7.10/ïŒãŸã㯠ããçžåœã®ãã®ïŒã«è¡ããã€ã³ã¹ããŒã«ããïŒãã ãããã«ã¯rootã§ãªããšãããªãïŒïŒ
sudo ./install.sh
ä»åºŠã¯ãPrimeSenseãã©ã€ããå±éãããã£ã¬ã¯ããªïŒç§ã®å Žå Sensor-master/ ïŒã«ç§»åããåãæé ãç¹°ãè¿ããŸãïŒPlatform/Linux/CreateRedist/ã«ç§»åãã./RedistMakerãå®è¡ããPlatform/Linux/Redist/Sensor-Bin-Linux-x64-v5.1.6.6/ãsudo ./install.shãå®è¡ãããïŒã ããã§ãšããããã§OpenNIãã€ã³ã¹ããŒã«å®äºã§ããã
OpenNIåæ§ãnVidia CUDAã¯ãªãã·ã§ã³ã®äŸåé¢ä¿ã§ãããPCLãç¹å®ã®èšç®ã«GPUïŒã°ã©ãã£ãã¯ã¹ã»ããã»ãã·ã³ã°ã»ãŠããããã€ãŸãã°ã©ãã£ãã¯ã¹ã«ãŒãïŒã䜿çšã§ããããã«ãããããã¯ãKinFuã®ãããªããŒã«ã§ã¯å¿ é ã§ããïŒå°ãªããšã1.5 GBã®VRAMãæèŒããã·ãªãŒãº400以äžã®ã«ãŒããæã£ãŠããªãå Žåã¯ç¡èŠãããïŒã
äžéšã®ãã£ã¹ããªãã¥ãŒã·ã§ã³ã§ã¯ããªããžããªå ã®CUDAçšã®ããã±ãŒãžãæäŸããŠãããããšãã°ãUbuntuã§ã¯æ¬¡ã®ããã«ãªãã
sudo apt-get install nvidia-cuda-dev nvidia-cuda-toolkit
æåã§ã€ã³ã¹ããŒã«ããå Žåã¯ïŒä»¥åã®æ¹æ³ãšäºææ§ããªãïŒãCUDAã®ããŠã³ããŒãããŒãžã«ç§»åããèªåã®ã·ã¹ãã ã«ãã£ãå°ããª.debãã¡ã€ã«ã倧ããª.runããŒã«ããã/ SDKã€ã³ã¹ããŒã©ãã¡ã€ã«ãå ¥æãããïŒãã®åã«nVidiaãã©ã€ããã€ã³ã¹ããŒã«ããŠããå¿ èŠãããããå¿ èŠã«å¿ããŠã€ã³ã¹ããŒã©ã代è¡ããïŒã
.debãã¡ã€ã«ãéžæããå Žåã¯ãGdebiããã±ãŒãžãããŒãžã£ã䜿ããããŸãã¯ã³ã³ãœãŒã«ãã次ã®ã³ãã³ããå®è¡ããããšã§ã€ã³ã¹ããŒã«ãããïŒ
sudo dpkg -i <package.deb>
.debã«ã¯CUDAã®ãã®ããã¹ãŠå«ãŸããŠããããã§ã¯ãªãããœãããŠã§ã¢ãªã¹ãã«ãªããžããªãè¿œå ããã ãã§ããã次ã«ãã¹ãŠãã€ã³ã¹ããŒã«ããïŒ
sudo apt-get update
sudo apt-get install cuda
äžæ¹ã.runãããŠã³ããŒãããå Žåã¯ãå®è¡æš©éãäžããã
chmod +x cuda_7.0.28_linux.run
ãããŠã€ã³ã¹ããŒã«ããã ããã©ã«ãã®ãªãã·ã§ã³ã䜿çšããããšã¯ã§ããããã«ãŒãçšã®nVidiaã°ã©ãã£ãã¯ã¹ãã©ã€ããåäœããŠããå Žåã¯ãã€ã³ã¹ããŒã«æã«ãnoããšã€ã³ã¹ããŒã©ã«å¯ŸããŠå ¥åããªããã°ãªããªãããšãããïŒ
sudo ./cuda_7.0.28_linux.run
ã·ã¹ãã ãCUDAã®ã©ã€ãã©ãªãšãã€ããªãèŠã€ããããã«ãç°å¢å€æ°ãå€æŽããå¿ èŠãããã ããã«ã¯/etc/ld.so.confãéã
sudo nano /etc/ld.so.conf
次ã®2ã€ã®è¡ã®ãããããè¿œå ãã
/usr/local/cuda/lib64 # 64ãããã®å Žå
/usr/local/cuda/lib # 32ãããã®å Žå
Ctrl+Oã§ä¿åããŠEnterãæŒããCtrl + Xã§çµäºããŸãã ãã€ãããã¯ãªã³ã«ã®ãã£ãã·ã¥ã次ã®ããã«åããŒãããã
sudo ldconfig
ããªãã®PATHã«CUDAã®binãã£ã¬ã¯ããªãè¿œå ãããã ããŒã«ã«ã®.bashrcãã¡ã€ã«ãç·šéããïŒ
nano ~/.bashrc
ãããŠæ¬¡ã®è¡ãè¿œå ããïŒ
export PATH=$PATH:/usr/local/cuda/bin
ããã§CUDAãã€ã³ã¹ããŒã«ãããŸããã
ããŠãPCLã®ãœãŒã¹ã³ãŒããããŠã³ããŒãããã ãŸããPCLã®å®å®çãŸãã¯å®éšçã®ã©ã¡ããã€ã³ã¹ããŒã«ããããéžæããã å®å®çãã©ã³ãã¯ææ°ã®å ¬åŒãªãªãŒã¹ã§ãããåé¡ãªãåäœããããšãä¿èšŒãããŠããã å®éšãã©ã³ãã¯ã³ã³ãã€ã«ã»ãšã©ãŒãèµ·ããããšã¯ãã£ãã«ãªãããå®å®çã®ããã«æ°ã¶æåŸ ãããããããªèå³æ·±ãæ©èœãèŠã€ããããšãã§ããã ãã以å€ã¯ãã©ã¡ããåãããã«æ§ç¯ãããŠããã
å®å®çãå ¥æããã«ã¯ãããŠã³ããŒãããŒãžã«è¡ããpcl-pcl-1.7.2.tar.gz(ãããã¯ææ°ãªãªãŒã¹ç)ãããŠã³ããŒãããã©ããã«å±éããã å®éšçã¯ã次ã®ããã«Gitã䜿ãïŒ
sudo apt-get install git
git clone https://github.com/PointCloudLibrary/pcl PCL-trunk-Source
ã³ã³ãã€ã«ãããPCLã®ãã©ã³ã¯çã¯8 GB以äžãå æããã ããã§ååãªç©ºãé åãæã€ããŒãã£ã·ã§ã³ã«ãœãŒã¹ãã©ã«ãã眮ããïŒ
PCLãœãŒã¹ãã£ã¬ã¯ããªïŒpcl-pcl-1.7.2/ãŸã㯠PCL-trunk-Source/ïŒã«ç§»åãããã«ãçšã®ãã¡ã€ã«ãä¿åãããããã£ã¬ã¯ããªbuildãäœæããã
mkdir build
cd build
ããŠCMakeã䜿ã£ãŠãããžã§ã¯ããèšå®ããããRelease(æé©åããããããã°æ©èœãªãïŒã¢ãŒãã§ãã«ãããããã«æ瀺ããåŸã§æ®ãã®ãªãã·ã§ã³ãã«ã¹ã¿ãã€ãºããïŒ
cmake -DCMAKE_BUILD_TYPE=Release ..
CMakeã¯ãã¹ãŠã®äŸåé¢ä¿ãèŠã€ããããšãã§ããªããã°ãªããªãã®ã§ããããã©ã«ãã§ã¯ç¡å¹ããšããŒã¯ããããµãã·ã¹ãã 以å€ã®ãã¹ãŠã®ãµãã·ã¹ãã ãæ§ç¯ããã ããã§ãããã°ä»æ§ç¯ããããšã¯ã§ããããCMakeã®cursesã€ã³ã¿ãã§ãŒã¹ãåŒã³åºããŠãããã€ãã®ç¹ãå€æŽãããïŒæåŸã®ãïŒãã«æ³šæïŒïŒ
ccmake .
ããã§ãã«ããªãã·ã§ã³ãå€æŽããããšãã§ããã ããã°ã©ã ã®äœ¿çšç¶æ³ããç»é¢ã®äžéšã«è¡šç€ºãããã ãã¹ãŠã®æ©èœãããªã³ãã«ããŠã¿ããã æãéèŠãªããšã¯ãCUDAã䜿çšãããå Žåã¯ããããæå¹ã«ããŠCMakeã«SDKãžã®ãã¹ãäžããããšã§ããã "CUDA_SDK_ROOT_DIR"ãªãã·ã§ã³ã«è¡ããæ£ãããã¹ãå ¥åããïŒãããã/usr/local/cuda/ïŒã
èšå®ãçµãã£ãããCãæŒããŠæ§æã確å®ããGãæŒããŠçæãçµäºããã å€æŽãããªãã·ã§ã³ã«ãã£ãŠã以åã«çç¥ããããã©ã¡ãŒã¿ãã¢ã¯ãã£ãã«ãªãå ŽåããèŠåããã¹ãã衚瀺ãããããšãããã ã¡ãã»ãŒãžãèªã¿çµãããEãæŒããçæããããŸã§CããŒãæŒãç¶ããïŒæ°ãããã©ã¡ãŒã¿ã«ã¯ã¢ã¹ã¿ãªã¹ã¯ãä»ããŠããããã確èªããŠããã«ã«ã¹ã¿ãã€ãºããå¿ èŠããããã©ãããå€æã§ããïŒã
æ§æãå®äºãããããã«ããããïŒ
make
泚ïŒã³ã³ãã€ã«ã®ã¹ããŒããäžããããã«ãã©ã¡ãŒã¿ -jX
ãè¿œå ã§ãã.ããã§Xã¯PCã®ã³ã¢ãŸãã¯ããã»ããµã®æ°ã«1ãå ãããã®ã§ãã
build/ãã£ã¬ã¯ããªã空ã«ããããšã«ããããã€ã§ã匷å¶çã«åæ§æã»ãã«ãããªããããšãã§ããããšã«æ³šæã
rm -rf ./*
PCLãã³ã³ãã€ã«ããã«ã¯æéããããïŒPCãåå匷åã§ãªãå Žåã¯æ倧æ°æéãããïŒã äœæ¥ãçµäºãããã次ãå®è¡ããã·ã¹ãã å šäœã«å¯ŸããŠã€ã³ã¹ããŒã«ããã
sudo make install
ã·ã¹ãã ãåèµ·åãã次ç¯ã«é²ã¿ãã³ã³ãã¥ãŒã¿ãKinectããã€ã¹ãèªèïŒããã³äœ¿çšïŒãããã©ããã確èªãããã
äœæãããã£ã¬ã¯ããªã®äžã«ãCMakeLists.txtãšããååã®æ°ããããã¹ããã¡ã€ã«ãäœãã PCLããŒã¹ã®ããã°ã©ã ãCMakeãã«ãã·ã¹ãã ã䜿çšããã ä»»æã®ãšãã£ã¿ãéãã次ã®å 容ã貌ãä»ãããã
cmake_minimum_required(VERSION 2.8 FATAL_ERROR)
project(PCL_openni_viewer)
find_package(PCL 1.7 REQUIRED)
include_directories(${PCL_INCLUDE_DIRS})
link_directories(${PCL_LIBRARY_DIRS})
add_definitions(${PCL_DEFINITIONS})
set(PCL_BUILD_TYPE Release)
file(GLOB PCL_openni_viewer_SRC
"src/*.h"
"src/*.cpp"
)
add_executable(openniViewer ${PCL_openni_viewer_SRC})
target_link_libraries (openniViewer ${PCL_LIBRARIES})
CMakeã®æ§æã¯æçã§ããã ããã§ã¯CMakeããŒãžã§ã³2.8以äžãã€ã³ã¹ããŒã«ããŠã»ããã ãŸã"openni_PCL_viewer"ãšããååã®æ°ãããããžã§ã¯ãã宣èšããã CMakeã«ãPCLã©ã€ãã©ãªéçºãã¡ã€ã«ãããŒãžã§ã³1.7ã®ååšã確èªããããã«æ瀺ããã ã·ã¹ãã ãCMakeããã³PCLã®ããŒãžã§ã³èŠä»¶ãæºãããªãå Žåã¯ãããã»ã¹ã¯å€±æããã
ã³ã³ãã€ã©ãšãªã³ã«ãŒã«ãPCLããããã£ã¬ã¯ããªãšãPCLã®ã©ã€ãã©ãªããããã£ã¬ã¯ããªãæããPCLã®å®çŸ©ã·ã³ãã«ãæããã 次ã«CMakeã« "Release"ã®ãã«ãã¿ã€ãã䜿çšããããæ瀺ããããããã«ããã䜿çšããã³ã³ãã€ã©ã«å¿ããŠç¹å®ã®æé©åãæå¹ã«ãªãã Release以å€ã«ã"Debug"ã "MinSizeRel"ã "RelWithDebInfo"ãªã©ã®ãã«ãã¿ã€ããå©çšã§ããã
æåŸã«ãã³ã³ãã€ã«ãããã¡ã€ã«ã®ãªã¹ããæ ŒçŽããå€æ° "opennipclviewer_SRC"ãäœæããïŒãã ãããã®ãã¡ã€ã«ã¯1ã€ã ãã§ããïŒã ãããã®ãœãŒã¹ãã¡ã€ã«ããã³ã³ãã€ã«ããããã«æ°ãããã€ããªãäœæãããããPCLã©ã€ãã©ãªã«ãªã³ã¯ããã
ä»ã®ãªãã·ã§ã³ã«ã€ããŠã¯ãCMakeã®ãã«ããåç §ããããšã
CMakeã«å¯Ÿãsrc/ ãµããã£ã¬ã¯ããªã«ãœãŒã¹ãã¡ã€ã«ããããšæããã ããã§ãããå®ãããã次ã®å 容ãæã€æ°ããmain.cppãã¡ã€ã«ãsrc/ã®äžã«è¿œå ããã
// Original code by Geoffrey Biggs, taken from the PCL tutorial in
// http://pointclouds.org/documentation/tutorials/pcl_visualizer.php
// Simple OpenNI viewer that also allows to write the current scene to a .pcd
// when pressing SPACE.
#include <pcl/io/openni_grabber.h>
#include <pcl/io/pcd_io.h>
#include <pcl/visualization/cloud_viewer.h>
#include <pcl/console/parse.h>
#include <iostream>
using namespace std;
using namespace pcl;
PointCloud<PointXYZRGBA>::Ptr cloudptr(new PointCloud<PointXYZRGBA>); // A cloud that will store color info.
PointCloud<PointXYZ>::Ptr fallbackCloud(new PointCloud<PointXYZ>); // A fallback cloud with just depth data.
boost::shared_ptr<visualization::CloudViewer> viewer; // Point cloud viewer object.
Grabber* openniGrabber; // OpenNI grabber that takes data from the device.
unsigned int filesSaved = 0; // For the numbering of the clouds saved to disk.
bool saveCloud(false), noColor(false); // Program control.
void
printUsage(const char* programName)
{
cout << "Usage: " << programName << " [options]"
<< endl
<< endl
<< "Options:\n"
<< endl
<< "\t<none> start capturing from an OpenNI device.\n"
<< "\t-v FILE visualize the given .pcd file.\n"
<< "\t-h shows this help.\n";
}
// This function is called every time the device has new data.
void
grabberCallback(const PointCloud<PointXYZRGBA>::ConstPtr& cloud)
{
if (! viewer->wasStopped())
viewer->showCloud(cloud);
if (saveCloud)
{
stringstream stream;
stream << "inputCloud" << filesSaved << ".pcd";
string filename = stream.str();
if (io::savePCDFile(filename, *cloud, true) == 0)
{
filesSaved++;
cout << "Saved " << filename << "." << endl;
}
else PCL_ERROR("Problem saving %s.\n", filename.c_str());
saveCloud = false;
}
}
// For detecting when SPACE is pressed.
void
keyboardEventOccurred(const visualization::KeyboardEvent& event,
void* nothing)
{
if (event.getKeySym() == "space" && event.keyDown())
saveCloud = true;
}
// Creates, initializes and returns a new viewer.
boost::shared_ptr<visualization::CloudViewer>
createViewer()
{
boost::shared_ptr<visualization::CloudViewer> v
(new visualization::CloudViewer("OpenNI viewer"));
v->registerKeyboardCallback(keyboardEventOccurred);
return (v);
}
int
main(int argc, char** argv)
{
if (console::find_argument(argc, argv, "-h") >= 0)
{
printUsage(argv[0]);
return -1;
}
bool justVisualize(false);
string filename;
if (console::find_argument(argc, argv, "-v") >= 0)
{
if (argc != 3)
{
printUsage(argv[0]);
return -1;
}
filename = argv[2];
justVisualize = true;
}
else if (argc != 1)
{
printUsage(argv[0]);
return -1;
}
// First mode, open and show a cloud from disk.
if (justVisualize)
{
// Try with color information...
try
{
io::loadPCDFile<PointXYZRGBA>(filename.c_str(), *cloudptr);
}
catch (PCLException e1)
{
try
{
// ...and if it fails, fall back to just depth.
io::loadPCDFile<PointXYZ>(filename.c_str(), *fallbackCloud);
}
catch (PCLException e2)
{
return -1;
}
noColor = true;
}
cout << "Loaded " << filename << "." << endl;
if (noColor)
cout << "This cloud has no RGBA color information present." << endl;
else cout << "This cloud has RGBA color information present." << endl;
}
// Second mode, start fetching and displaying frames from the device.
else
{
openniGrabber = new OpenNIGrabber();
if (openniGrabber == 0)
return -1;
boost::function<void (const PointCloud<PointXYZRGBA>::ConstPtr&)> f =
boost::bind(&grabberCallback, _1);
openniGrabber->registerCallback(f);
}
viewer = createViewer();
if (justVisualize)
{
if (noColor)
viewer->showCloud(fallbackCloud);
else viewer->showCloud(cloudptr);
}
else openniGrabber->start();
// Main loop.
while (! viewer->wasStopped())
boost::this_thread::sleep(boost::posix_time::seconds(1));
if (! justVisualize)
openniGrabber->stop();
}
ãããã»ãŒãããŠãã¡ã€ã«ãéãã
PCLãæ§ç¯ããã®ãšåãæé ã«åŸãã ã€ãŸããsrc/ãã£ã¬ã¯ããªã®é£ã«æ°ããbuild/ãµããã£ã¬ã¯ããªãäœæããã ãããŠã¿ãŒããã«ãéãã以äžãå®è¡ããïŒ
cmake -DCMAKE_BUILD_TYPE=Release ..
make
åãã¿ãŒããã«ã«ãããŠãã³ã³ãã€ã«ããããµã³ãã«ããã°ã©ã ãå®è¡ããïŒ
./openniViewer
æ°ç§åŸãã¡ã€ã³ãŠã£ã³ããŠã衚瀺ãããã¢ããªã±ãŒã·ã§ã³ã¯ããã€ã¹ãããã¬ãŒã ãååŸãå§ãããããŠã¹ã䜿çšããŠçŸåšã®ãã€ã³ãã¯ã©ãŠããæ€æ»ããå転ããå·Šãã¿ã³ããºãŒã ããããã®å³ãã¿ã³ïŒãŸãã¯ããŠã¹ãã€ãŒã«ïŒãããã³ã«ã¡ã©ããã³ããããã®äžå€®ã®ãã€ã³ãã¯ã©ãŠããæ€æ»ããããšãã§ãããæåã¯ãé»ãç»é¢ã倧ããªè²ä»ãã®è»žãã衚瀺ããããã¯ã©ãŠãã¯è¡šç€ºãããªãããºãŒã ã¢ãŠãããŠãã·ãŒã³å šäœã衚瀺ããŠã¿ããããã1ã€ã®äŸ¿å©ãªããŒã¯Rã§ããããããæŒããšã«ã¡ã©ã®ãã©ã¡ãŒã¿ããªã»ããããããäžéšã®ã«ã¡ã©ã®åãã®åŸã§ãºãŒã ãé ããªã£ãããšã«æ°ãã€ããæããã¯ã©ãŠãããŸã èŠããªããšãã«äœ¿çšãããè¿œå ã®ã³ã³ãããŒã«ãšæ©èœã«ã€ããŠã¯ãPCLVisualizerãã¥ãŒããªã¢ã«ãåç §ã®ããšã
æºåãã§ããããã¹ããŒã¹ããŒãæŒãããããã°ã©ã ã¯æ°ç§éåæ¢ããåºåã¯ãä¿åãããinputCloud0.pcdããšãªããã³ã³ãœãŒã«ã«è¡šç€ºããããçŸåšã®ãã©ã«ãã調ã¹ãŠãå®éã«inputCloud0.pcdãã¡ã€ã«ãæžã蟌ãŸããŠããããšã確èªãããã QãŸãã¯Alt + F4ã§ããã°ã©ã ãéããããšãã§ããã
次ã«ãå床å®è¡ããŠæ¬¡ã®ãã©ã¡ãŒã¿ãæå®ããã
./openniViewer -v inputCloud0.pcd
ããã«ãããããã°ã©ã ã¯ããã€ã¹ããããŒã¿ãååŸããã代ããã«ä¿åããããã€ã³ãã¯ã©ãŠããã¡ã€ã«ããããŒã¿ãååŸããã ããŒãåŸããã£ã¹ã¯ã«ä¿åããã®ãšåãã·ãŒã³ã衚瀺ãããããšã«æ°ä»ãã ããã
泚ïŒPCDããŒã¿ã¯ã»ã³ãµãŒã«å¯ŸããŠä¿åãããã ãã¥ãŒãã©ãã ãæäœããŠãããã¡ã€ã«ãããŒããããšããã©ã«ãã«ãªã»ãããããã
ãã®æç¹ã§ãKinectããã€ã¹ãåäœãã深床ããŒã¿ãååŸããå¿ èŠãããã å ¬åŒWebããŒãžã«ã¯ãPCLã«é¢ããåªãããã¥ãŒããªã¢ã«ããããŸãã Kinectã»ã³ãµãŒã䜿çšããŠå®éšãé²ããåã«ããããããã¹ãŠçµäºããããšããå§ãããã ããã§ã¯ãPCLã©ã€ãã©ãªã§ã®åªãã玹ä»/ãã¥ãŒããªã¢ã«ãèŠã€ããããšãã§ããŸãã
Kinectã®ä»£ããã«ASUS Xtion PROããã€ã¹ã䜿çšããŠããå Žåã¯ãåé¡ãè¿œå æé ãªãã§ãã¹ãŠã皌åãããå¿ èŠãããïŒãããããããé€ãïŒã
Go to root: PhD-3D-Object-Tracking
Links to articles:
PCL/OpenNI tutorial 0: The very basics
PCL/OpenNI tutorial 1: Installing and testing
PCL/OpenNI tutorial 2: Cloud processing (basic)
PCL/OpenNI tutorial 3: Cloud processing (advanced)
PCL/OpenNI tutorial 4: 3D object recognition (descriptors)
PCL/OpenNI tutorial 5: 3D object recognition (pipeline)
PCL/OpenNI troubleshooting