linux下调用opencv接口函数使图片有渐变的效果

来源:互联网 发布:淘宝如何管理商家 编辑:程序博客网 时间:2024/05/19 22:55
#include <stdio.h>
#include <opencv2/highgui/highgui.hpp>


int main(int argc,char* argv[])
{
CvPoint center;
double scale=-3;
IplImage* image= cvLoadImage(argv[1]);

center =cvPoint(image->width/2,image->height/2);


for(int i=0;i<image->height;i++)
for(int j=0;j<image->width;j++)
{
double dx=(double)(j-center.x)/center.x;
double dy=(double)(j-center.y)/center.y;
double weight=exp((dx*dy+dy*dy)*scale);
uchar* ptr=&CV_IMAGE_ELEM(image,uchar,i,j*3);
ptr[0]=cvRound(ptr[0]*weight);
ptr[1]=cvRound(ptr[1]*weight);
ptr[2]=cvRound(ptr[2]*weight);
}
cvNamedWindow("image",CV_WINDOW_AUTOSIZE);
cvShowImage("image",image);
cvWaitKey(0);


cvReleaseImage(&image);/* 释放相关资源 */  
        cvDestroyWindow("image");  
    
return 0; 
}