Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Access channels of CV_8U Image

I want to convert a float matrix to an unsigned char matrix with the same number of channels.

cv::Mat imgA(3, 3, CV_32FC(5));
// image is filled with something
cv::Mat imgB;
imgA.convertTo(imgB, CV_8UC(imgA.channels()));

How can the additional channels of a CV_8UC image be accessed? The following gives a segmentation fault.

std::cout << (int) imgB.at<uchar>(0,0,1) << "\n";

Access channels of CV_8U CV_8UC Image

I want to convert a float matrix to an unsigned char matrix with the same number of channels.

cv::Mat imgA(3, 3, CV_32FC(5));
// image is filled with something
cv::Mat imgB;
imgA.convertTo(imgB, CV_8UC(imgA.channels()));

How can the additional channels of a CV_8UC image be accessed? The following gives a segmentation fault.

std::cout << (int) imgB.at<uchar>(0,0,1) << "\n";