-
Notifications
You must be signed in to change notification settings - Fork 2
/
add_frame.cpp
executable file
·117 lines (97 loc) · 2.99 KB
/
add_frame.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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
#include <iostream>
#include<opencv2/opencv.hpp>
#include <opencv2/imgproc/imgproc.hpp>
#include "add_frame.h"
#include <QtCore>
#include <QWidget>
using namespace std;
using namespace cv;
Mat QImage2cvMatframe(QImage image) {
cv::Mat mat;
cv::Mat dst;
switch(image.format())
{
case QImage::Format_ARGB32:
case QImage::Format_RGB32:
case QImage::Format_ARGB32_Premultiplied:
image = image.convertToFormat(QImage::Format_RGB888);
mat = cv::Mat(image.height(), image.width(), CV_8UC3, (void*)image.constBits(), image.bytesPerLine());
cv::cvtColor(mat, dst, COLOR_BGR2RGB);
break;
case QImage::Format_RGB888:
mat = cv::Mat(image.height(), image.width(), CV_8UC3, (void*)image.constBits(), image.bytesPerLine());
cv::cvtColor(mat, dst, COLOR_BGR2RGB);
break;
case QImage::Format_Indexed8:
mat = cv::Mat(image.height(), image.width(), CV_8UC1, (void*)image.constBits(), image.bytesPerLine());
break;
}
return dst;
}
Mat addframe(Mat img, int frame_num){
// Mat frame1, frame2, frame3, frame4;
int parameter = 10;
if (frame_num == 1)
{
parameter = 10;
QImage *frameImage1;
frameImage1 = new QImage(":/images/heart.jpg");
frame = QImage2cvMatframe(*frameImage1);
}
if (frame_num == 2)
{
parameter = 30;
QImage *frameImage2;
frameImage2 = new QImage(":/images/Gauty.jpg");
frame = QImage2cvMatframe(*frameImage2);
}
if (frame_num == 3)
{
parameter = 10;
QImage *frameImage3;
frameImage3 = new QImage(":/images/COCOa.jpg");
frame = QImage2cvMatframe(*frameImage3);
}
if (frame_num == 4)
{
parameter = 100;
QImage *frameImage4;
frameImage4 = new QImage(":/images/Vintage.jpg");
frame = QImage2cvMatframe(*frameImage4);
}
resize(frame, frame, Size(img.cols,img.rows), 0, 0, INTER_LINEAR);
cvtColor(frame,mask,COLOR_BGR2GRAY);
bitwise_not(mask, mask);
threshold(mask, mask, parameter, 255, THRESH_BINARY);
frame.copyTo(img,mask);
return img.clone();
}
Mat addframe_cv(Mat img, int mode){
top = int (0.15*img.rows);
bottom = static_cast<int> (0.15*img.rows);
int left = static_cast<int> (0.15*img.cols);
int right = static_cast<int> (0.15*img.cols);
//边缘模糊
if(mode == 1){
borderType=BORDER_REPLICATE;
copyMakeBorder( img, dst, top, bottom, left, right, borderType);
}
//边缘翻转
if (mode==2){
borderType=BORDER_REFLECT_101;
copyMakeBorder( img, dst, top, bottom, left, right, borderType);
}
//黑边框
if(mode == 3){
Scalar value(0 ,0, 0);
borderType=BORDER_CONSTANT;
copyMakeBorder( img, dst, top, bottom, left, right, borderType,value);
}
//白边框
if(mode == 4){
Scalar value2(255,255,255);
borderType=BORDER_CONSTANT;
copyMakeBorder( img, dst, top, bottom, left, right, borderType,value2);
}
return dst;
}