参考来源:

利用OpenCV生成关于某点的颜色径向均匀渐变图像

// define head function
#ifndef PS_ALGORITHM_H_INCLUDED
#define PS_ALGORITHM_H_INCLUDED #include <iostream>
#include <string>
#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 <time.h> 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<Img.rows; i++)
{
for (int j=0; j<Img.cols; j++)
{
dis2=sqrt((i-origin.x)*(i-origin.x)+(j-origin.y)*(j-origin.y));
Img.at<Vec3f>(i,j)[0]=Img.at<Vec3f>(i,j)[0]+weightB*dis2;
Img.at<Vec3f>(i,j)[1]=Img.at<Vec3f>(i,j)[1]+weightG*dis2;
Img.at<Vec3f>(i,j)[2]=Img.at<Vec3f>(i,j)[2]+weightR*dis2;
}
} Img=Img/255.0; Show_Image(Img, "img");
imwrite("Out.jpg", Img*255); waitKey();
cout<<"All is well."<<endl; } // define the show image
#include "PS_Algorithm.h"
#include <iostream>
#include <string> 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); }

OpenCV——颜色均匀渐变的更多相关文章

  1. 学习opencv中文版教程——第二章

    学习opencv中文版教程——第二章 所有案例,跑起来~~~然而并没有都跑起来...我只把我能跑的都尽量跑了,毕竟看书还是很生硬,能运行能出结果,才比较好. 越着急,心越慌,越是着急,越要慢,越是陌生 ...

  2. 立体视觉-opencv中立体匹配相关代码

    三种匹配算法比较 BM算法: 该算法代码: view plaincopy to clipboardprint? CvStereoBMState *BMState = cvCreateStereoBMS ...

  3. OpenCV 玩九宫格数独(二):knn 数字识别

    欢迎大家关注腾讯云技术社区-博客园官方主页,我们将持续在博客园为大家推荐技术精品文章哦~ 作者:刘潇龙 前言 首先需要说明,这里所说的数字识别不是手写数字识别! 但凡对机器学习有所了解的人,相信看到数 ...

  4. OpenCV stereo matching 代码 matlab实现视差显示

    转载请注明出处:http://blog.csdn.net/wangyaninglm/article/details/44151213, 来自:shiter编写程序的艺术 基础知识 计算机视觉是一门研究 ...

  5. 【OpenCV】SIFT原理与源码分析:DoG尺度空间构造

    原文地址:http://blog.csdn.net/xiaowei_cqu/article/details/8067881 尺度空间理论   自然界中的物体随着观测尺度不同有不同的表现形态.例如我们形 ...

  6. opencv学习之路(31)、GrabCut & FloodFill图像分割

    一.GrabCut 1.利用Rect做分割 #include "opencv2/opencv.hpp" using namespace cv; void main() { Mat ...

  7. Python+OpenCV图像处理(十三)—— Canny边缘检测

    简介: 1.Canny边缘检测算子是John F. Canny于 1986 年开发出来的一个多级边缘检测算法. 2.Canny 的目标是找到一个最优的边缘检测算法,最优边缘检测的含义是: 好的检测- ...

  8. [PyImageSearch] Ubuntu16.04 使用OpenCV和python识别信用卡 OCR

    在今天的博文中,我将演示如何使用模板匹配作为OCR的一种形式来帮助我们创建一个自动识别信用卡并从图像中提取相关信用卡数位的解决方案. 今天的博文分为三部分. 在第一部分中,我们将讨论OCR-A字体,这 ...

  9. 基于opencv+Dlib的面部合成(Face Morph)

    引自:http://blog.csdn.net/wangxing233/article/details/51549880 零.前言 前段时间看到文章[1]和[2],大概了解了面部合成的基本原理.这两天 ...

随机推荐

  1. XSD文件详解

    XSD (xml Schema Definition) Xml Schema的用途 1.  定义一个Xml文档中都有什么元素 2.  定义一个Xml文档中都会有什么属性 3.  定义某个节点的都有什么 ...

  2. Coursera machine learning 第二周 quiz 答案 Octave/Matlab Tutorial

    https://www.coursera.org/learn/machine-learning/exam/dbM1J/octave-matlab-tutorial Octave Tutorial 5  ...

  3. python 基础 9.6 设计表结构

    一. 设计表结构    在操作设计数据库之前,我们先要设计数据库表结构,我们就来分析分析经典的学生,课程,成绩,老师这几者他们之间的关系,我们先来分析各个主体他们直接有什么属性,并确定表结构,在实际开 ...

  4. [Sdoi2014]数数[数位dp+AC自动机]

    3530: [Sdoi2014]数数 Time Limit: 10 Sec  Memory Limit: 512 MBSubmit: 834  Solved: 434[Submit][Status][ ...

  5. ORDER BY today_used ASC' % (MAX_USED_TIMES)

    python D:\pymine\clean\spider_map\get_bd_uid_rest_b.py python D:\pymine\clean\spider_map\get_bd_uid_ ...

  6. 【转载】解决Apache2+PHP上传文件大小限制的问题

    原文出处:http://evol1216.blog.163.com/blog/static/13019958020106783623528/ 在用PHP进行文件上传的操作中,需要知道怎么控制上传文件大 ...

  7. oracle decode的用法

    需求:分别统计emp表中1980,1981,1982,1987年入职的同事的数量. 这里用decode很容易就解决了: select sum(t.num_1980) as "1980&quo ...

  8. eclipse revert resources 很慢的解决办法

    eclipse启动无响应,停留在Loading workbench状态,或老是加载不了revert resources 做开发的同学们或多或少的都会遇到eclipse启动到一定程度时,就进入灰色无响应 ...

  9. 小程序坑 redirectTo 计时器 setInterval clearInterval

    var time = 20: var timer = setInterval(function () { time = time - 1; that.setData({ CountDown: time ...

  10. 通过tile和url判断页面跳转是否正确

    通过webdriver中的.title和.current_url获取title和url from time import sleep from selenium import webdriver br ...