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

📄 imageprocessview.cpp

📁 一个基于知识的人脸检测系统
💻 CPP
📖 第 1 页 / 共 2 页
字号:
	//get the excuation time.
	CClientDC dc1(this);
	char strtime[20];
	_itoa(int(finish-start)*1000/CLOCKS_PER_SEC,strtime,10 ); 
	dc1.TextOut(30,20,"excuation time in milliseconds:");
	dc1.TextOut(300,20,strtime);

	ReleaseDC(&dc1);

	//end the whole program. 
	//during the  testing time,below sentences is needed.
	/*delete []myP->myPArray;
	delete []myP->myHSIArray;
	delete []myP->RGBImage;*/

}

void CImageProcessView::OnFileSave() 
{
/*purpose: after modifying the image,the results can be restored.
**global array: myPArray, it stored the image's RGB value.
**founder: Li Xuewei
**date: 2003.8.10
**mender:Li Xuewei
**date: 2004.1.14
*/
	if(!IsOpen)
	{
		AfxMessageBox("you must open a file first!");
		return;
	}

	if(!myP->myPArray)
	{
		AfxMessageBox("the image have been damaged!");
		return;
	}

	CFile destFile; //save file

	CFileDialog dlg( FALSE,_T("bmp"),_T(""),OFN_OVERWRITEPROMPT,
	                 _T("24bit(*.bmp)|*.bmp|"));	

	if(dlg.DoModal()==IDOK)
	{
		destFile.Open(dlg.GetFileName(),CFile::modeCreate|CFile::modeReadWrite);

		BITMAPFILEHEADER *dfh=&(myP->tFileHead);
		BITMAPINFOHEADER *dfi=&(myP->tFileInfo);
		destFile.Write(dfh,myP->nHeadRead1);//or directly to write.
		destFile.Write(dfi,myP->nInfoRead2);	
		
		int height,width; //the image matrix's height and width of stored format
		height=myP->myPHeight;


		if(myP->myPWidth*3 % 4 != 0)
			width=((myP->myPWidth*3)/4+1)*4;
		else
			width=myP->myPWidth*3;

		BYTE *Image;
		Image=new BYTE[height*width];
		//stored in image matrix
		int i,j;
		BYTE R,B,G;
		int tp=0; 
		for(i=height-1;i>=0;i--)
		{
			for(j=0;j<myP->myPWidth;j++)
			{
				R=GetRValue(myP->myPArray[i*myP->myPWidth+j]);
				G=GetGValue(myP->myPArray[i*myP->myPWidth+j]);
				B=GetBValue(myP->myPArray[i*myP->myPWidth+j]);

				*(Image+tp)=B;//*(Image + tp++)
				tp++;
				*(Image+tp)=G;
				tp++;
				*(Image+tp)=R;
				tp++;
			}
			for(j=myP->myPWidth*3;j<width;j++) //fill with 0
			{
				*(Image+tp)=0;
				tp++;
			}
		}

		BYTE *Offset;//
		Offset=new BYTE[myP->gOffset];
		for(i=0;i<myP->gOffset;i++)
			Offset[i]=0;

		destFile.Write(Offset,myP->gOffset);
		////destFile.SeekToEnd();
		destFile.Write(Image,height*width);  //tp    sizeof(Image)=4

		destFile.Close();

		delete []Image;
		delete []Offset;
	}
	else // null file name
		return;
}

void CImageProcessView::OnProjectiontest() 
{
	myP->TestProjection();

	CClientDC dc(this);
	DrawCenterDC(&dc);
	ReleaseDC(&dc);	

	CClientDC dc1(this);
	char str1[20],str2[20];

	_itoa(int(myP->sSum),str1,10 ); 
	dc1.TextOut(30,20,"the symmetry in intensity difference is:");
	dc1.TextOut(300,20,str1);

	_itoa(int(myP->minangle),str2,10 ); 
	dc1.TextOut(30,50,"the maximum gradient angle is:");
	dc1.TextOut(300,50,str2);/**/

	ReleaseDC(&dc1);	
}

