⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 speed.cpp

📁 SiftGPU is an implementation of SIFT [1] for GPU. SiftGPU processes pixels parallely to build Gaussi
💻 CPP
字号:
////////////////////////////////////////////////////////////////////////////
//	File:		Speed.cpp
//	Author:		Changchang Wu
//	Description : Evaluate the speed of SiftGPU 
//
//
//
//	Copyright (c) 2007 University of North Carolina at Chapel Hill
//	All Rights Reserved
//
//	Permission to use, copy, modify and distribute this software and its
//	documentation for educational, research and non-profit purposes, without
//	fee, and without a written agreement is hereby granted, provided that the
//	above copyright notice and the following paragraph appear in all copies.
//	
//	The University of North Carolina at Chapel Hill make no representations
//	about the suitability of this software for any purpose. It is provided
//	'as is' without express or implied warranty. 
//
//	Please send BUG REPORTS to ccwu@cs.unc.edu
//
////////////////////////////////////////////////////////////////////////////


#include <stdlib.h>
#include <vector>
#include <iostream>
using std::cout;

#ifdef _WIN32
	//dll import definition for win32
	#define SIFTGPU_DLL
	#ifdef _DEBUG
		#pragma comment(lib, "../lib/siftgpu_d.lib")
	#else
		#pragma comment(lib, "../lib/siftgpu.lib")
	#endif

#endif


#if defined(_WIN32)
	#define WIN32_LEAN_AND_MEAN
	#include <windows.h>
	#include <mmsystem.h>
	#pragma comment(lib, "Winmm.lib")
#else
	#include <sys/time.h>
#endif



#include "../../SiftGPU/src/SiftGPU.h"

#define SIFTGPU_REPEAT 30

//you should specify the input image and the sift parameter to speed.exe
// for example: speed.exe -i 600.pgm  -fo -1
// to test CUDA, you first need to recompile SiftGPU with CUDA capability

int GetMilliSecond();

int main(int argc, char * argv[])
{
 
	SiftGPU sift;
	int num;
	float timing[10], time_all =0, time_start;


	//Parse parameters
	sift.ParseParam(argc - 1, argv + 1);
	sift.SetVerbose(0); 

	//create an OpenGL context for computation
	if(sift.CreateContextGL() ==0) return 0;
	

	std::cout<<"Initialize and run... ";
	if(sift.RunSIFT()==0)	return 0;

	//image is loaded for only once for this experiment
	std::cout<<"Loading image: " << sift._timing[0]*1000 << "ms, "
	         <<"Tex initialization: "<<sift._timing[1]*1000 << "ms\n\n"
	         <<"Start 2x"<<SIFTGPU_REPEAT<<" repetitions...\n";

	//run one more time to get all texture allocated

	sift.RunSIFT();
	num = sift.GetFeatureNum();


	//use no message output mode to get maximum speed.
	time_start = (float) GetMilliSecond();
	for(int i = 0; i < SIFTGPU_REPEAT; i++)
	{
		sift.RunSIFT();
		std::cout <<"+";
	}
	time_all = ((float)GetMilliSecond() - time_start)/1000/SIFTGPU_REPEAT;
	std::cout<<"\n"; 

	//change the timing setting, so that we can get more accurate timing for each steps
	//in this mode, the overal speed will be decreased.
	sift.SetVerbose(-2); //little trick to disable all output but keep the timing
	std::fill(timing, timing + 10, 0.0f);
	for(int k = 0; k < SIFTGPU_REPEAT; k++)
	{
		sift.RunSIFT();
		for(int j = 0; j < 10; j++)		timing[j] += sift._timing[j];
		std::cout <<"#";
	}
	for(int j = 0; j < 10; j++) 	timing[j] /= SIFTGPU_REPEAT;

	std::cout
		<<"\n\n****************************************\n"
		<<"[Feature Count]:\t" << num << "\n"
		<<"[Average Time]:\t\t" << time_all * 1000.0f << "ms\n"
		<<"[Average Speed]:\t" << 1.0 / time_all << "hz\n"
		<<"[Build Pyramid]:\t" << timing[2] * 1000.0f << "ms\n"
		<<"[Detection]:\t\t" << timing[3] * 1000.0f << "ms\n"
		<<"[Feature List]:\t\t" << timing[4] * 1000.0f << "ms\n"
		<<"[Orientation]:\t\t" << timing[5] * 1000.0f << "ms\n"
		<<"[MO Feature List]:\t" << timing[6] * 1000.0f << "ms\n"
		<<"[Download Keys]:\t" << timing[7] * 1000.0f << "ms\n"
		<<"[Descriptor]:\t\t" << timing[8] * 1000.0f << "ms\n"
		<<"****************************************\n";

	return 1;
}





int GetMilliSecond()
{
	static int    started = 0;
#ifdef _WIN32
	//the resolution of teimGetTime will be changed to 1ms inside SiftGPU
	static int	tstart;
	if(started == 0)
	{
		tstart = timeGetTime();
		started = 1;
		return 0;
	}else
	{
		return timeGetTime() - tstart;
	}
#else
	static struct timeval tstart;
	if(started == 0) 
	{
		gettimeofday(&tstart, NULL);
		started = 1;
		return 0;
	}else
	{	
		struct timeval now;
		gettimeofday(&now, NULL) ;
		return (now.tv_usec - tstart.tv_usec)/1000 + (now.tv_sec - tstart.tv_sec) * 1000;
	}
#endif
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -