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

📄 algorithm.c

📁 DSP编程
💻 C
字号:
#include "algorithm.h"

int RelBmp1[] = {0,0,0,0,0,0,0,0,0,0,0,0,139,255,255,255,255,255,255,255,255,255,255,255,255,255,255,0,0,0,0,0,0,0,0,0,0,0,0,180,255,255,255,255,255,255,255,255,255,255,255,255,255,255,0,0,0,0,0,0,0,0,0,0,74,212,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,0,0,0,0,0,0,0,0,0,121,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,0,0,0,0,0,0,0,0,0,80,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,0,0,0,0,0,0,0,1,213,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,0,0,0,0,0,0,9,214,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,0,0,0,0,0,0,0,0,0,52,182,255,254,255,255,255,255,255,255,255,255,255,255,255,255,255,255,0,0,0,0,0,0,0,0,0,0,0,0,3,41,73,94,104,106,88,67,34,11,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
int startcol[19]={0,16,32,48,64,80,96,112,128,144,160,176,192,208,224,240,256,272,288};	//14*27模板
int endcol[19]={16,32,48,64,80,96,112,128,144,160,176,192,208,224,240,256,272,288,297};

/*---------------------------------*/
/* FUNCTION: Algorithm programmes  */
/*---------------------------------*/
void match1(unsigned short *pRefBmp,                   //待识别红外图像
            int nRefRow,                    //图像行
            int nRefCol,                    //图像列
            int DspNo,                      //Dsp号,从0开始编号,为0,1,2,3,4,5,6,7
            MATCHRESULT *Rdata              //返回的匹配结果
            )
{
	int REX=8754415;
	int i,j,k,p,q,l;
	int recy,xy,crcd;
	int m,n;
	int pixel;
	int grad,tmpgrad,gradmaxline;
	int srcrowst,srcrowend;

	grad = 0;
	l = startcol[DspNo];
	for (i=0;i<nRefRow-14;i++) {
		tmpgrad = 0;
		p = l + startcol[DspNo];
		for (j=startcol[DspNo];j<endcol[DspNo]+26;j++) {
			tmpgrad += pRefBmp[p] - pRefBmp[p+nRefCol];
			p++;
		}
		l += 320;
		if (tmpgrad > grad) {
			grad = tmpgrad;
			gradmaxline = i;
		}
	}
	gradmaxline -= 7;

	if (gradmaxline - SRCRANGE < 0) {
		srcrowst = 0;
		srcrowend = SRCRANGE*2;
	}
	else if (gradmaxline + SRCRANGE > nRefRow - 13) {
		srcrowend = nRefRow - 13;
		srcrowst = srcrowend - SRCRANGE*2;
	}
	else {
		srcrowst = gradmaxline - SRCRANGE;
		srcrowend = gradmaxline + SRCRANGE;
	}
	Rdata->dCoeff = -1000;
	l = srcrowst*nRefCol;
	for (i=srcrowst;i<srcrowend;i++) {
		for (j=startcol[DspNo];j<endcol[DspNo];j++) {
			recy = 0;
			xy = 0;
			k = 0;
			q = l + j;
			for (m=0;m<14;m++) {
				for (n=q;n<q+27;n++) {
					pixel = pRefBmp[n];
					recy += pixel*pixel;
					xy += pixel*RelBmp1[k++];
				}
				q += 320;
			}
			crcd = xy*200/REX*xy/recy*5;
			if (Rdata->dCoeff < crcd) {
				Rdata->dCoeff = crcd;
				Rdata->iXLeftUp = j;
				Rdata->iYLeftUp = i;
				Rdata->iXRightDown = j+27;
				Rdata->iYRightDown = i+14;
			}
		}
		l += 320;
	}
	if (Rdata->dCoeff < 676*676/1000) {
		Rdata->iXLeftUp = 0;
		Rdata->iYLeftUp = 0;
		Rdata->iXRightDown = 319;//j+13;
		Rdata->iYRightDown = 239;
	}
}

void OnSimdsp(unsigned short *imga) 
{
    long i,j;
    int cr,detx,dspno,dety;
	// TODO: Add your command handler code here
	MATCHRESULT Rdata[19];
	for (i=0;i<19;i++) {
		match1(imga,HEIGHT,WIDTH,i,&Rdata[i]);
	}
 	cr = Rdata[0].dCoeff;
	detx = Rdata[0].iXLeftUp;
	dspno = 0;
	dety = Rdata[0].iYLeftUp;
	for (i=1;i<19;i++) {
		if (Rdata[i].dCoeff>cr) {
			cr = Rdata[i].dCoeff;
			detx = Rdata[i].iXLeftUp;
			dety = Rdata[i].iYLeftUp;
			dspno = i;
		}
	}

	for(j=dety;j<=Rdata[dspno].iYRightDown;j+=(Rdata[dspno].iYRightDown-dety))
		for(i=detx;i<=Rdata[dspno].iXRightDown;i++)
		{
			imga[i+j*WIDTH]=255;
		}
		for(i=detx;i<=Rdata[dspno].iXRightDown;i+=Rdata[dspno].iXRightDown-detx)
			for(j=dety;j<=Rdata[dspno].iYRightDown;j++)
			{
				imga[i+j*WIDTH]=255;
			}
}

⌨️ 快捷键说明

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