I want to convert 16UC3 image to 1 dimensional array? [closed]
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.cols*i + image.cols*image.rows * 0] = image.at<cv::Vec3b>(i, j)[0];
img[j + image.cols*i + image.cols*image.rows * 1] = image.at<cv::Vec3b>(i, j)[1];
img[j + image.cols*i + image.cols*image.rows * 2] = image.at<cv::Vec3b>(i, j)[2];
}
}
Vec3b is the wrong access for 16UC3 (uchar vs ushort)
What is the correct way to access those values??
image.at<ushort>(i,j)[0] is this way to access values...
hmm, that's a different context now. (why didn't you tell before ?)
one of the main differences between code above and answer below is, that opencv uses interleaved bgr pixels, while you seem to want sequential channels, can you clarify ?