OpenCV遍历访问图像的每一个元素

// my8.cpp : 定义控制台应用程序的入口点。
//

#include "stdafx.h"
#include "highgui.h"
#include "cv.h"
#include <iostream>
using namespace std;

int _tmain(int argc, _TCHAR* argv[])
{

 IplImage* image = cvLoadImage("e:\\wali2.jpg");

 cvNamedWindow("s");

 //用指针指向图像的数据区头部
 uchar* pchar;
 int width = image->width; cout<<width<<endl;
 int heigh = image->height; cout<<heigh<<endl;
 int channel = image->nChannels;  cout<<channel<<endl;
 int widthStep = image->widthStep;  cout<<widthStep<<endl;


 int i,j;

 for(i=0; i<heigh; i++)
 {
  pchar = (uchar*) image->imageData +  i*widthStep;
        for (j=0; j<width; j++)
        {
   uchar* temp = pchar +j*channel;
   temp[0] -= 10; //通道B
      temp[1] -= 10; //通道G
   temp[2] -= 10; //通道R
        }
 }

 

    cvShowImage("s",image);
 cvWaitKey(0);
 cvReleaseImage(&image);
 cvDestroyWindow("s");
 
 

 return 0;
}

 

你可能感兴趣的:(opencv)