forked from oreillymedia/Learning-OpenCV-3_examples
-
Notifications
You must be signed in to change notification settings - Fork 0
/
example_05-01.cpp
52 lines (40 loc) · 1.4 KB
/
example_05-01.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
// alphablend <imageA> <image B> <x> <y> <width> <height> <alpha> <beta>
//
//#include <opencv2/opencv.hpp>
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
int main(int argc, char** argv) {
// Using the first two arguments, open up the image to be copied onto
// (src1), and the image that will be copied from (src2).
//
cv::Mat src1 = cv::imread(argv[1],1);
cv::Mat src2 = cv::imread(argv[2],1);
if( argc==9 && !src1.empty() && !src2.empty() ) {
// Four more arguments tell where in src1 to paste the chunk taken from
// src2. Note that the width and height also specify what portion of
// src2 to actually use.
//
int x = atoi(argv[3]);
int y = atoi(argv[4]);
int w = atoi(argv[5]);
int h = atoi(argv[6]);
// Two more arguments set the blending coefficients.
//
double alpha = (double)atof(argv[7]);
double beta = (double)atof(argv[8]);
cv::Mat roi1( src1, cv::Rect(x,y,w,h) );
cv::Mat roi2( src2, cv::Rect(0,0,w,h) );
// Blend together the image src2 onto the image src1
// at the specified location.
//
cv::addWeighted( roi1, alpha, roi2, beta, 0.0, roi2 );
// Create a window to shoow the result and show it.
//
cv::namedWindow( "Alpha Blend", 1 );
cv::imshow( "Alpha Blend", src2 );
// Leave the window up and runnnig until the user hits a key
//
cv::waitKey( 0 );
}
return 0;
}