Opencv指针访问每一个像素值

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

#include<opencv2/opencv.hpp>
#include<opencv2/core.hpp>
#include<iostream>
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;
}

猜你喜欢

转载自blog.csdn.net/weixin_38285131/article/details/80877978