Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p><code>cv::Mat</code> is preferred over <code>IplImage</code> because it simplifies your code</p> <pre><code>cv::Mat img = cv::imread("lenna.png"); for(int i=0; i&lt;img.rows; i++) for(int j=0; j&lt;img.cols; j++) // You can now access the pixel value with cv::Vec3b std::cout &lt;&lt; img.at&lt;cv::Vec3b&gt;(i,j)[0] &lt;&lt; " " &lt;&lt; img.at&lt;cv::Vec3b&gt;(i,j)[1] &lt;&lt; " " &lt;&lt; img.at&lt;cv::Vec3b&gt;(i,j)[2] &lt;&lt; std::endl; </code></pre> <p>This assumes that you need to use the RGB values together. If you don't, you can uses cv::split to get each channel separately. See etarion's answer for the link with example.</p> <p>Also, in my cases, you simply need the image in gray-scale. Then, you can load the image in grayscale and access it as an array of uchar.</p> <pre><code>cv::Mat img = cv::imread("lenna.png",0); for(int i=0; i&lt;img.rows; i++) for(int j=0; j&lt;img.cols; j++) std::cout &lt;&lt; img.at&lt;uchar&gt;(i,j) &lt;&lt; std::endl; </code></pre> <p><strong>UPDATE</strong>: Using split to get the 3 channels</p> <pre><code>cv::Mat img = cv::imread("lenna.png"); std::vector&lt;cv::Mat&gt; three_channels = cv::split(img); // Now I can access each channel separately for(int i=0; i&lt;img.rows; i++) for(int j=0; j&lt;img.cols; j++) std::cout &lt;&lt; three_channels[0].at&lt;uchar&gt;(i,j) &lt;&lt; " " &lt;&lt; three_channels[1].at&lt;uchar&gt;(i,j) &lt;&lt; " " &lt;&lt; three_channels[2].at&lt;uchar&gt;(i,j) &lt;&lt; std::endl; // Similarly for the other two channels </code></pre> <p>UPDATE: Thanks to entarion for spotting the error I introduced when copying and pasting from the cv::Vec3b example.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload