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

📄 siftgpu.cpp

📁 SiftGPU is an implementation of SIFT [1] for GPU. SiftGPU processes pixels parallely to build Gaussi
💻 CPP
📖 第 1 页 / 共 3 页
字号:
			GlobalUtil::_SubpixelLocalization = min(max(0, sp),5);
		}
		else if(_stricmp(opt, "ofix")==0)
		{
			GlobalUtil::_FixedOrientation = 1;
		}else if(_stricmp(opt, "ofix-not")==0)
		{
			GlobalUtil::_FixedOrientation = 0;
		}else if(_stricmp(opt, "loweo")==0)
		{
			GlobalUtil::_LoweOrigin = 1;
		}else if(_stricmp(opt, "fastmath")==0)
		{
			GlobalUtil::_UseFastMath = 1;
		}else if(_stricmp(opt, "narrow")==0)
		{
			GlobalUtil::_NarrowFeatureTex = 1;
		}else if(_stricmp(opt, "debug")==0)
		{
			GlobalUtil::_debug = 1;
		}else if(i+1>=argc)
		{
			//make sure there is the param			
		}else if(_stricmp(opt, "i")==0)
		{
			strcpy(_imgpath, param);
			i++;
			//get the file list..
			_list->push_back(param);
			while( i+1 < argc && argv[i+1][0] !='-')
			{
				_list->push_back(argv[++i]);
			}
		}else if(_stricmp(opt, "il")==0)
		{
			LoadImageList(param);
			i++;
		}else if( _stricmp(opt, "o")==0)
		{
			strcpy(_outpath, param);
			i++;
		}else if( _stricmp(opt, "f")==0 )
		{

			float factor;
			sscanf(param, "%f", &factor);
			if(factor>0 )
			{
				GlobalUtil::_FilterWidthFactor  = factor;
				i++;
			}
		}else if( _stricmp(opt, "ot")==0 )
		{

			float factor;
			sscanf(param, "%f", &factor);
			if(factor>0 )
			{
				GlobalUtil::_MulitiOrientationThreshold  = factor;
				i++;
			}
		}else if(_stricmp(opt, "w")==0 )
		{

			float factor;
			sscanf(param, "%f", &factor);
			if(factor>0 )
			{
				GlobalUtil::_OrientationWindowFactor  = factor;
				i++;
			}
		}else if(_stricmp(opt, "dw")==0 )
		{

			float factor;
			sscanf(param, "%f", &factor);
			if(factor>0 )
			{
				GlobalUtil::_DescriptorWindowFactor  = factor;
				i++;
			}
		}else if(_stricmp(opt, "fo")==0)
		{

			int first_octave;
			sscanf(param, "%d", &first_octave);
			if(first_octave >=-2 )
			{
				GlobalUtil::_octave_min_default = first_octave;
				i++;
			}

		}else if(_stricmp(opt, "no")==0)
		{

			int octave_num=-1;
			sscanf(param, "%d", &octave_num);
			if(octave_num<=0) octave_num = -1;

			if(octave_num ==-1 || octave_num >=1)
			{
				GlobalUtil::_octave_num_default = octave_num;
				i++;
			}

		}else if( _stricmp(opt, "t")==0)
		{

			float threshold;
			sscanf(param, "%f", &threshold);
			if(threshold >0 && threshold < 0.5)
			{
				SiftParam::_dog_threshold = threshold;
				i++;
			}
		}else if(_stricmp(opt, "e")==0 )
		{
			float threshold;
			sscanf(param, "%f", &threshold);
			if(threshold >0 )
			{
				SiftParam::_edge_threshold = threshold;
				i++;
			}
		}else if(_stricmp(opt, "d")==0)
		{
			int num;
			sscanf(param, "%d", &num);
			if(num >=1 && num <=10)
			{
				SiftParam::_dog_level_num = num;
				i++;
			}

		}else if(_stricmp(opt, "fs")==0)
		{
			int num;
			sscanf(param, "%d", &num);
			if(num >=1)
			{
				GlobalParam::_FeatureTexBlock = num;
				i++;
			}

		}else if(_stricmp(opt, "p")==0)
		{
			int w =0, h=0;
			sscanf(param, "%dx%d", &w, &h);
			if(w >0 &&  h>0)
			{
				GlobalParam::_InitPyramidWidth = w;
				GlobalParam::_InitPyramidHeight = h;
			}
		}else if(_stricmp(opt, "levelmax")==0 || _stricmp(opt, "lm")==0)
		{
			int num;
			sscanf(param, "%d", &num);
			if(num >=1000)
			{
				GlobalParam::_MaxLevelFeatureNum = num;
				i++;
			}
		}else if(_stricmp(opt, "levelmaxpercent")==0 || _stricmp(opt, "lmp")==0)
		{
			float num;
			sscanf(param, "%f", &num);
			if(num >=0.001)
			{
				GlobalParam::_MaxFeaturePercent = num;
				i++;
			}
		}else if(_stricmp(opt, "v")==0 )
		{
			int num;
			sscanf(param, "%d", &num);
			if(num >=0 && num <=5)
			{
				SetVerbose(num);
			}
		}else if(_stricmp(opt, "maxd")==0 )
		{
			int num;
			sscanf(param, "%d", &num);
			if(num > 0)
			{
				GlobalUtil::_texMaxDim = num; 
				setMaxD = 1;
			}
		}
	}

	if(setMaxD == 0) GlobalUtil::_texMaxDim = GlobalUtil::_usePackedTex ? 3200 : 2560;

	//do not write result if there are more than one input images
	if(_outpath[0] && _list->size()>1)		_outpath[0] = 0;
} 

