OpenCV获取图片所有对应坐标中的像素值


获取图片所有对应坐标中的像素值。直接上代码了

#include 
#include "cv.h"
#include 
#include
using namespace std;

int main()
{
    IplImage *img = cvLoadImage("C:\\Users\\Sunstarisme\\Desktop\\Lemon\\All Frames\\2.bmp", CV_LOAD_IMAGE_COLOR);
    uchar *data = (uchar *)img->imageData;
    int step = img->widthStep / sizeof(uchar);
    int channels = img->nChannels;
    int R, G, B;
    ofstream fout;
    fout.open("RGB.txt", ios::app);
    for(int i = 0; i < img->height; i++)
    {
        for(int j = 0; j < img->width; j++)
        {
            B = (int)data[i * step + j * channels + 0];
            G = (int)data[i * step + j * channels + 1];
            R = (int)data[i * step + j * channels + 2];
            fout << "( " << i << ", " << j << " ) = ( " << R << "," << G << "," << B << ")" << endl;
        }
    }
    fout.close();
    return 0;
}

结果是:

OpenCV获取图片所有对应坐标中的像素值_第1张图片

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