opencv 画渐变色

#include "stdafx.h"
#include 
#include 
 

int main(int argc, char** argv)
{
 int nWidth = 256 * 2 - 1;
 int nHeight = 400;
 IplImage* pImg = cvCreateImage( cvSize(nWidth, nHeight), IPL_DEPTH_8U, 3 );

 for(int i= 0;iheight;i++)
 {
  uchar* data=(uchar*)pImg->imageData + pImg->widthStep * i;
  for(int j=0;jwidth;j++)
  {
   int nColor;
   if (j <= 255)
   {
    nColor = 255 - j;
   } 
   else
   {
    nColor = j - 255;
   }
  
   data[3*j] = data[3*j+1] = data[3*j+2] = nColor;   
  }
 }

 cvShowImage("benben", pImg);

 cvSaveImage( "C:\\Users\\benben_wsx\\Desktop\\132132.jpg", pImg);
 cvWaitKey(0);


 return 0;
}


你可能感兴趣的:(opencv 画渐变色)