I am writing a small program to convert an OpenInventor file to a PCD one. To do so I have two files in input, namely the OpenInventor file and a JPEG image. The texture coordinates are float values between 0.0 and 1.0.
I use OpenCV to extract the RGB value and return it in decimal format, but the following function does not seem to work properly…
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;
}
I load the image with
cv::imread("filename.jpg", CV_LOAD_IMAGE_COLOR).
I found the answer to my own question in a comment found in the PCL’s header "point_types.hpp" (PCL version: 1.5.1):
After refactoring and few other bug fixes, the function has become: