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).