void SiftGPU::SetImageList(int nimage, const char** filelist)
{
	_list->resize(0);
	for(int i = 0; i < nimage; i++)
	{
		_list->push_back(filelist[i]);
	}
	_current = 0;

}
void SiftGPU:: LoadImageList(char *imlist)
{
	char filename[_MAX_PATH];
	ifstream in(imlist);
	while(in>>filename)
	{
		_list->push_back(filename);
	}
	in.close();


	if(_list->size()>0)
	{
		strcpy(_imgpath, _list->at(0).data());
		strcpy(filename, imlist);
		char * slash = strrchr(filename, '\\');
		if(slash == 0) slash = strrchr(filename, '/');
		if(slash )
		{
			slash[1] = 0;
			chdir(filename);
		}
	}
	_image_loaded = 0;


}
float SiftParam::GetLevelSigma( int lev)
{
	return _sigma0 * powf( 2.0f,  float(lev) / float(_dog_level_num )); //bug fix 9/12/2007
}

void SiftGPUEX::DisplayFeatureBox(int view )
{
	view = view%3;
	if(view<0)view+=3;
	if(view ==2) return;
	int idx = 0;
	const int *fnum = _pyramid->GetLevelFeatureNum();
	const GLuint *vbo = _pyramid->GetFeatureDipslayVBO();
	const GLuint *vbop = _pyramid->GetPointDisplayVBO();
	if(vbo == NULL || vbop == NULL) return;
	//int  nvbo = _dog_level_num * _pyramid->_octave_num;
	glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
	glEnableClientState(GL_VERTEX_ARRAY);
	glPushMatrix();
//	glTranslatef(0.0f, 0.0f, -1.0f);
	glPointSize(2.0f);

	float scale = 1.0f;
	if(_pyramid->_octave_min >0) scale *= (1<<_pyramid->_octave_min);
	else if(_pyramid->_octave_min < 0) scale /= (1<<(-_pyramid->_octave_min));
	glScalef(scale, scale, 1.0f);


	for(int i = 0; i < _pyramid->_octave_num; i++)
	{

		for(int j = 0; j < _dog_level_num; j++, idx++)
		{
			if(fnum[idx]>0)
			{
				if(view ==0)
				{
					glColor3f(0.2f, 1.0f, 0.2f);
					glBindBuffer(GL_ARRAY_BUFFER_ARB, vbop[idx]);
					glVertexPointer( 4, GL_FLOAT,4*sizeof(float), (char *) 0);
					glDrawArrays( GL_POINTS, 0, fnum[idx]);
					glFlush();
				}else
				{
						
					//glColor3f(1.0f, 0.0f, 0.0f);
					glColor3fv(_colors+ (idx%COLOR_NUM)*3);
					glBindBuffer(GL_ARRAY_BUFFER_ARB, vbo[idx]);
					glVertexPointer( 4, GL_FLOAT,4*sizeof(float), (char *) 0);
					glDrawArrays( GL_LINES, 0, fnum[idx]*10 );
					glFlush();
				}

			}
		
		}
		glTranslatef(-.5f, -.5f, 0.0f);
		glScalef(2.0f, 2.0f, 1.0f);

	}
	glPopMatrix();
	glDisableClientState(GL_VERTEX_ARRAY);
	glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
	glPointSize(1.0f);
							
}

