 <p>Do you mean to return it as a 32-bit integer?</p> <pre><code>unsigned int get_color(cv::Mat img, float x, float y) { int i = x*img.cols; int j = y*img.rows; unsigned char R = img.ptr&lt;unsigned char&gt;(j)[3*i]; unsigned char G = img.ptr&lt;unsigned char&gt;(j)[3*i+1]; unsigned char B = img.ptr&lt;unsigned char&gt;(j)[3*i+2]; return (R &lt;&lt; 16) | (G &lt;&lt; 8) | B; } </code></pre> <p>Or perhaps you want to return it as floats in which case you need to do the following</p> <pre><code>struct FloatColour { float r; float g; float b; }; float get_color(cv::Mat img, float x, float y) { int i = x*img.cols; int j = y*img.rows; unsigned char R = img.ptr&lt;unsigned char&gt;(j)[3*i]; unsigned char G = img.ptr&lt;unsigned char&gt;(j)[3*i+1]; unsigned char B = img.ptr&lt;unsigned char&gt;(j)[3*i+2]; FloatColour retCol; retCol.r = R / 255.0f; retCol.g = G / 255.0f; retCol.b = B / 255.0f; return retCol; } </code></pre>