1 #include <iostream>
2
3 #include "opencv2/core/opengl.hpp"
4 #include "opencv2/highgui/highgui.hpp"
5 #include "opencv2/cudaimgproc.hpp"
6
7 using namespace std;
8 using namespace cv;
9 using namespace cv::cuda;
10
main()11 int main()
12 {
13 cout << "This program demonstrates using alphaComp" << endl;
14 cout << "Press SPACE to change compositing operation" << endl;
15 cout << "Press ESC to exit" << endl;
16
17 namedWindow("First Image", WINDOW_NORMAL);
18 namedWindow("Second Image", WINDOW_NORMAL);
19 namedWindow("Result", WINDOW_OPENGL);
20
21 setGlDevice();
22
23 Mat src1(640, 480, CV_8UC4, Scalar::all(0));
24 Mat src2(640, 480, CV_8UC4, Scalar::all(0));
25
26 rectangle(src1, Rect(50, 50, 200, 200), Scalar(0, 0, 255, 128), 30);
27 rectangle(src2, Rect(100, 100, 200, 200), Scalar(255, 0, 0, 128), 30);
28
29 GpuMat d_src1(src1);
30 GpuMat d_src2(src2);
31
32 GpuMat d_res;
33
34 imshow("First Image", src1);
35 imshow("Second Image", src2);
36
37 int alpha_op = ALPHA_OVER;
38
39 const char* op_names[] =
40 {
41 "ALPHA_OVER", "ALPHA_IN", "ALPHA_OUT", "ALPHA_ATOP", "ALPHA_XOR", "ALPHA_PLUS", "ALPHA_OVER_PREMUL", "ALPHA_IN_PREMUL", "ALPHA_OUT_PREMUL",
42 "ALPHA_ATOP_PREMUL", "ALPHA_XOR_PREMUL", "ALPHA_PLUS_PREMUL", "ALPHA_PREMUL"
43 };
44
45 for(;;)
46 {
47 cout << op_names[alpha_op] << endl;
48
49 alphaComp(d_src1, d_src2, d_res, alpha_op);
50
51 imshow("Result", d_res);
52
53 char key = static_cast<char>(waitKey());
54
55 if (key == 27)
56 break;
57
58 if (key == 32)
59 {
60 ++alpha_op;
61
62 if (alpha_op > ALPHA_PREMUL)
63 alpha_op = ALPHA_OVER;
64 }
65 }
66
67 return 0;
68 }
69