码迷,mamicode.com
首页 > 其他好文 > 详细

OpenCV Tutorials —— Adding (blending) two images using OpenCV

时间:2014-11-16 21:23:44      阅读:181      评论:0      收藏:0      [点我收藏+]

标签:style   http   io   ar   os   sp   div   on   art   

An interesting dyadic (two-input) operator is thelinear blend operator:

bubuko.com,布布扣

 

#include <cv.h>
#include <highgui.h>
#include <iostream>

using namespace cv;

int main( int argc, char** argv )
{
 double alpha = 0.5; double beta; double input;

 Mat src1, src2, dst;

 /// Ask the user enter alpha
 std::cout<<" Simple Linear Blender "<<std::endl;
 std::cout<<"-----------------------"<<std::endl;
 std::cout<<"* Enter alpha [0-1]: ";
 std::cin>>input;

 /// We use the alpha provided by the user if it is between 0 and 1
 if( input >= 0.0 && input <= 1.0 )
   { alpha = input; }

 /// Read image ( same size, same type )
 src1 = imread("../../images/LinuxLogo.jpg");
 src2 = imread("../../images/WindowsLogo.jpg");

 if( !src1.data ) { printf("Error loading src1 \n"); return -1; }
 if( !src2.data ) { printf("Error loading src2 \n"); 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;
}

 

 

注意 :可以用 src1=src1(Range(0:cols),Range(0:rows));

来进行图像的截取,而且,是先cols 然后 rows

OpenCV Tutorials —— Adding (blending) two images using OpenCV

标签:style   http   io   ar   os   sp   div   on   art   

原文地址:http://www.cnblogs.com/sprint1989/p/4101794.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!