I'm unable to access the values in the matrix properly. for (int i = 0; i < image.rows; i++) { for (int j = 0; j < image.cols; j++) { img[j + image.colsi + image.colsimage.rows * 0] = image.at<cv::vec3b>(i, j)[0]; img[j + image.colsi + image.colsimage.rows * 1] = image.at<cv::vec3b>(i, j)[1]; img[j + image.colsi + image.colsimage.rows * 2] = image.at<cv::vec3b>(i, j)[2]; } }