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

📄 scan_bmp.cpp

📁 由visual c++编写的北航一个的指纹识别系统
💻 CPP
📖 第 1 页 / 共 2 页
字号:
			{
				(pRGB+i)->rgbBlue = 0;
				(pRGB+i)->rgbGreen = 0;
				(pRGB+i)->rgbRed = 0;
				(pRGB+i)->rgbReserved=0;
			}else
			{
				(pRGB+i)->rgbBlue = i + (light - 128);
				(pRGB+i)->rgbGreen= i + (light - 128);
				(pRGB+i)->rgbRed = i + (light - 128);
				(pRGB+i)->rgbReserved=0;
			}
		}
	}
}

/*void Scan_Bmp::ChangeContrast(short contrast)
{
	int i = 0;
	RGBQUAD* pRGB=m_Bmp_pRGB ;
	if(contrast > 0)
	{
		for(i = 0; i<256 ; i++)
		{
			if(i < contrast )
			{
				(pRGB+i)->rgbBlue = 0;
				(pRGB+i)->rgbGreen= 0;
				(pRGB+i)->rgbRed = 0;
				(pRGB+i)->rgbReserved=0;
			}else if (i > (255 -contrast))
			{
				(pRGB+i)->rgbBlue = 255;
				(pRGB+i)->rgbGreen= 255;
				(pRGB+i)->rgbRed = 255;
				(pRGB+i)->rgbReserved=0;
			}else
			{
				(pRGB+i)->rgbBlue =(unsigned char)( i * (255.0/(255.0 - 2.0*contrast)) - (255.0/(255.0 - 2.0*contrast))*contrast);
				(pRGB+i)->rgbGreen=(unsigned char)( i * (255.0/(255.0 - 2.0*contrast)) - (255.0/(255.0 - 2.0*contrast))*contrast);
				(pRGB+i)->rgbRed = (unsigned char)(i * (255.0/(255.0 - 2.0*contrast)) - (255.0/(255.0 - 2.0*contrast))*contrast);
				(pRGB+i)->rgbReserved=0;
			}
		}
	}else
	{
		for(i = 0 ;i<256; i++)
		{
			(pRGB+i)->rgbBlue = (unsigned char)(i*(1+contrast/128.0) - contrast);
			(pRGB+i)->rgbGreen= (unsigned char)(i*(1+contrast/128.0) - contrast);
			(pRGB+i)->rgbRed = (unsigned char)(i*(1+contrast/128.0) - contrast);
			(pRGB+i)->rgbReserved=0;
		}
	}
}
*/
void Scan_Bmp::InitRGB()
{
	for(int i = 0 ; i < 256 ; i++)
	{
		(m_Bmp_pRGB + i)->rgbBlue		= i;
		(m_Bmp_pRGB + i)->rgbGreen		= i;
		(m_Bmp_pRGB + i)->rgbRed		= i;
		(m_Bmp_pRGB + i)->rgbReserved	= 0;
	}
}

void Scan_Bmp::Reverse()
{
	long i;
	int m_Width = ((BITMAPINFOHEADER *)m_Bmp_pHuge)->biWidth;
	int m_Height = ((BITMAPINFOHEADER *)m_Bmp_pHuge)->biHeight;

	for(i=0;i<m_Width*m_Height;i++)
		*(BYTE*)(m_Bmp_pBmpValue+i)=256-*(BYTE*)(m_Bmp_pBmpValue+i);
}


