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

📄 vgg_nearest_neighbour.cxx

📁 一个学习自然场景类别的贝叶斯模型、基于“词袋”模型的目标分类。来源于Feifei Li的论文。是近年来的目标识别模型热点之一。
💻 CXX
字号:
#include "mex.h"#include <float.h>#include <memory.h>// [ind, d2] = vgg_nearest_neighbour(X, Y)void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[]){	int				nx, ny, dim;	const double	*X, *Y, *py;	int				*ind;	double			*d2;	double			d, dmin;	int				i, j, k;	if (nrhs != 2)		mexErrMsgTxt("two input arguments expected.");	if (nlhs != 2)		mexErrMsgTxt("two output arguments expected.");	if (!mxIsDouble(prhs[0]) || mxIsComplex(prhs[0]) ||		mxGetNumberOfDimensions(prhs[0]) != 2)		mexErrMsgTxt("input 1 (X) must be a real double matrix");	dim = mxGetM(prhs[0]);	nx = mxGetN(prhs[0]);	if (!mxIsDouble(prhs[1]) || mxIsComplex(prhs[1]) ||		mxGetNumberOfDimensions(prhs[1]) != 2 ||		mxGetM(prhs[1]) != dim)		mexErrMsgTxt("input 2 (Y) must be a real double matrix compatible with input 1 (X)");	ny = mxGetN(prhs[1]);	plhs[0] = mxCreateNumericMatrix(nx, 1, mxINT32_CLASS, mxREAL);	ind = (int *) mxGetData(plhs[0]);	plhs[1] = mxCreateDoubleMatrix(nx, 1, mxREAL);	d2 = mxGetPr(plhs[1]);	X = mxGetPr(prhs[0]);	Y = mxGetPr(prhs[1]);	for (i = 1; i <= nx; i++, X += dim, ind++)	{		dmin = DBL_MAX;		*ind = 0;		for (j = 1, py = Y; j <= ny; j++, py += dim)		{			d = 0.0;			for (k = 0; k < dim; k++) {			   double diff = (X[k] - py[k]);			   d += diff*diff;			   if (d > dmin)			     break;			}			if (d < dmin)			{				dmin = d;				*ind = j;			}		}		*(d2++) = dmin;	}}

⌨️ 快捷键说明

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