枫语过 發表於 2019-8-30 11:26:00

Ubuntu 16.04 install CloudCompare

<h3 id="one-single-command-should-work-1">One single command should work <sup></sup></h3>
<pre><code>snap install cloudcompare
</code></pre>
<p>But error occurs:</p>
<pre><code>error: cannot perform the following tasks:
- Download snap "cloudcompare" (200) from channel "stable" (Get https://api.snapcraft.io/api/v1/snaps/download/SMYgr36XCuPZDbMnuOu5x4eFvcHALPyL_200.snap: dial tcp: lookup api.snapcraft.io on 127.0.1.1:53: read udp 127.0.0.1:55699-&gt;127.0.1.1:53: i/o timeout)
</code></pre>
<h2 id="solved-by-adding-sudo">Solved by adding <code>sudo</code></h2>
<pre><code>sudo snap install cloudcompare
</code></pre>
<h3 id="open-cloudcompare-in-a-terminal-2">Open cloudcompare in a terminal <sup></sup></h3>
<p><code>cloudcompare.ccViewer</code></p>
<p>or <code>cloudcompare.CloudCompare</code></p>
<p>Error occurs:</p>
<pre><code>QXcbConnection: Could not connect to display :0
Aborted (core dumped)
</code></pre>
<h2 id="solved-by-answer-3">Solved by answer <sup></sup></h2>
<p><code>sudo snap install meshlab</code></p>
<h3 id="error-occurred-while-loading-pcd-file">Error occurred while loading pcd file</h3>
<p><code> Can't guess file format: unhandled file extension'pcd'</code></p>
<h2 id="sovled-by-answer-4">Sovled by answer <sup></sup></h2>
<p>The stable version of CC can not open pcd file.</p>
<p>Switch it to edge version by</p>
<p><code>sudo snap refresh --edge cloudcompare</code></p>
<h2 id="note-edge-verstion-dosent-stable-when-saving-pcd-files">NOTE: Edge verstion dosen't stable when saving .pcd files</h2>
<p>There is <strong>a 90° rotation between along axis x</strong> between the original point cloud and output cloud.</p>
<p><img src="https://img2018.cnblogs.com/blog/1329367/201912/1329367-20191227144353140-233087665.png"></p>
<blockquote>
<p><em>Update: a solution found <sup></sup></em></p>
</blockquote>
<hr>
<p>So I gived up the edge version. <strong>Build and install CC from source</strong> <sup></sup></p>
<pre><code>git clone --recursive https://github.com/cloudcompare/trunk.git
cd trunk
mkdir build
cd build
cmake ..
make -j4
sudo make install
</code></pre>
<p>Launch CC <code>./qCC/CloudCompare</code></p>
<h2 id="pcd-file-to-text-file">PCD file to text file</h2>
<p>In this <code>pcd2txt.cpp</code> file <em>(Thanks for Gordon)</em>, .pcd file can be converted to .txt file or reversally (that means .txt file can be converted to .pcd file too).</p>
<pre><code>#include &lt;string&gt;
#include &lt;iostream&gt;
#include &lt;fstream&gt;

#include &lt;pcl/io/pcd_io.h&gt;
#include &lt;pcl/point_types.h&gt;
#include &lt;pcl/point_cloud.h&gt;

#include &lt;Eigen/Geometry&gt;
#include &lt;Eigen/Core&gt;

void pcd2txt(pcl::PointCloud&lt;pcl::PointXYZI&gt;::Ptr pcdPtr)
{
    /*------------------ output pointcloud xyz as txt ----------------*/
    /*----------------------------------------------------------------*/
    std::ofstream xyz_txt("/home/gordon/feelEnvironment/data/segByCloudCompare/raw_pointcloud/pointcloud_xyz.txt", std::ios::out);
    for(int i = 0; i &lt; pcdPtr-&gt;points.size(); i++)
    {
      xyz_txt &lt;&lt; std::fixed &lt;&lt; std::setprecision(6) &lt;&lt; pcdPtr-&gt;points.x &lt;&lt; ' ' &lt;&lt; pcdPtr-&gt;points.y &lt;&lt; ' ' &lt;&lt; pcdPtr-&gt;points.z &lt;&lt; std::endl;
    }
    xyz_txt.close();
}


void txt2pcd(pcl::PointCloud&lt;pcl::PointXYZ&gt;::Ptr pcdPtr){
    std::ifstream fin("/home/gordon/feelEnvironment/data/segByCloudCompare/ganjian.txt", std::ios::in);
    int row;
    fin &gt;&gt; row;
    std::cout &lt;&lt; "row size = " &lt;&lt; row &lt;&lt; std::endl;
   
    double temp;
    pcl::PointXYZ point;
    for(int i = 0; i &lt; row; i++){
      fin &gt;&gt; temp;
      point.x = temp;
      
      fin &gt;&gt; temp;
      point.y = temp;
      
      fin &gt;&gt; temp;
      point.z = temp;
      
      pcdPtr-&gt;points.push_back(point);
    }
   
    if(row == pcdPtr-&gt;size())
      std::cout &lt;&lt; "Success!" &lt;&lt; std::endl;
   
}

int main (int argc, char** argv)
{
//   pcd to txt
    pcl::PCDReader reader;
    pcl::PointCloud&lt;pcl::PointXYZI&gt;::Ptr cloud (new pcl::PointCloud&lt;pcl::PointXYZI&gt;);
   
    std::string fileLocation = "/home/gordon/feelEnvironment/data/segByCloudCompare/raw_pointcloud/1574588098460847.pcd";
    reader.read(fileLocation,*cloud);
   
    std::cout &lt;&lt; "ori_pointcloud size = "&lt;&lt; cloud-&gt;points.size() &lt;&lt; std::endl;
    std::cout &lt;&lt; "width = " &lt;&lt; cloud-&gt;width &lt;&lt; "; height = " &lt;&lt; cloud-&gt;height &lt;&lt; std::endl;
    std::cout &lt;&lt; "sensor origin : " &lt;&lt; cloud-&gt;sensor_origin_ &lt;&lt; std::endl;
    std::cout &lt;&lt; "sensor orientation : " &lt;&lt; cloud-&gt;sensor_orientation_.coeffs() &lt;&lt; std::endl;
   
    pcd2txt(cloud);


    // txt to pcd
    // pcl::PCDWriter writer;
   
    // pcl::PointCloud&lt;pcl::PointXYZ&gt;::Ptr segCloud(new pcl::PointCloud&lt;pcl::PointXYZ&gt;);
    // txt2pcd(segCloud);
    // segCloud-&gt;width = segCloud-&gt;size();
    // segCloud-&gt;height = 1;
   
    // writer.write("/home/gordon/feelEnvironment/data/segByCloudCompare/xyz.pcd", *segCloud);
   

    return 0;
}
</code></pre>
<p>The <code>CMakeLists.txt</code> looks like this</p>
<pre><code>cmake_minimum_required(VERSION 2.8 FATAL_ERROR)

project(pcd2txt)

find_package(PCL 1.5 REQUIRED)

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

add_executable(pcd2txt pcd2txt.cpp)
target_link_libraries (pcd2txt ${PCL_LIBRARIES})
</code></pre>
<p><strong>NOTE: When saving .txt make sure to check <code>number of points (seperate line)</code></strong></p>
<h3 id="references">References:</h3>
<p><span id="ref1"></span> CloudCompare - Open Source project<br>
<span id="ref2"></span> Ubuntu18.04 cloudcompare安装 - 写东西仪式感极强(其实拖延症晚期晚期)的大龄小白<br>
<span id="ref3"></span> ubuntu - QxcbConnection error - CloudCompare won't launch - Stack Overflow<br>
<span id="ref4"></span> Still cannot open PCD files on Linux · Issue #536 · CloudCompare/CloudCompare · GitHub<br>
<span id="ref5">[5</span> 经过CloudCompare保存的点云视点改变导致的问题_旅行在明天之前昨天之后的博客-CSDN博客</p><br><br>
来源:https://www.cnblogs.com/linweilin/p/11434056.html
頁: [1]
查看完整版本: Ubuntu 16.04 install CloudCompare