-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBlending.cpp
More file actions
43 lines (31 loc) · 1.16 KB
/
Blending.cpp
File metadata and controls
43 lines (31 loc) · 1.16 KB
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
//
// Created by stephan on 03.04.19.
//
#include "Blending.h"
cv::Mat Blending::blend() {
double alpha = 0.5; double beta;
cv::Mat src1, src2, dst;
src1 = cv::imread("img/test.jpg");
src2 = cv::imread("img/test2.jpg");
if( !src1.data ) { printf("Error loading src1 \n"); return src1; }
if( !src2.data ) { printf("Error loading src2 \n"); return src1; }
/// Create Windows
//cv::namedWindow("Linear Blend", 1);
int width, height;
if(src1.cols > src2.cols) width = src1.cols;
else width = src2.cols;
if(src1.rows > src2.rows) height = src1.rows;
else height = src2.rows;
cv::Mat img1(height, width, CV_8UC3, cv::Scalar(0, 0, 0));
src1.copyTo(img1(cv::Rect(0,0,src1.cols, src1.rows)));
int min_x = ( img1.cols - src2.cols)/2;
int min_y = ( img1.rows - src2.rows)/2;
cv::Rect roi = cv::Rect(min_x, min_y, src2.cols, src2.rows);
cv::Mat out_image = img1.clone();
cv::Mat A_roi= img1(roi);
cv::Mat out_image_roi = out_image(roi);
beta = ( 1.0 - alpha );
cv::addWeighted(A_roi,alpha,src2, beta,0.0,out_image_roi);
//imshow( "Linear Blend", out_image_roi );
return out_image_roi;
}