虚拟视点图像生成012

马上要毕业了,比较忙,有半年多没有更新博客了,在毕业之际,对以前写的代码进行整理封装,以备后来者改进,希望长江后浪推前浪,一代更比一点强!

整理原有代码,封装为c++类的形式。

分为三个类:即配置类、点映射类和图像映射类。一个基础函数库。一个demo。一个配置文件。

主函数接口:main_virtual_viewpoint_rendering.cpp

基于函数库:base_function.h base_function.cpp

配置类:configure.h configure.cpp

点映射类:point_mapping.h point_mapping.cpp

图像映射类:image_mapping.h image_mapping.cpp

配置文件:conf_file.txt

main_virtual_viewpoint_rendering.cpp

#include "configure.h"
#include "image_mapping.h"
#include "base_function.h"
#include <fstream>
#include <iostream>

using namespace std;
int main(){
	Configure cfg("D:\\virtual_viewpoint_rendering\\conf\\conf_file.txt");

	char filename[100];
	strcpy(filename, cfg.m_psnr_ssim_file);
	char time_buf[15];
	strcat_s(filename, getNewFileName(time_buf));
	strcat_s(filename, ".txt");
	ofstream fout(filename);

	ImageMapping imgmp(&cfg);
	char str_left[200][200];
	char str_right[200][200];
	char str_virtual[200][200];
	double value_psnr = 0;
	double value_ssim = 0;
	getArrayOfImageFile(&cfg, str_left, str_right, str_virtual);
	for (int i = 0; i < 100; i++){
		imgmp.process(str_left[i], str_left[i + 100], str_right[i], str_right[i+100]);

		value_psnr += psnr(imgmp.save_dirr, str_virtual[i]);
		printf("psnr=%lf\n", value_psnr / (i + 1));
		fout << value_psnr / (i + 1) << "\t"; 

		value_ssim += ssim(imgmp.save_dirr, str_virtual[i]);
		printf("ssim=%lf\n", value_ssim / (i + 1));
		fout << value_ssim / (i + 1) << "\t"; 

		fout << endl;
	}
	cout << "process finished!!!!!!!!!!!!!!!!!!!!!!!!"<<endl;
	cout << "******************************************************************"<<endl;
	fout << "process finished!!!!!!!!!!!!!!!!!!!!!!!!"<<endl;
	fout << "*****************************************************************" << endl;
	return 0;
}

base_function.h

#ifndef __base_function__
#define __base_function__

#include "configure.h"
#include "opencv2/imgproc/imgproc.hpp"
#include "opencv2/highgui/highgui.hpp"
#include <time.h>
#include <stdio.h>
#include <math.h>
#include <cv.h>
using namespace std;

char *getNewFileName(char time_buf[15]/*YYYYMMDDhhmmss*/);
double round_off(double x);
double max(double x, double y);
double ssim(char *ref_image, char *obj_image);
double psnr(char *ref_image, char *obj_image);
void getArrayOfImageFile(Configure *cfg, char str_left[200][200], char str_right[200][200], char str_virtual[200][200]);
#endif //__base_function__
base_function.cpp
#include "base_function.h"

char *getNewFileName(char time_buf[15]/*YYYYMMDDhhmmss*/){
	time_t aclock;
	time(&aclock);
	strftime(time_buf, 15, "%Y%m%d%H%M%S", localtime(&aclock));
	//printf("%s\n", tmpbuf);
	return time_buf;
}
double round_off(double x)
{
	double temp = floor(x + 0.5);
	return temp;
}
double max(double x, double y) {
	return ((x > y) ? x : y);
}
double 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->height;
	int nChan = img1_temp->nChannels, d = IPL_DEPTH_32F;
	CvSize size = cvSize(x, y);

	img1 = cvCreateImage(size, d, nChan);
	img2 = cvCreateImage(size, d, nChan);

	cvConvert(img1_temp, img1);
	cvConvert(img2_temp, img2);
	cvReleaseImage(&img1_temp);
	cvReleaseImage(&img2_temp);


	img1_sq = cvCreateImage(size, d, nChan);
	img2_sq = cvCreateImage(size, d, nChan);
	img1_img2 = cvCreateImage(size, d, nChan);

	cvPow(img1, img1_sq, 2);
	cvPow(img2, img2_sq, 2);
	cvMul(img1, img2, img1_img2, 1);

	mu1 = cvCreateImage(size, d, nChan);
	mu2 = cvCreateImage(size, d, nChan);

	mu1_sq = cvCreateImage(size, d, nChan);
	mu2_sq = cvCreateImage(size, d, nChan);
	mu1_mu2 = cvCreateImage(size, d, nChan);


	sigma1_sq = cvCreateImage(size, d, nChan);
	sigma2_sq = cvCreateImage(size, d, nChan);
	sigma12 = cvCreateImage(size, d, nChan);

	temp1 = cvCreateImage(size, d, nChan);
	temp2 = cvCreateImage(size, d, nChan);
	temp3 = cvCreateImage(size, d, nChan);

	ssim_map = cvCreateImage(size, d, nChan);
	/*************************** END INITS **********************************/


	//
	// PRELIMINARY COMPUTING
	cvSmooth(img1, mu1, CV_GAUSSIAN, 11, 11, 1.5);
	cvSmooth(img2, mu2, CV_GAUSSIAN, 11, 11, 1.5);

	cvPow(mu1, mu1_sq, 2);
	cvPow(mu2, mu2_sq, 2);
	cvMul(mu1, mu2, mu1_mu2, 1);


	cvSmooth(img1_sq, sigma1_sq, CV_GAUSSIAN, 11, 11, 1.5);
	cvAddWeighted(sigma1_sq, 1, mu1_sq, -1, 0, sigma1_sq);

	cvSmooth(img2_sq, sigma2_sq, CV_GAUSSIAN, 11, 11, 1.5);
	cvAddWeighted(sigma2_sq, 1, mu2_sq, -1, 0, sigma2_sq);

	cvSmooth(img1_img2, sigma12, CV_GAUSSIAN, 11, 11, 1.5);
	cvAddWeighted(sigma12, 1, mu1_mu2, -1, 0, sigma12);


	//
	// FORMULA

	// (2*mu1_mu2 + C1)
	cvScale(mu1_mu2, temp1, 2);
	cvAddS(temp1, cvScalarAll(C1), temp1);

	// (2*sigma12 &
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值