void SiftGPUEX::ToggleDisplayDebug()
{
	_view_debug = !_view_debug;
}

void SiftGPUEX::DisplayDebug()
{
	glPointSize(1.0f);
	glColor3f(1.0f, 0.0f, 0.0f);
	ShaderMan::UseShaderDebug();
	glBegin(GL_POINTS);
	for(int i = 0; i < 100; i++)
	{
		glVertex2f(i*4.0f+0.5f, i*4.0f+0.5f);
	}
	glEnd();
	ShaderMan::UnloadProgram();
}

int SiftGPU::CreateContextGL()
{
	//use GLUT to create an OpenGL Context
	if(!GlobalUtil::CreateWindowGLUT()) return 0;
	return VerifyContextGL();
}

int SiftGPU::VerifyContextGL()
{
	//GlobalUtil::_GoodOpenGL = -1;  //unknown
	InitSiftGPU();
	return GlobalUtil::_GoodOpenGL + GlobalUtil::_FullSupported;
}

int SiftGPU::IsFullSupported()
{
	return GlobalUtil::_GoodOpenGL==1 &&  GlobalUtil::_FullSupported;
}

void SiftGPU::SaveSIFT(const char * szFileName)
{
	_pyramid->SaveSIFT(szFileName);
}

int SiftGPU::GetFeatureNum()
{
	return _pyramid->GetFeatureNum();
}

void SiftGPU::GetFeatureVector(SiftKeypoint * keys, float * descriptors)
{
//	keys.resize(_pyramid->GetFeatureNum());
	if(GlobalUtil::_DescriptorPPT)
	{
	//	descriptors.resize(128*_pyramid->GetFeatureNum());
		_pyramid->CopyFeatureVector((float*) (&keys[0]), &descriptors[0]);
	}else
	{
		//descriptors.resize(0);
		_pyramid->CopyFeatureVector((float*) (&keys[0]), NULL);
	}
}

void SiftGPU::SetTightPyramid(int tight)
{
	GlobalUtil::_ForceTightPyramid = tight;
}

int SiftGPU::AllocatePyramid(int width, int height)
{
	_pyramid->_down_sample_factor = 0;
	_pyramid->_octave_min = GlobalUtil::_octave_min_default;
	if(GlobalUtil::_octave_min_default>=0)
	{
		width >>= GlobalUtil::_octave_min_default;
		height >>= GlobalUtil::_octave_min_default;
	}else
	{
		width <<= (-GlobalUtil::_octave_min_default);
		height <<= (-GlobalUtil::_octave_min_default);
	}
	_pyramid->ResizePyramid(width, height);
	return _pyramid->_pyramid_height == height && width == _pyramid->_pyramid_width ;
}
void SiftGPU::SetMaxDimension(int sz)
{
	if(sz < GlobalUtil::_texMaxDimGL)
	{
		GlobalUtil::_texMaxDim = sz;
	}
}
int SiftGPU::GetImageCount()
{
	return _list->size();
}

void SiftGPUEX::HSVtoRGB(float hsv[3],float rgb[3] )
{

	int i;
	float q, t, p;
	float hh,f, v = hsv[2];
	if(hsv[1]==0.0f)
	{
		rgb[0]=rgb[1]=rgb[2]=v;
	}
	else
	{
		//////////////
		hh =hsv[0]*6.0f ;   // sector 0 to 5
		i =(int)hh ;
		f = hh- i;   // factorial part of h
		//////////
		p=  v * ( 1 - hsv[1] );
		q = v * ( 1 - hsv[1] * f );
		t = v * ( 1 - hsv[1] * ( 1 - f ) );
		switch( i ) {
			case 0:rgb[0] = v;rgb[1] = t;rgb[2] = p;break;
			case 1:rgb[0] = q;rgb[1] = v;rgb[2] = p;break;
			case 2:rgb[0] = p;rgb[1] = v;rgb[2] = t;break;
			case 3:rgb[0] = p;rgb[1] = q;rgb[2] = v;break;
			case 4:rgb[0] = t;rgb[1] = p;rgb[2] = v;break;
			case 5:rgb[0] = v;rgb[1] = p;rgb[2] = q;break;
			default:rgb[0]= 0;rgb[1] = 0;rgb[2] = 0;
		}
	}
}

SiftGPU* CreateNewSiftGPU(int np)
{
	return new SiftGPU(np);
}

⌨️ 快捷键说明

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