结合网络上的资料和自己的修改,实现了psnr和ssim的c++版本。
#include<iostream>
#include<opencv2\opencv.hpp>
#include <math.h>
#include <stdio.h>
#include <cv.h>
#include <highgui.h>
using std::cout;
using std::endl;
int ssim(char *ref_image, char *obj_image)
{
// default settings
double C1 = 6.5025, C2 = 58.5225;
IplImage
*img1 = NULL, *img2 = NULL, *img1_img2 = NULL,
*img1_temp = NULL, *img2_temp = NULL,
*img1_sq = NULL, *img2_sq = NULL,
*mu1 = NULL, *mu2 = NULL,
*mu1_sq = NULL, *mu2_sq = NULL, *mu1_mu2 = NULL,
*sigma1_sq = NULL, *sigma2_sq = NULL, *sigma12 = NULL,
*ssim_map = NULL, *temp1 = NULL, *temp2 = NULL, *temp3 = NULL;
/***************************** INITS **********************************/
img1_temp = cvLoadImage(ref_image);
img2_temp = cvLoadImage(obj_image);
if (img1_temp == NULL || img2_temp == NULL)
return -1;
int x = img1_temp->width, y = img1_temp-&