-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCV_Alpha_Blending
59 lines (45 loc) · 1.57 KB
/
CV_Alpha_Blending
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
53
54
55
56
57
58
59
// OpenCV Alpha Blending Tutorial modified for Face Morphing
#include <cv.h>
#include <highgui.h>
#include <iostream>
using namespace cv;
using namespace std;
int main()
{
double alpha = 0.5, beta, input;
Mat src1, src2, dst;
// Ask user to enter alpha
cout << " Simple Linear Blender " << endl;
cout << "-----------------------" << endl;
cout << " Enter alpha [0-1]: ";
cin >> input;
// We use the alpha provided by user if its between 0 and 1
if( input >= 0.0 && input <= 1.0 )
alpha = input;
// Read image (same size, same type )
src1 = imread("f1.jpg");//Linux.jpg");//atom.jpg");//"Linux.jpg"); //f1.jpg
src2 = imread("f2.jpg");//Windows.jpg");//fool.jpg");//"Windows.jpg"); //f2.jpg
if( !src1.data ) { printf("Error loadind src1 \n"); return -1;}
if( !src2.data ) { printf("Error loadind src2 \n"); return -1;}
// Create windows
//namedWindow("Windows Logo", CV_WINDOW_AUTOSIZE );
//namedWindow("Linux Logo", CV_WINDOW_AUTOSIZE );
namedWindow("Linear Blend", CV_WINDOW_AUTOSIZE );
//imshow( "Linux Logo", src1 );
//imshow( "Windows Logo", src2 );
// Uncomment the below 'for' loop for morphing effect
for(int k = 0; k <= 100; ++k )
{
alpha = (double)k/100;
beta = 1 - alpha;
//double t = (double)getTickCount(); // To calculate time reqd.
addWeighted( src2, alpha, src1, beta, 0.0, dst );
//t = ((double)getTickCount() - t)/getTickFrequency();
//cout << "Linear blnding took " << t*1000 << " milliseconds." << endl;
//imwrite("CV_Blending_dst_Gamma0.jpg", dst);
imshow( "Linear Blend", dst );
cvWaitKey(50);
}
cvWaitKey();
return 0;
}