-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmainBrisque.cpp
118 lines (92 loc) · 3.16 KB
/
mainBrisque.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 <string>
#include <iomanip> // for controlling float print precision
#include <sstream> // string to number conversion
#include <opencv2/core/core.hpp>
#include <opencv2/imgproc/imgproc.hpp> // Gaussian Blur
#include <opencv2/highgui/highgui.hpp>
#include "brisque/brisque.h"
#include "brisque/libsvm/svm.h"
#include "useCameraInput.h"
#include <fstream> // to create the csv file i'll plot later with Python:metaplot()
using namespace std;
using namespace cv;
float getBrisque(cv::Mat frame,int frameNum, svm_model *model);
int main(int argc, char *argv[])
{
if (argc != 3) {
cout << "Not enough parameters" << endl;
return -1;
}
string videoSource;
if(std::strcmp(argv[1],"0") != 0) {
videoSource = argv[1];
} else {
videoSource = useCameraInput();
}
int delay = std::stoi(argv[2]);;
/*conv << argv[2] << endl;
conv >> delay; */
char c; // to stop
int frameNum = -1; // Frame counter
VideoCapture captRefrnc(videoSource);
if (!captRefrnc.isOpened())
{
cout << "Could not open video " << videoSource << endl;
return -1;
}
Size refS = Size((int) captRefrnc.get(CAP_PROP_FRAME_WIDTH),
(int) captRefrnc.get(CAP_PROP_FRAME_HEIGHT));
const char* WIN_RF = "Reference";
// Windows
namedWindow(WIN_RF, WINDOW_AUTOSIZE);
moveWindow(WIN_RF, 400 , 0);
cout << "Reference frame resolution: Width=" << refS.width << " Height=" << refS.height
<< " of nr#: " << captRefrnc.get(CAP_PROP_FRAME_COUNT) << endl;
cv::Mat frame;
double psnrV;
cv::Scalar mssimV;
struct svm_model *model = (struct svm_model *) svm_load_model("allmodel");
float brisqueValue;
// calculate how many frames in the video
double countFrame = captRefrnc.get(CAP_PROP_FRAME_COUNT) / 2;
std::ofstream outf{ "result.csv" };
if (!outf) {
std::cerr << "result.csv could not be opened for writing!\n";
return 1;
}
outf << "frame,brisque";
outf << "\n";
for(;;) //Show the image captured in the window and repeat
{
captRefrnc >> frame;
if (frame.empty()) {
cout << " < < < Video ended! > > > ";
break;
}
++frameNum;
brisqueValue = getBrisque(frame,frameNum, model);
if(frameNum >= 0) {
String line = std::to_string(frameNum) + "," + std::to_string(brisqueValue);
outf << line;
outf << "\n";
}
const string text = "Brisque at Frame " + std::to_string(frameNum) + ": " + std::to_string(brisqueValue);
cv::putText(frame,
text,
cv::Point(10, frame.rows / 4),
cv::FONT_HERSHEY_DUPLEX,1.0,CV_RGB(118, 185, 0),2);
cout << endl;
imshow(WIN_RF, frame);
c = (char) waitKey(delay);
if (c == 27) break;
}
// remove the 0,nan value
return 0;
}
float getBrisque(cv::Mat frame,int frameNum, svm_model *model)
{
float score = computescore(frame,model,frameNum);
std::cout << "Frame " << frameNum << " score " << score << std::endl;
return score;
}