首页 / 操作系统 / Linux / OpenCV基础篇之图片叠加
OpenCV基础篇之图片叠加程序及分析/*
* FileName : blend.cpp
* Author : xiahouzuoxin @163.com
* Version : v1.0
* Date : Mon 28 Jul 2014 08:47:59 PM CST
* Brief :
*
* Copyright (C) MICL,USTB
*/
#include <cv.h>
#include <highgui.h>
#include <stdio.h>using namespace std;
using namespace cv;int main(int argc, char *argv[])
{
double alpha = 0.5;
double beta;
double input; Mat src1, src2, dst; // User input alpha
cout<<"Simple Linear Blender" << endl;
cout<<"---------------------" << endl;
cout<<"Enter alpha [0-1]: ";
cin>>input; if (alpha >=0 && alpha <=1) {
alpha = input;
} // Read images
src1 = imread("../test_imgs/KeNan.jpg");
src2 = imread("../test_imgs/Background.jpg"); if (!src1.data) {
cout<<"Error loading src1
"<<endl;
return -1;
}
if (!src2.data) {
cout<<"Error loading src2
"<<endl;
return -1;
} // Create WIndows
namedWindow("Linear Blend", 1); beta = (1.0 - alpha);
addWeighted(src1, alpha, src2, beta, 0.0, dst); imshow("Linear Blend", dst);
waitKey(0); return 0;
}这里的图像叠加指线性叠加,设图像A的像素为fA(x),图像B的像素为fB(x),叠加系数为α,则线性叠加操作为:α为0-1之间的值,从上面也可以看出,叠加必需保证两幅输入图像的尺寸大小相同。程序中的
addWeighted(src1, alpha, src2, beta, 0.0, dst); 完成叠加操作。效果--------------------------------------分割线 --------------------------------------Ubuntu Linux下安装OpenCV2.4.1所需包 http://www.linuxidc.com/Linux/2012-08/68184.htmUbuntu 12.04 安装 OpenCV2.4.2 http://www.linuxidc.com/Linux/2012-09/70158.htmCentOS下OpenCV无法读取视频文件 http://www.linuxidc.com/Linux/2011-07/39295.htmUbuntu 12.04下安装OpenCV 2.4.5总结 http://www.linuxidc.com/Linux/2013-06/86704.htmUbuntu 10.04中安装OpenCv2.1九步曲 http://www.linuxidc.com/Linux/2010-09/28678.htm基于QT和OpenCV的人脸识别系统 http://www.linuxidc.com/Linux/2011-11/47806.htm--------------------------------------分割线 --------------------------------------本文永久更新链接地址:http://www.linuxidc.com/Linux/2014-08/105084.htm