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],大概了解了面部合成的基本原理.这两天 ...
随机推荐
- hdu_1226超级密码(BFS)
超级密码 Problem Description Ignatius花了一个星期的时间终于找到了传说中的宝藏,宝藏被放在一个房间里,房间的门用密码锁起来了,在门旁边的墙上有一些关于密码的提示信息:密码是 ...
- jvm本身的多线程机制
1 多线程环境下的构造函数调用 构造函数本身并没有隐式的同步,因为各个线程构建的是自己的对象,它们之间是不存在竞争关系的. 2 class loader在load class时被了sychronize ...
- Python菜鸟之路:Python基础——函数
一.函数 1. 简介 函数是组织好的,可重复使用的,用来实现单一,或相关联功能的代码段.函数能提高应用的模块性,和代码的重复利用率. 2. 组成 函数代码块以 def 关键词开头,后接函数名和圆括号( ...
- 洛谷 P2051 [AHOI2009]中国象棋
题目描述 这次小可可想解决的难题和中国象棋有关,在一个N行M列的棋盘上,让你放若干个炮(可以是0个),使得没有一个炮可以攻击到另一个炮,请问有多少种放置方法.大家肯定很清楚,在中国象棋中炮的行走方式是 ...
- 如何将cordova导入Android studio,只需两步即可
Cordova的技术交流新群 微信公众号:
- linux 中 用户管理 (composer 时不能root 遇到)
linux 是支持多用户的,可以同时多个用户在线操作,这点与 Windows 不同. 在我们项目组 操作linux 服务器时,可进行多用户管理,并赋予不同权限,下面是我学习并用的比较频繁的命令: 1. ...
- 蓝屏代码stop:0X000000EA(0X85E286B8,0X8635F210,0XF7A53CBC,0X00000001)
你这是显卡驱动问题,我把蓝屏代码都给你,以后在出现蓝屏自己看看行了. 1.0x0000000A:IRQL_NOT_LESS_OR_EQUAL ◆错误分析:主要是由问题的驱动程序.有缺陷或不兼容的硬件与 ...
- model特性
1.scope http://blog.csdn.net/lissdy/article/details/51107883 2.ActiveConcern http://www.tuicool.com/ ...
- Floyd 学习笔记
#include <cstdio> #include <cstring> #include <ctype.h> #include <cstdlib> # ...
- Ansible playbook练习
示例1:创建用户的Playbook --- - name: create user hosts: openstack gather_facts: false tasks: - name: create ...