depth to color mapping

  • Hi Guys,

    I am developing an application what display depth datas from depth camera( 3D camera)..
    This camera put depth datas for each pixels of 320x240 image into the "unsigned short *m_pCameraBuf[2]".

    if I draw this raw data without color mapping, I can see some pictures but I want to convert depth data to fantastic color data with a mapping table.

    this is my code to print raw depth data but it is just experimental.. please advice me what's the best code to draw depth data with QT5.

    QImage image( (uchar*) m_pCameraBuf[DATA_DEPTH], imageWidth, imageHeight, imageWidth * bytesPerPixel, QImage::Format_RGB16, Q_NULLPTR, Q_NULLPTR);

    Thanks a lot..

  • Why don't you first try in some way what told you want to do. You only seem to have a possibly working call to construct a QImage. It will build a 16 bit color image, which seems funny - why not go to the 32 bit formats, which have 8 bits per color for eac channel (R,G, B). You should probably first create just the image without your data and fill it in the next step.

    Of course you need the mapping table or mapping function. That is the core of things - how to represent depth with an RGB pixel. Once you figure that out (and that is not a Qt issue), you can just loop through your image (for x = 0; x < 320; x++ and so on) and create each pixel:
    QRgb myPixel = conversionFunctionToGetColorOfDepth(myDepth[x, y]);
    myImage.setPixel(QPoint(x, y), myPixel());

    SetPixel is slow, but you need to start with that to understand what you are doing and the code can be refactored later for efficiency, if needed.

Log in to reply