<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Realsense ImageData to OpenCV Mat in Software Archive</title>
    <link>https://community.intel.com/t5/Software-Archive/Realsense-ImageData-to-OpenCV-Mat/m-p/1000451#M29941</link>
    <description>&lt;P&gt;Hi there!&lt;/P&gt;

&lt;P&gt;Can someone tell me how I can get the realsense imagedata into a cv::Mat?&lt;/P&gt;

&lt;P&gt;I found some stuff in the forum,but I was confused with the planes/pitches.Any links/sample code for conversion from realsense to mat formats?&lt;/P&gt;</description>
    <pubDate>Mon, 30 Mar 2015 15:31:12 GMT</pubDate>
    <dc:creator>Marios_B_</dc:creator>
    <dc:date>2015-03-30T15:31:12Z</dc:date>
    <item>
      <title>Realsense ImageData to OpenCV Mat</title>
      <link>https://community.intel.com/t5/Software-Archive/Realsense-ImageData-to-OpenCV-Mat/m-p/1000451#M29941</link>
      <description>&lt;P&gt;Hi there!&lt;/P&gt;

&lt;P&gt;Can someone tell me how I can get the realsense imagedata into a cv::Mat?&lt;/P&gt;

&lt;P&gt;I found some stuff in the forum,but I was confused with the planes/pitches.Any links/sample code for conversion from realsense to mat formats?&lt;/P&gt;</description>
      <pubDate>Mon, 30 Mar 2015 15:31:12 GMT</pubDate>
      <guid>https://community.intel.com/t5/Software-Archive/Realsense-ImageData-to-OpenCV-Mat/m-p/1000451#M29941</guid>
      <dc:creator>Marios_B_</dc:creator>
      <dc:date>2015-03-30T15:31:12Z</dc:date>
    </item>
    <item>
      <title>It depends on what type of</title>
      <link>https://community.intel.com/t5/Software-Archive/Realsense-ImageData-to-OpenCV-Mat/m-p/1000452#M29942</link>
      <description>&lt;P&gt;It depends on what type of data you want to get, and in what format.&lt;/P&gt;

&lt;P&gt;For example, to get a color image, you could do something like this: (it can be done more efficiently, and you should error check on each step, but this should be easy to understand)&lt;/P&gt;

&lt;P&gt;Let's say you have a color image:&lt;/P&gt;

&lt;P&gt;PXCImage *color&lt;/P&gt;

&lt;P&gt;You can create a cv::Mat color image based on it:&lt;/P&gt;

&lt;PRE class="brush:cpp;"&gt;//First, create an ImageData object:

PXCImage::ImageData * data = new PXCImage::ImageData;

//Set the format that you want to use:
data-&amp;gt;format = PXCImage::PIXEL_FORMAT_RGB32; // For example 4 bytes in this case (8 * 4 = 32)

//Create a cv::Mat black canvas based on the size of the color image

int width = color-&amp;gt;QueryInfo().width;
int height = color-&amp;gt;QueryInfo().height;
cv::Mat frameColor = cv::Mat::zeros(height, width, CV_8UC3);

//Now get access to the memory of the image:

color-&amp;gt;AcquireAccess(PXCImage::ACCESS_READ, data-&amp;gt;format, data);

//Now we just need to paint the canvas with each pixel from the image data

 pxcBYTE *cpixels=data-&amp;gt;planes[0];
 
int x = 0, y = 0;

        for(int i=0; i &amp;lt; width * height; i++)
        {
            //BGRA
            //Read the first 3 bytes of each 4 bytes, and ignore the last one
            pxcBYTE bvalue = cpixels[i * 4 + 0];
            pxcBYTE gvalue = cpixels[i * 4 + 1];
            pxcBYTE rvalue = cpixels[i * 4 + 2];
            unsigned int bvalueUchar = static_cast&amp;lt;unsigned int&amp;gt;(bvalue);
            unsigned int gvalueUchar = static_cast&amp;lt;unsigned int&amp;gt;(gvalue);
            unsigned int rvalueUchar = static_cast&amp;lt;unsigned int&amp;gt;(rvalue);
 
            frameColor.at&amp;lt;cv::Vec3b&amp;gt;(y, x)[0] = (bvalueUchar);
            frameColor.at&amp;lt;cv::Vec3b&amp;gt;(y, x)[1] = (gvalueUchar);
            frameColor.at&amp;lt;cv::Vec3b&amp;gt;(y, x)[2] = (rvalueUchar);
            //Advance, one pixel at a time (can be done better of course!)
            x += 1;
            if(x &amp;gt;= width)
            {
                x = 0;
                y += 1;
            }
        }
        //At the end, release all the used memory
        color-&amp;gt;ReleaseAccess(data);
        delete data;

&lt;/PRE&gt;

&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 31 Mar 2015 05:05:00 GMT</pubDate>
      <guid>https://community.intel.com/t5/Software-Archive/Realsense-ImageData-to-OpenCV-Mat/m-p/1000452#M29942</guid>
      <dc:creator>samontab</dc:creator>
      <dc:date>2015-03-31T05:05:00Z</dc:date>
    </item>
    <item>
      <title>Thank you for your reply.</title>
      <link>https://community.intel.com/t5/Software-Archive/Realsense-ImageData-to-OpenCV-Mat/m-p/1000453#M29943</link>
      <description>&lt;P&gt;Thank you for your reply.&lt;/P&gt;

&lt;P&gt;I now understood the planes thing.However what exactly is the pitch?&lt;/P&gt;

&lt;P&gt;Also,what happens if I also want the depth pixels?&lt;/P&gt;

&lt;P&gt;Same thing exactly but with only 1 value per pixel?&lt;/P&gt;

&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 10 Apr 2015 11:25:57 GMT</pubDate>
      <guid>https://community.intel.com/t5/Software-Archive/Realsense-ImageData-to-OpenCV-Mat/m-p/1000453#M29943</guid>
      <dc:creator>Marios_B_</dc:creator>
      <dc:date>2015-04-10T11:25:57Z</dc:date>
    </item>
    <item>
      <title>Hi Marios,</title>
      <link>https://community.intel.com/t5/Software-Archive/Realsense-ImageData-to-OpenCV-Mat/m-p/1000454#M29944</link>
      <description>&lt;P&gt;Hi Marios,&lt;/P&gt;

&lt;P&gt;I recently made a video tutorial explaining how to get the depth, IR, and colour streams into OpenCV using a single and a multi threaded approach. You might find this useful:&lt;/P&gt;

&lt;P&gt;&lt;A href="https://software.intel.com/en-us/forums/realsense/topic/595033" target="_blank"&gt;https://software.intel.com/en-us/forums/realsense/topic/595033&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 29 Oct 2015 02:24:23 GMT</pubDate>
      <guid>https://community.intel.com/t5/Software-Archive/Realsense-ImageData-to-OpenCV-Mat/m-p/1000454#M29944</guid>
      <dc:creator>samontab</dc:creator>
      <dc:date>2015-10-29T02:24:23Z</dc:date>
    </item>
  </channel>
</rss>

