本教程开始介绍的源代码将对每一帧执行PSNR测量,并且只对PSNR低于输入值的帧进行SSIM测量。为了可视化的目的,我们在OpenCV窗口中展示两幅图像,并将PSNR和MSSIM值打印到控制台。期望看到如下内容:
video-input-psnr-ssim.cpp 将两个视频的每一帧逐一读取并计算其峰值信号噪声比(PSNR) 和 结构相似性指标(MSSIM)
#include <iostream> // 标准输入输出流
#include <string> // 字符串操作库
#include <iomanip> // 输入输出流格式控制
#include <sstream> // 字符串与数字转换
#include <opencv2/core.hpp> // OpenCV基础结构 (cv::Mat, Scalar)
#include <opencv2/imgproc.hpp> // 高斯模糊处理
#include <opencv2/videoio.hpp>
#include <opencv2/highgui.hpp> // OpenCV窗口输入输出
using namespace std;
using namespace cv;
double getPSNR(const Mat& I1, const Mat& I2); // 声明计算PSNR值的函数
Scalar getMSSIM(const Mat& I1, const Mat& I2); // 声明计算MSSIM值的函数
static void help() // 帮助文本输出函数
{
cout
<< "------------------------------------------------------------------------------" << endl
<< "This program shows how to read a video file with OpenCV. In addition, it "
<< "tests the similarity of two input videos first with PSNR, and for the frames "
<< "below a PSNR trigger value, also with MSSIM." << endl
<< "Usage:" << endl
<< "./video-input-psnr-ssim <re