void Scan_Bmp::ChangeContrast(short contrast)
{
	int i = 0;
	RGBQUAD* pRGB=m_Bmp_pRGB ;
	if(contrast > 0)
	{
		for(i = 0; i<256 ; i++)
		{
			if((pRGB+i)->rgbBlue < contrast )
			{
				(pRGB+i)->rgbBlue = 0;
				(pRGB+i)->rgbGreen= 0;
				(pRGB+i)->rgbRed = 0;
				(pRGB+i)->rgbReserved=0;
			}else if ((pRGB+i)->rgbBlue > (255 -contrast))
			{
				(pRGB+i)->rgbBlue = 255;
				(pRGB+i)->rgbGreen= 255;
				(pRGB+i)->rgbRed = 255;
				(pRGB+i)->rgbReserved=0;
			}else
			{
				(pRGB+i)->rgbBlue =(unsigned char)( ((float)(pRGB+i)->rgbBlue) * (255.0/(255.0 - 2.0*contrast)) - (255.0/(255.0 - 2.0*contrast))*contrast);
				(pRGB+i)->rgbGreen=(unsigned char)( ((float)(pRGB+i)->rgbGreen) * (255.0/(255.0 - 2.0*contrast)) - (255.0/(255.0 - 2.0*contrast))*contrast);
				(pRGB+i)->rgbRed = (unsigned char)(((float)(pRGB+i)->rgbRed) * (255.0/(255.0 - 2.0*contrast)) - (255.0/(255.0 - 2.0*contrast))*contrast);
				(pRGB+i)->rgbReserved=0;
			}
		}
	}else
	{
		for(i = 0 ;i<256; i++)
		{
			(pRGB+i)->rgbBlue = (unsigned char)(((pRGB+i)->rgbBlue)*(1+contrast/128.0) - contrast);
			(pRGB+i)->rgbGreen= (unsigned char)(((pRGB+i)->rgbGreen)*(1+contrast/128.0) - contrast);
			(pRGB+i)->rgbRed = (unsigned char)(((pRGB+i)->rgbRed)*(1+contrast/128.0) - contrast);
			(pRGB+i)->rgbReserved=0;
		}
	}
}
/*
void Scan_Bmp::ChangeLight(unsigned short light)
{
	RGBQUAD* pRGB=m_Bmp_pRGB ;
	for(int i=0;i<256;i++)
	{
		if(light > 128)
		{
			if(i + (light - 128) >= 255)
			{
				(pRGB+i)->rgbBlue = 255;
				(pRGB+i)->rgbGreen=255;
				(pRGB+i)->rgbRed=255;
				(pRGB+i)->rgbReserved=0;
			}else
			{
				(pRGB+i)->rgbBlue = i + (light - 128);
				(pRGB+i)->rgbGreen=i + (light - 128);
				(pRGB+i)->rgbRed=i + (light - 128);
				(pRGB+i)->rgbReserved=0;
			}
		}else
		{
			if(i + (light - 128) < 0)
			{
				(pRGB+i)->rgbBlue = 0;
				(pRGB+i)->rgbGreen = 0;
				(pRGB+i)->rgbRed = 0;
				(pRGB+i)->rgbReserved=0;
			}else
			{
				(pRGB+i)->rgbBlue = i + (light - 128);
				(pRGB+i)->rgbGreen= i + (light - 128);
				(pRGB+i)->rgbRed = i + (light - 128);
				(pRGB+i)->rgbReserved=0;
			}
		}
	}
}

*/

void Scan_Bmp::Copy(Scan_Bmp & bmp)
{
	if( bmp.m_Bmp_pBmpValue != NULL)
	{
		GlobalFree( bmp.m_Bmp_pBmpValue );
	}
	m_Width = ((BITMAPINFOHEADER *)m_Bmp_pHuge)->biWidth;
	m_Height = ((BITMAPINFOHEADER *)m_Bmp_pHuge)->biHeight;
	bmp.m_Bmp_pBmpValue=(BYTE *)GlobalAlloc(GPTR, m_Width*m_Height);
	bmp.m_Bmp_pBmpInfo->biWidth=m_Width;
	bmp.m_Bmp_pBmpInfo->biHeight=m_Height;
	memcpy(bmp.m_Bmp_pBmpValue,m_Bmp_pBmpValue,m_Width*m_Height);
}

void Scan_Bmp::ChangeLightAndContrast(short light, short contrast)
{
	ChangeLight(light);
	ChangeContrast(contrast);
}

