Software Archive
Read-only legacy content
17061 Discussions

Print RGB value in format R G B intel realsense

Andrea_B_1
Beginner
989 Views

Hello, we have to acquire all RGB value for every pixel  from the image, how can we take them?

I had try make this code but it doesn't work right, can someone explain me how i must proced? 

Thanks

 

 


// retrieve all available image samples
PXCCapture::Sample *sample = psm->QuerySample();
// retrieve the image or frame by type from the sample
colorIm = sample->color;
depthIm = sample->depth;

PXCImage::ImageData colordata;
colorIm->AcquireAccess(PXCImage::ACCESS_READ, PXCImage::PIXEL_FORMAT_RGB32, &colordata);

pxcBYTE *R = new pxcBYTE[WIDTH*HEIGHT];
pxcBYTE *G = new pxcBYTE[WIDTH*HEIGHT];
pxcBYTE *B = new pxcBYTE[WIDTH*HEIGHT];

for (int y = 0; y < HEIGHT; y++){
    for (int x = 0; x < WIDTH; x++){

        B[x + y] = (colordata.planes[0] + y*colordata.pitches[0])[4 * x + 0];
        G[x + y] = (colordata.planes[0] + y*colordata.pitches[0])[4 * x + 1];
        R[x + y] = (colordata.planes[0] + y*colordata.pitches[0])[4 * x + 2];

    }
}

 

 

0 Kudos
2 Replies
Felipe_P_Intel
Employee
989 Views

Hi Andrea, 

Have you tried to take a look into the 3d Segmentation sample that comes with SDK? 

Also, to access the image data you need to follow the steps described here: https://software.intel.com/sites/landingpage/realsense/camera-sdk/v1.1/documentation/html/manuals_image_and_audio_data.html

Here is the code from 3d Segmentation showing what you need to do:

    PXCImage::ImageData segmented_image_data;
    segmented_image->AcquireAccess(PXCImage::ACCESS_READ_WRITE,
        PXCImage::PIXEL_FORMAT_RGB32, &segmented_image_data);
    const pxcI32 height = segmented_image->QueryInfo().height;
    const pxcI32 width = segmented_image->QueryInfo().width;
    for (int y = 0; y < height; y++)
    {
        // Get the address of the row of pixels
        pxcBYTE* p = segmented_image_data.planes[0]
            + y * segmented_image_data.pitches[0];

        // For each pixel in the row...
        const char GREY = 0x7f;
        for (int x = 0; x < width; x++)
        {
            // ...if the pixel is part of the segmented region...
            if (p[3] > 0)
            {
                // set the return flag, if it's not already set
                if (!bMaskIsSegmented) bMaskIsSegmented = true;

                // When the user moves into the near/far extent, the alpha values will drop from 255 to 1.
                // This can be used to fade the user in/out as a cue to move into the ideal operating range.
                if (p[3] != 255)
                {
                    const float blend_factor = (float)p[3] / 255.0f;
                    for (int ch = 0; ch < 3; ch++)
                    {
                        pxcBYTE not_visible = ((p[ch] >> 4) + GREY);
                        p[ch] = (pxcBYTE)(p[ch] * blend_factor + not_visible * (1.0f - blend_factor));
                    }
                }
            }
            else for (int ch = 0; ch < 3; ch++) p[ch] = (p[ch] >> 4) + GREY;

            // Move the pointer to the next pixel (RGBA)
            p += 4;
        }
    }
    segmented_image->ReleaseAccess(&segmented_image_data);

 

0 Kudos
Yuri_M_Intel
Employee
989 Views

    Hi Andrea,

your code is correct, but you have made a small mistake  

       B[x + y*WIDTH] = (colordata.planes[0] + y*colordata.pitches[0])[4 * x + 0];
       G[x + y*WIDTH] = (colordata.planes[0] + y*colordata.pitches[0])[4 * x + 1];
        R[x + y*WIDTH] = (colordata.planes[0] + y*colordata.pitches[0])[4 * x + 2];

0 Kudos
Reply