0
得到RGB值我有一個點雲。我想獲得它的RGB值。我怎樣才能做到這一點?
爲了讓我的問題更清楚,請參閱代碼。如何從點雲
// Load the first input file into a PointCloud<T> with an appropriate type :
pcl::PointCloud<pcl::PointXYZRGB>::Ptr cloud1 (new pcl::PointCloud<pcl::PointXYZRGB>);
if (pcl::io::loadPCDFile<pcl::PointXYZRGB> ("../data/station1.pcd", *cloud1) == -1)
{
std::cout << "Error reading PCD file !!!" << std::endl;
exit(-1);
}
我想每個單獨的值
std::cout << " x = " << cloud1->points[11].x << std::endl;
std::cout << " y = " << cloud1->points[11].y << std::endl;
std::cout << " z = " << cloud1->points[11].z << std::endl;
std::cout << " r = " << cloud1->points[11].r << std::endl;
std::cout << " g = " << cloud1->points[11].g << std::endl;
std::cout << " b = " << cloud1->points[11].b << std::endl;
但是結果是我得到類似的東西:
x = 2.33672
y = 3.8102
z = 8.86153
r = �
g = w
b = �
謝謝@Kevin;但我仍然得到同樣的錯誤;這是新的代碼: 'uint32_t的RGB = *的reinterpret_cast(cloud1->點[11] .rgb); uint8_t r =(rgb >> 16)&0x0000ff; uint8_t g =(rgb >> 8)&0x0000ff; uint8_t b =(rgb)&0x0000ff; std :: cout <<「x =」<< cloud1-> points [11] .x << std :: endl; std :: cout <<「y =」<< cloud1-> points [11] .y << std :: endl; std :: cout <<「z =」<< cloud1-> points [11] .z << std :: endl; std :: cout <<「r =」<< r << std :: endl; std :: cout <<「g =」<< g << std :: endl; std :: cout <<「b =」<< b << std :: endl; ' –
lotfishtaine
我成功解決了!實際上R,G和B值是unsigned char類型,因此我們需要將它們轉換爲int來查看它們的數值。 我嘗試:'性病::法院<< 「R =」 << INT(cloud1->點[11] .R)<<的std :: ENDL;'和它的作品 – lotfishtaine
作出這樣的(INT)cloud1->點[11] .r雖然;)您現在調用int的構造函數(創建一個新變量並將其返回到輸出與cout),而不是將值轉換爲int類型。 – Kevin