700字范文,内容丰富有趣,生活中的好帮手!
700字范文 > opencv 图片边缘渐变_OpenCV——颜色均匀渐变

opencv 图片边缘渐变_OpenCV——颜色均匀渐变

时间:2022-01-26 23:14:32

相关推荐

opencv 图片边缘渐变_OpenCV——颜色均匀渐变

参考来源:

// define head function

#ifndef PS_ALGORITHM_H_INCLUDED

#define PS_ALGORITHM_H_INCLUDED

#include

#include

#include "cv.h"

#include "highgui.h"

#include "cxmat.hpp"

#include "cxcore.hpp"

#include "math.h"

using namespace std;

using namespace cv;

void Show_Image(Mat&, const string &);

#endif // PS_ALGORITHM_H_INCLUDED

/*

This program will generate

color gradient mapping

*/

#include "PS_Algorithm.h"

#include

using namespace std;

using namespace cv;

int main(void)

{

Mat Img(600, 800, CV_32FC3);

Scalar a(255.0, 255.0, 255.0);

Scalar b(0.0, 0.0, 0.0);

Img.setTo(a);

int width, height;

width=Img.cols;

height=Img.rows;

Point2f origin(0.0, 0.0);

Point2f Cen(Img.cols/2.0, Img.rows/2.0);

float dis;

if (origin.x<=Cen.x && origin.y<=Cen.y)

{

dis=sqrt((width-1-origin.x)*(width-1-origin.x)+

(height-1-origin.y)*(height-1-origin.y));

}

else if (origin.x<=Cen.x && origin.y>Cen.y)

{

dis=sqrt((width-1-origin.x)*(width-1-origin.x)+

origin.y*origin.y);

}

else if (origin.x>Cen.x && origin.y>Cen.y)

{

dis=sqrt(origin.x*origin.x+(origin.y)*(origin.y));

}

else

{

dis=sqrt(origin.x*origin.x+

(height-1-origin.y)*(height-1-origin.y));

}

float weightB=(b[0]-a[0])/dis;

float weightG=(b[1]-a[1])/dis;

float weightR=(b[2]-a[2])/dis;

float dis2;

for (int i=0; i

{

for (int j=0; j

{

dis2=sqrt((i-origin.x)*(i-origin.x)+(j-origin.y)*(j-origin.y));

Img.at(i,j)[0]=Img.at(i,j)[0]+weightB*dis2;

Img.at(i,j)[1]=Img.at(i,j)[1]+weightG*dis2;

Img.at(i,j)[2]=Img.at(i,j)[2]+weightR*dis2;

}

}

Img=Img/255.0;

Show_Image(Img, "img");

imwrite("Out.jpg", Img*255);

waitKey();

cout<

}

// define the show image

#include "PS_Algorithm.h"

#include

#include

using namespace std;

using namespace cv;

void Show_Image(Mat& Image, const string& str)

{

namedWindow(str.c_str(),CV_WINDOW_AUTOSIZE);

imshow(str.c_str(), Image);

}

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。