gpt4 book ai didi

c++ - OpenInventor 到 PCD : cannot convert RGB to decimal

转载 作者:塔克拉玛干 更新时间:2023-11-03 06:54:43 27 4
gpt4 key购买 nike

我正在编写一个小程序来将 OpenInventor 文件转换为 PCD 文件。为此,我有两个输入文件,即 OpenInventor 文件和 JPEG 图像。纹理坐标是介于 0.0 和 1.0 之间的浮点值。

我使用OpenCV提取RGB值并以十进制格式返回,但是下面的函数好像不能正常运行...

float get_color(cv::Mat img, float x, float y) {

int i = x*img.cols;
int j = y*img.rows;

unsigned char R = img.ptr<unsigned char>(j)[3*i];
unsigned char G = img.ptr<unsigned char>(j)[3*i+1];
unsigned char B = img.ptr<unsigned char>(j)[3*i+2];

return R*pow(16,4) +
G*pow(16,2) +
B;
}

我加载图像

 cv::imread("filename.jpg", CV_LOAD_IMAGE_COLOR).

最佳答案

您的意思是将其作为 32 位整数返回吗?

unsigned int get_color(cv::Mat img, float x, float y) 
{

int i = x*img.cols;
int j = y*img.rows;

unsigned char R = img.ptr<unsigned char>(j)[3*i];
unsigned char G = img.ptr<unsigned char>(j)[3*i+1];
unsigned char B = img.ptr<unsigned char>(j)[3*i+2];

return (R << 16) |
(G << 8) |
B;
}

或者您可能想将其作为 float 返回,在这种情况下您需要执行以下操作

struct FloatColour
{
float r;
float g;
float b;
};

float get_color(cv::Mat img, float x, float y)
{

int i = x*img.cols;
int j = y*img.rows;

unsigned char R = img.ptr<unsigned char>(j)[3*i];
unsigned char G = img.ptr<unsigned char>(j)[3*i+1];
unsigned char B = img.ptr<unsigned char>(j)[3*i+2];

FloatColour retCol;
retCol.r = R / 255.0f;
retCol.g = G / 255.0f;
retCol.b = B / 255.0f;
return retCol;
}

关于c++ - OpenInventor 到 PCD : cannot convert RGB to decimal,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11603091/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com