-
Notifications
You must be signed in to change notification settings - Fork 4
/
vqats.hh
97 lines (80 loc) · 3 KB
/
vqats.hh
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
/*
* Video Quality Assessment Tool using SSIM (VQATS).
* Written by Kah Keng Tay, kahkeng AT gmail DOT com, 2008.
*
* This tool computes VSSIM*, a similarity score between two videos, when given
* their image sequences as input. When comparing any two frames, we average the
* RGB SSIM values and use that as the overall video SSIM index for the frames.
*
* Features:
* - accomodates frame skips and stalls in input videos.
* - performs such alignment automatically and quickly.
* - minimize computation to keep things fast.
*
* Credit goes to:
* - Zhou Wang for the SSIM metric. http://www.ece.uwaterloo.ca/~z70wang/research/ssim/
* - Rabah Mehdi for original SSIM OpenCV code. http://mehdi.rabah.free.fr/
* - John-Mark Gurney for fib package. http://resnet.uoregon.edu/~gurney_j/jmpc/fib.html
*/
#include <utility>
#include <map>
#include <set>
#include <vector>
#include <list>
#include <string>
#include <opencv/cv.h>
#include <opencv/highgui.h>
// default settings for SSIM computation
#define C1 6.5025
#define C2 58.5225
#define W_Y 0.8
#define W_Cr 0.1
#define W_Cb 0.1
#define INF 1e9
#ifndef CACHE_SIZE
#define CACHE_SIZE 20 // number of frames in cache for each video
#endif
#define INSERTED_FRAME 0.0 // score for an inserted frame, with 1.0 being best possible score
#define DELETED_FRAME 0.0 // score for an inserted frame, with 1.0 being best possible score
typedef double score_t;
typedef uint16_t video_t;
typedef uint16_t frame_t;
struct FrameData
{
FrameData();
~FrameData();
bool load(); // load the image, returns true if image is now loaded
bool unload(); // unload the image, returns true if image got unloaded
bool _loaded; // whether this image is loaded yet
frame_t _index; // the frame index number
std::string _path; // the path to the image
IplImage *_image; // image object
#ifndef SAMPLING_SIZE
IplImage *_image_sq, *_mu, *_mu_sq, *_sigma_sq; // other preprocessed computations
#endif
CvSize _size;
int _nChannels, _depth;
};
struct VideoData
{
typedef std::vector<FrameData> FrameList;
typedef std::list<frame_t> CacheList;
FrameList _frames; // sequence of video frames
CacheList _cache;
};
class VQATS;
score_t compute_video_score(VQATS& v, const video_t& video1, const video_t& video2); // returns the similarity score between two videos
class VQATS
{
friend score_t compute_video_score(VQATS& v, const video_t& video1, const video_t& video2);
public:
typedef std::map<video_t, VideoData> VideoMap;
VQATS();
~VQATS();
video_t load_video(std::string filename); // takes as input an ascii file that has paths to images of the sequence on separate lines
private:
score_t compute_frame_score(const video_t& video1, const video_t& video2, const frame_t& index1, const frame_t& index2); // returns the similarity score between two frames
bool load_video_frame(const video_t& video_index, const frame_t& frame_index); // loads the video frame into cache
VideoMap _video_map;
video_t _num_videos;
};