Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8268837
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T06:01:39+00:00 2026-06-08T06:01:39+00:00

I am writing a small program to convert an OpenInventor file to a PCD

  • 0

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).
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T06:01:41+00:00Added an answer on June 8, 2026 at 6:01 am

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

    Due to historical reasons (PCL was first developed as a ROS package),
    the RGB information is packed into an integer and casted to a float.
    This is something we wish to remove in the near future, but in the
    meantime, the following code snippet should help you pack and unpack
    RGB colors in your PointXYZRGB structure:

    uint8_t r = 255, g = 0, b = 0;
    uint32_t rgb = ((uint32_t)r << 16 | (uint32_t)g << 8 | (uint32_t)b);
    p.rgb = *reinterpret_cast<float*>(&rgb);
    

    After refactoring and few other bug fixes, the function has become:

    float get_color(cv::Mat img, float s, float t){
    
            int j = (1.0 - s)*(float)img.cols;
            int i = (1.0 - t)*(float)img.rows;
    
            uint8_t R = img.at<cv::Vec3b>(i,j)[2];
            uint8_t G = img.at<cv::Vec3b>(i,j)[1];
            uint8_t B = img.at<cv::Vec3b>(i,j)[0];
    
            uint32_t rgb_32 = ((uint32_t)R << 16 | (uint32_t)G << 8 | (uint32_t)B);
    
            return *reinterpret_cast<float*>(&rgb_32);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am writing a small program in C++ using OpenCV-2.3 API. I have an
I have a problem with Regular Expressions. I'm writing a small program that matches
I am writing a small test program that gives the following xml file as
I am writing a small program which needs to create a new file with
I'm writing a small program in C that will read input from the console.
I am writing a small program to copy files. The program checks whether the
I am writing a small program in OpenGL on my Mac. I have a
I'm writing a small program, it can show and manager all files and folder
I am writing a small program in C++ that receives mic input and does
I'm writing a small ruby program to play with Twitter over OAuth and have

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.