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——颜色均匀渐变的更多相关文章
- 学习opencv中文版教程——第二章
学习opencv中文版教程——第二章 所有案例,跑起来~~~然而并没有都跑起来...我只把我能跑的都尽量跑了,毕竟看书还是很生硬,能运行能出结果,才比较好. 越着急,心越慌,越是着急,越要慢,越是陌生 ...
- 立体视觉-opencv中立体匹配相关代码
三种匹配算法比较 BM算法: 该算法代码: view plaincopy to clipboardprint? CvStereoBMState *BMState = cvCreateStereoBMS ...
- OpenCV 玩九宫格数独(二):knn 数字识别
欢迎大家关注腾讯云技术社区-博客园官方主页,我们将持续在博客园为大家推荐技术精品文章哦~ 作者:刘潇龙 前言 首先需要说明,这里所说的数字识别不是手写数字识别! 但凡对机器学习有所了解的人,相信看到数 ...
- OpenCV stereo matching 代码 matlab实现视差显示
转载请注明出处:http://blog.csdn.net/wangyaninglm/article/details/44151213, 来自:shiter编写程序的艺术 基础知识 计算机视觉是一门研究 ...
- 【OpenCV】SIFT原理与源码分析:DoG尺度空间构造
原文地址:http://blog.csdn.net/xiaowei_cqu/article/details/8067881 尺度空间理论 自然界中的物体随着观测尺度不同有不同的表现形态.例如我们形 ...
- opencv学习之路(31)、GrabCut & FloodFill图像分割
一.GrabCut 1.利用Rect做分割 #include "opencv2/opencv.hpp" using namespace cv; void main() { Mat ...
- Python+OpenCV图像处理(十三)—— Canny边缘检测
简介: 1.Canny边缘检测算子是John F. Canny于 1986 年开发出来的一个多级边缘检测算法. 2.Canny 的目标是找到一个最优的边缘检测算法,最优边缘检测的含义是: 好的检测- ...
- [PyImageSearch] Ubuntu16.04 使用OpenCV和python识别信用卡 OCR
在今天的博文中,我将演示如何使用模板匹配作为OCR的一种形式来帮助我们创建一个自动识别信用卡并从图像中提取相关信用卡数位的解决方案. 今天的博文分为三部分. 在第一部分中,我们将讨论OCR-A字体,这 ...
- 基于opencv+Dlib的面部合成(Face Morph)
引自:http://blog.csdn.net/wangxing233/article/details/51549880 零.前言 前段时间看到文章[1]和[2],大概了解了面部合成的基本原理.这两天 ...
随机推荐
- JQuery+Json 省市区三级联动
一.画面以及JS <!DOCTYPE html> <head> <meta http-equiv="Content-Type" content=&qu ...
- python模块, 包的初识
Python 模块(Module), 是一个 Python 文件,以 .py 结尾,包含了 Python 对象定义和Python语句. 模块让你能够有逻辑地组织你的 Python 代码段. 把相关的代 ...
- 【BZOJ1513】[POI2006]Tet-Tetris 3D 二维线段树
[BZOJ1513][POI2006]Tet-Tetris 3D Description Task: Tetris 3D "Tetris" 游戏的作者决定做一个新的游戏, 一个三维 ...
- tmpfs(转)
什么是tmpfs tmpfs是Linux/Unix系统上的一种基于内存的文件系统.tmpfs可以使用您的内存或swap分区来存储文件. 实现原理:基于VM子系统 tmpfs是基于Linux的虚拟内存管 ...
- DNN 数据的表示
- 【python】-- 类的实例化过程、特征、共有属性和私有属性
实例化过程 1.类的定义和语法 class dog(object): #用class定义类 "dog class" #对类的说明 def __init__(self,name): ...
- lua解析json
自己写的lua解析json,带容错,如果要是用于格式检查,得修改下.很简单直接贴代码 --------------------------------------------------json解析- ...
- Meeting-in-the-Middle (LA 2965)
Meeting-in-the-Middle,又称“中途相遇法”.准确地说,它只是一种策略. 顺便说一下,这个算法真的很冷门! 结合这道题来讨论一下吧:LA 2965.ε(┬┬﹏┬┬)3 因为博主的英文 ...
- 使用nginx进行负载均衡
nginx主要用于1:请求分流 2:负载均衡.用在大型系统(集群)上,在单机上体现不出优势. 本实例在windows环境下进行. 一.安装nginx 1.下载nginx1.8.0版 2.解压至1 ...
- CSS选择器(一)
一.CSS 元素选择器 最常见的 CSS 选择器是元素选择器.换句话说,文档的元素就是最基本的选择器. 如果设置 HTML 的样式,选择器通常将是某个 HTML 元素,比如 p.h1.em.a,甚至可 ...