title: Accessing RGB values of all pixels in a certain image in openCV
body: <p>I have searched internet and stackoverflow thoroughly, but I didn't find what exactly I'm looking for!</p>
  
  <p>How can I get RGB (BGR actually) values of a certain image (all pixels of the image) in OpenCV? I'm using C++, the image is stored in cv::Mat variable.</p>
  
  <p>I'm showing some of my efforts so far: I tried this code from another stackoverflow link. But every time I re-run the code the value in Hexadecimal changed! For example once its 00CD5D7C, in next run it is 00C09D7C.</p>
  
  <pre><code>cv::Mat img_rgb = cv::imread("img6.jpg");
  Point3_&lt;uchar&gt;* p = img_rgb.ptr&lt;Point3_&lt;uchar&gt; &gt;(10,10);
  p-&gt;x; //B
  p-&gt;y; //G
  p-&gt;z; //R
  std::cout&lt;&lt;p;
  </code></pre>
  
  <p>In another try I used this code from another answer. Here output is always -858993460.</p>
  
  <pre><code>img_rgb.at&lt;cv::Vec3b&gt;(10,10);
  img_rgb.at&lt;cv::Vec3b&gt;(10,10)[0] = newval[0];
  img_rgb.at&lt;cv::Vec3b&gt;(10,10)[1] = newval[1];
  img_rgb.at&lt;cv::Vec3b&gt;(10,10)[2] = newval[2];
  
  cout&lt;&lt;newval[0]; //For cout&lt;&lt;newval[1]; cout&lt;&lt;newval[2]; the result is still same
  </code></pre>
  
  <p>NOTE: I used (10,10) as a test to get the RGB, my target is get the RGB values if the whole image!</p>