I have recently switched from the OpenCV C++ API to JavaCV and I'm trying to perform a basic operation, such as iterating over a Mat. I'm trying to access the pixel value of the Mat, but I can't seem to find a way, and the JavaCV project is short on documentation. Using the OpenCV C++ API, I used to access the pixel value of a Mat by using the .at()
method.
The Mat is loaded as CV_8UC1 Mat (greyscale), as you can see in the code below, and I would like to print/use the 0-255 value of the pixels.
Mat image = imread("images/Text00.png", CV_8UC1);
// Make sure it was successfully loaded.
if (image == null) {
System.out.println("Image not found!");
System.exit(1);
}
System.out.println(image.rows());
System.out.println(image.cols());
for (int y = 0; y < image.rows(); y++) {
for (int x = 0; x < image.cols(); x++) {
// How to print the 0 to 255 value of each pixel in the Mat image.
}
}
Similar but not applicable answers:
- How to iterate through a cvMat matrix in JavaCV? (outdated, applicable to CvMat)