Opencv指针访问每一个像素值

利用opencv访问单通道图像中的像素值

#include
#include
#include
using namespace cv;
using namespace std;

int main()
{
    Mat img = imread("MRF_focus.tif", 0);
    int rows = img.rows;
    int cols = img.cols;
    for (int i = 0; i < rows; i++)
    {
        uchar* ptr = (uchar*)img.data +i *cols;
        for (int j = 0; j < cols; j++)
        {
            int value = ptr[j];
            cout << "第" << i << "行" << j << "列灰度值:" << value << endl;
        }
    }
    waitKey();
    return 0;
}

你可能感兴趣的:(OpenCV,C++)