参考来源:

利用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. 转载 --iOS QQ第三方登实现

    我们经常会见到应用登陆的时候会有QQ,微信,微博等的第三方登陆 如图: 下面我们主要讲一下qq的第三方登陆如何实现 首先,到官网注册: http://wiki.connect.qq.com 一,下载S ...

  2. github-readme.md-格式

    大标题 大标题一般显示project名,类似html的<h1> 你仅仅要在标题以下跟上=====就可以 中标题 中标题一般显示重点项,类似html的<h2> 你仅仅要在标题以下 ...

  3. 爬虫入门【3】BeautifulSoup4用法简介

    快速开始使用BeautifulSoup 首先创建一个我们需要解析的html文档,这里采用官方文档里面的内容: html_doc = """ <html>< ...

  4. Lorenzo Von Matterhorn(STL_map的应用)

    Lorenzo Von Matterhorn time limit per test 1 second memory limit per test 256 megabytes input standa ...

  5. [转]为 windows cmd 设置代理

    为 windows cmd 设置代理 转自:http://blog.csdn.net/lovelyelfpop/article/details/69586366 通过cmd命令行执行某些命令,如果这些 ...

  6. mysql存储过程之事务篇

    mysql存储过程之事务篇 事务的四大特征: ACID:Atomic(原子性).Consistent(一致性).Isolated(独立性).Durable (持久性) MySQL的事务支持不是绑定在M ...

  7. Asp.Net mvc4 项目 在vs中调试正常 在IIS发布后连接oracle数据库时提示数据库连接关闭

    解决办法: 1.打开iis,找到发布的程序 2.右键单击“TAKANAPP” 从右键菜单选择“管理应用程序”--“高级设置....” 在打开的高级设置  面板 查看对应的应用程序池 名称 3.设置应用 ...

  8. 使用 Python 为 KVM 编写脚本,第 1 部分: libvirt

    虚拟化是目前市场上大多数服务器操作系统的标准设备.在 Linux® 的世界里,服务器虚拟化有两个主要选择:基于 Kernel 的虚拟机 (KVM) 和 Xen.KVM 是 Red Hat 和其他公司采 ...

  9. Linux基础系列:常用命令(5)_samba服务与nginx服务

    作业一:部署samba 每个用户有自己的目录,可以浏览内容,也可以删除 所有的用户共享一个目录,只能浏览内容,不能删 安装samba服务 1.准备环境 setenforce 0 2.安装软件包 yum ...

  10. iOS 在视图控制器里面判断 应用程序的前台 后台切换 UIViewController

    1.时机  用户点击home 键  应用退到后台 再次点击进入前台  在UIViewController里面 控制器如何获取相关的事件? 2.需求 (1)NSTimer   在应用程序进入后台 10秒 ...