void CImageProcessView::OnYcbcr() 
{
	myP->YCbCr();

	CClientDC dc(this);
	DrawCenterDC(&dc);
	ReleaseDC(&dc);	
}

void CImageProcessView::OnHighboost() 
{
	myP->High_Boost();

	CClientDC dc(this);
	DrawCenterDC(&dc);
	ReleaseDC(&dc);		
}

void CImageProcessView::OnGrayscaledilate() 
{
	//cout<<"this is in gray scale dilate"<<endl;
	//printf("this is in gray scale dilate");
	//myP->GrayScaleDilation();

	/*
	CClientDC dc(this);
	DrawCenterDC(&dc);
	ReleaseDC(&dc);	*/		
}

void CImageProcessView::OnGrayscaleerosion() 
{

/*	myP->Projection();

	CClientDC dc(this);
	DrawCenterDC(&dc);
	ReleaseDC(&dc);	*/
}

void CImageProcessView::OnFilterOpen() 
{
//	myP->postprocess();
	myP->SecEyeExtract();

	CClientDC dc(this);
	DrawCenterDC(&dc);
	ReleaseDC(&dc);	
}

void CImageProcessView::OnRegionfilter() 
{
	myP->MouthRegionProcess();

	CClientDC dc(this);
	DrawCenterDC(&dc);
	ReleaseDC(&dc);	

	/*myP->fileWrite();*/
}

void CImageProcessView::OnEditCopy() 
{
	
}

void CImageProcessView::OnFilterfeature() 
{
	clock_t start,finish;
	start=clock();

	myP->FilterFeature();

	CClientDC dc(this);
	DrawCenterDC(&dc);
	ReleaseDC(&dc);		

	finish=clock();

	//get the excuation time.
	CClientDC dc1(this);
	char strtime[20];
	_itoa(int(finish-start)*1000/CLOCKS_PER_SEC,strtime,10 ); 
	dc1.TextOut(30,20,"excuation time in milliseconds:");
	dc1.TextOut(300,20,strtime);

	ReleaseDC(&dc1);
}

void CImageProcessView::OnHueseg() 
{
	myP->TestHueSeg();
	
	CClientDC dc(this);
	DrawCenterDC(&dc);
	ReleaseDC(&dc);		
}

void CImageProcessView::OnLocseg() 
{
/*
** purpose: show the image of local segment
** founder: Li Xuewei
** date:  2003.8.25
*/
	int ini_size=5;
	LocSegDlg *MyDlg;
	MyDlg=new LocSegDlg;

	MyDlg->m_blocksize=ini_size;
	if(MyDlg->DoModal()==IDCANCEL) return;
	ini_size=MyDlg->m_blocksize;

	myP->TestSeg(ini_size);
	
	CClientDC dc(this);
	DrawCenterDC(&dc);
	ReleaseDC(&dc);	
}

void CImageProcessView::OnHistogram() 
{	
	// define another class "Histogram" to include all the operation about histogram.
	Histogram *hDlg;
	hDlg=new Histogram;

	int ini_label=1;
	hDlg->m_label=ini_label;
	if(hDlg->DoModal()==IDCANCEL) return;
	ini_label=hDlg->m_label;

	ComputeHistogram(ini_label);

	char ini_c='h';
	//strcpy(hDlg->m_combhsi,ini_c);

	CDC * pDC=GetDC();

	CRect rect;
	GetClientRect(rect);	//get the window's size
	pDC->FillSolidRect(rect,RGB(255,255,255));   //use black as the background color

    CString str="Intensity histogram";//+c
	pDC->TextOut(16,16,str); //rect.right-50
	str="Hue histogram";
	pDC->TextOut(280,16,str); //rect.right-50
	str="Saturation histogram";
	pDC->TextOut(650,16,str); //rect.right-50

	CPen pen;
	pen.CreatePen(PS_SOLID,1,RGB(0,0,255));   //select blue color

	CPen *pOldpen=pDC->SelectObject(&pen);	//select the pen,and save the previous

	int ic;
	for(ic=0;ic<256;ic++)
	{ 
		pDC->MoveTo(ic,rect.bottom);	//head-on fig.
		pDC->LineTo(ic,rect.bottom-*(ihisto+ic));  //his[ic]area
	}

	pDC->MoveTo(270,rect.bottom);
	pDC->LineTo(270,rect.top);

	for(ic=280; ic<360+280; ic++)
	{ 
		pDC->MoveTo(ic,rect.bottom);	//head-on fig.
		pDC->LineTo(ic,rect.bottom-*(hhisto+ic-280)/5);	//his[ic]area
	}	

	pDC->MoveTo(650,rect.bottom);
	pDC->LineTo(650,rect.top);

	for(ic=0;ic<100;ic++)
	{ 
		pDC->MoveTo(ic+660,rect.bottom);	//head-on fig.
		pDC->LineTo(ic+660,rect.bottom-*(shisto+ic)/5);//his[ic]area
	}


	pDC->SelectObject(pOldpen);	//resume the original pen */
	
	//Invalidate();
}