void Scan_Bmp::CopyPart(Scan_Bmp &bmp, POINT from, short width, short height)
{
	POINT position;
	int i;
	position.x=from.x-width/2;
	position.y=from.y-height/2;
	Scan_Bmp tempbmp;
	tempbmp.m_Bmp_pBmpInfo->biWidth=width;
	tempbmp.m_Bmp_pBmpInfo->biHeight=height;
	tempbmp.m_Bmp_pBmpValue=(BYTE *)GlobalAlloc(GPTR, width*height);
	if(position.x<0)
		position.x=0;
	else
		if(position.x+width>m_Bmp_pBmpInfo->biWidth) 
			position.x=m_Bmp_pBmpInfo->biWidth-width;
	if(position.y<0)
		position.y=0;
	else
		if(position.y+height>m_Bmp_pBmpInfo->biHeight)
			position.y=m_Bmp_pBmpInfo->biHeight-height;
	for(i=0;i<height;i++)
		memcpy(tempbmp.m_Bmp_pBmpValue+i*width,m_Bmp_pBmpValue+
		(m_Bmp_pBmpInfo->biHeight-(position.y+height-i))*m_Bmp_pBmpInfo->biWidth+
		position.x,width);

	tempbmp.ScaleImage(bmp, width*2, height*2);

	//	tempbmp.Copy(bmp);
}

void Scan_Bmp::EnHance(short gray)
{
	short i,j,m;
	double a,b;
	short i1,j1;
    short tmp;
	short d[256];
	BYTE *fp = NULL;
	FILE *file;
	short a1,b1;
	short th;
	short ran;
	short th1,scale;

	BYTE *wimage=m_Bmp_pBmpValue;
	short width = (short)((BITMAPINFOHEADER *)m_Bmp_pHuge)->biWidth;
	short height = (short)((BITMAPINFOHEADER *)m_Bmp_pHuge)->biHeight;
	fp = (BYTE *)GlobalAlloc(GPTR, width * height);
	if(fp == NULL)
	{
		AfxMessageBox("Memory No Enough!");
		return;
	}


	if(gray==1)
	{

	for(i=0;i<256;i++)
		d[i]=0;
	for (i=3;i<height-3;i++)
    for (j=3;j<width-3;j++)
     {
    	   tmp=wimage[i*width+j];
		   d[tmp]++;
	
	 };


	//file=fopen("c:\\gray.txt","w");

    a1=0;
	b1=255; 
	th=20;
	
	for(i=0;i<256;i++)
	{
	  if(d[i]>th) b1=i;
	  if(d[255-i]>th) a1=255-i;
	}
	//fclose(file);

	if(a1==b1)
	{
	  a1=0;
	  b1=255;
	}
	for (i=0;i<height;i++)
    for (j=0;j<width;j++)
    {
       tmp=wimage[i*width+j];
	   if(tmp<a1) tmp=a1;
       if(tmp>b1) tmp=b1;
       wimage[i*width+j]=(tmp-a1)*255/(b1-a1);
	};
	
	}

	ran=5;
     for (i=ran;i<height-ran;i++)
     for (j=ran;j<width-ran;j++)
     {
    
		 for(i1=-ran;i1<=ran;i1=i1+2)
		 for(j1=-ran;j1<=ran;j1=j1+2)
		 {
		   tmp+=wimage[(i+i1)*width+j+j1];
		 };
		 tmp=tmp/36;//((2*ran+1)*(2*ran+1));

		 fp[i*width+j]=tmp;
	 };

	 th1=8;
	 scale=128/th1;

	 for (i=0;i<height;i++)
     for (j=0;j<width;j++)
     {
    	 m= wimage[i*width+j]-fp[i*width+j];

		 if (m>=th1)
			 wimage[i*width+j]=255;
		 else if (m<=-th1)
			 wimage[i*width+j]=0;
		 else
			 wimage[i*width+j]=127+m*scale;
	 };
	 if(fp != NULL)
		GlobalFree(fp);
}

void Scan_Bmp::ExtendSmallBmp(Scan_Bmp *bmp)
{
	int dx=0,dy=0;
	dx=m_Width-bmp->m_Width;
	dy=m_Height-bmp->m_Height;
	BYTE *p,*q;
	p=m_Bmp_pBmpValue;
	q=bmp->m_Bmp_pBmpValue ;
	memset(p,255,m_Width*(dy/2));
	p+=m_Width*(dy/2);
	for(int i=0;i<bmp->m_Height;i++)
	{
		memset(p,255,dx/2);
		p+=dx/2;
		memcpy(p,q,bmp->m_Width);
		q+=bmp->m_Width;
		p+=bmp->m_Width;
		memset(p,255,dx/2);
		p+=dx/2;
	}
	memset(p,255,m_Width*(dy/2));
}

⌨️ 快捷键说明

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