码迷,mamicode.com
首页 > 其他好文 > 详细

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

时间:2015-05-30 09:25:05      阅读:150      评论:0      收藏:0      [点我收藏+]

标签:opencv   c++   

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

#include <iostream>
#include "cv.h"
#include <highgui.h>
#include<fstream>
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获取图片所有对应坐标中的像素值

标签:opencv   c++   

原文地址:http://blog.csdn.net/sunshihua12829/article/details/46242451

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!