void CImageProcessView::ComputeHistogram(int label)
{
	myP->MomentDescription();	

	if(!(myP->IntCentdx[label-1]>0 && myP->IntCentdy[label-1]>0 ))
	{
		AfxMessageBox("this region is not exist!");
		return;
	}
	
	int i,j;

	for(i=0;i<=255;i++)
		ihisto[i]=0;
	for(i=0;i<360;i++)
		hhisto[i]=0;
	for(i=0;i<100;i++)
		shisto[i]=0;
	
	int h;
	short ii;
	double s;

	for(i=0;i<myP->myPHeight;i++)
	{
		for(j=0;j<myP->myPWidth;j++)
		{
			if(*(myP->RegionLabel+i*myP->myPWidth+j)==label)
			{
				ii=myP->myHSIArray[i*myP->myPWidth+j].I;
				h=myP->myHSIArray[i*myP->myPWidth+j].H;
				s=myP->myHSIArray[i*myP->myPWidth+j].S;

				ihisto[ii]++;
				hhisto[h]++;
				shisto[int(s*100)]++;
			}
		}
	}
}

void CImageProcessView::OnStatistical() 
{
/*
**purpose: 计算整幅图像的灰度,色调,饱和度的方差和平均值等。
**founder: lixuewei
**date: 2003.11.6
*/
	int AvgR,AvgG,AvgB;
	BYTE Avgi;
	short Avgh;
	double Avgs;

	myP->StaticForImage(AvgR,AvgG,AvgB,Avgi,Avgh,Avgs);

	long sumStdR=0,sumStdG=0,sumStdB=0;
	int i,j;
	for(i=0;i<myP->myPHeight;i++)
		for(j=0;j<myP->myPWidth;j++)
		{
			sumStdR+=(AvgR-GetRValue(myP->myPArray[i*myP->myPWidth+j]))
					*(AvgR-GetRValue(myP->myPArray[i*myP->myPWidth+j]));
			sumStdG+=(AvgG-GetGValue(myP->myPArray[i*myP->myPWidth+j]))
					*(AvgG-GetGValue(myP->myPArray[i*myP->myPWidth+j]));
			sumStdB+=(AvgB-GetBValue(myP->myPArray[i*myP->myPWidth+j]))
					*(AvgB-GetBValue(myP->myPArray[i*myP->myPWidth+j]));
		}

	short stdR,stdG,stdB;
	stdR=sumStdR/(myP->myPHeight*myP->myPWidth);
	stdG=sumStdG/(myP->myPHeight*myP->myPWidth);
	stdB=sumStdB/(myP->myPHeight*myP->myPWidth);

	CClientDC dc1(this);
	char str1[20],str2[20],str3[20];
	_itoa(AvgR,str1,10 ); 
	dc1.TextOut(10,20,"Average R:");
	dc1.TextOut(110,20,str1);

	_itoa(AvgG,str2,10 ); 
	dc1.TextOut(10,40,"Average G:");
	dc1.TextOut(110,40,str2);

	_itoa(AvgB,str3,10 ); 
	dc1.TextOut(10,60,"Average B:");
	dc1.TextOut(110,60,str3);

	char str4[20],str5[20],str6[20];
	_itoa(stdR,str4,10 ); 
	dc1.TextOut(10,80,"standard deviation of R:");
	dc1.TextOut(210,80,str4);

	_itoa(stdG,str5,10 ); 
	dc1.TextOut(10,100,"standard deviation of G:");
	dc1.TextOut(210,100,str5);

	_itoa(stdB,str6,10 ); 
	dc1.TextOut(10,120,"standard deviation of B:");
	dc1.TextOut(210,120,str6);

	ReleaseDC(&dc1);
}

void CImageProcessView::OnTestclassify() 
{
	myP->TestClassify();

	CClientDC dc(this);
	DrawCenterDC(&dc);
	ReleaseDC(&dc);	

	//display the ratio
	CClientDC dc1(this);
	char strnr[20],strhr[20],strsr[20];
	_itoa(int(myP->hr*100),strhr,10 ); 
	_itoa(int(myP->nr*100),strnr,10 ); 
	_itoa(int(myP->sr*100),strsr,10 ); 

	dc1.TextOut(30,20,"the highlight ratio:");
	dc1.TextOut(200,20,strhr);
	dc1.TextOut(30,40,"the normal light ratio:");
	dc1.TextOut(200,40,strnr);
	dc1.TextOut(30,60,"the shadow light ratio:");
	dc1.TextOut(200,60,strsr);

	ReleaseDC(&dc1);
}

void CImageProcessView::OnVisionimage() 
{
	myP->visionImage();

	CClientDC dc(this);
	DrawCenterDC(&dc);
	ReleaseDC(&dc);		
}

void CImageProcessView::OnHistequliz() 
{
	myP->HistEqulization();

	CClientDC dc(this);
	DrawCenterDC(&dc);
	ReleaseDC(&dc);	
}

void CImageProcessView::OnMomentseg() 
{
	myP->MomentSeg();

	CClientDC dc(this);
	DrawCenterDC(&dc);
	ReleaseDC(&dc);	
}

void CImageProcessView::OnImageenhance() 
{
	myP->ImageEnhance();

	CClientDC dc(this);
	DrawCenterDC(&dc);
	ReleaseDC(&dc);		
}

void CImageProcessView::OnItertive() 
{
	int t=myP->AvgThreshold();

	int i,j;
	for(i=0;i<myP->myPHeight;i++)
		for(j=0;j<myP->myPWidth;j++)
		{
			if(myP->myHSIArray[i*myP->myPWidth+j].I<t)
				*(myP->myPArray+i*myP->myPWidth+j)=RGB(0,0,0);
			else
				*(myP->myPArray+i*myP->myPWidth+j)=RGB(255,255,255);
		}


	CClientDC dc(this);
	DrawCenterDC(&dc);
	ReleaseDC(&dc);		
}

void CImageProcessView::OnMouthdef() 
{
	myP->MouthRegionProcess();

	CClientDC dc(this);
	DrawCenterDC(&dc);
	ReleaseDC(&dc);	
}

void CImageProcessView::OnMeanfiltering() 
{
	myP->MeanFilter();

	CClientDC dc(this);
	DrawCenterDC(&dc);
	ReleaseDC(&dc);		
}

void CImageProcessView::OnImgadjust() 
{
	myP->IntAdjust();

	CClientDC dc(this);
	DrawCenterDC(&dc);
	ReleaseDC(&dc);	
}

void CImageProcessView::OnGauss() 
{
	myP->Gauss();

	CClientDC dc(this);
	DrawCenterDC(&dc);
	ReleaseDC(&dc);	

	//try to redraw the defined window, but can not maintain the effect!
	/*CWnd* frame = (CWnd*)AfxGetMainWnd();//
	CRect r(200,100,50,50);
	LPRECT rect=&r;//
   if( frame->RedrawWindow(r))
	   AfxMessageBox("Success!");//RDW_ERASE
   else
	   AfxMessageBox("Failed!");*/

}

⌨️ 快捷键说明

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