📄 imageprocessview.cpp
字号:
// ImageProcessView.cpp : implementation of the CImageProcessView class
//
#include <iostream.h>
#include <stdio.h>
#include "stdafx.h"
#include "ImageProcess.h"
#include "ImageProcessDoc.h"
#include "ImageProcessView.h"
#include "LocSegDlg.h"
#include "Histogram.h"
#include <sys/timeb.h>
#include <time.h>
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CImageProcessView
IMPLEMENT_DYNCREATE(CImageProcessView, CView)
BEGIN_MESSAGE_MAP(CImageProcessView, CView)
//{{AFX_MSG_MAP(CImageProcessView)
ON_COMMAND(ID_BUTTONGRAY, OnButtongray)
ON_COMMAND(ID_FILE_OPEN, OnFileOpen)
ON_COMMAND(ID_BUTTONTEST, OnButtontest)
ON_COMMAND(ID_MENUITEMSOBEL, OnMenuitemsobel)
ON_COMMAND(ID_MENUITEMVISIONSOBEL, OnMenuitemvisionsobel)
ON_COMMAND(ID_SKINCLASSIFY, OnSkinclassify)
ON_COMMAND(ID_BUTTONIngSheen, OnBUTTONIngSheen)
ON_COMMAND(ID_FIRSTCLASSIFY, OnFirstclassify)
ON_COMMAND(ID_SMALLDEL, OnSmalldel)
ON_COMMAND(ID_MOMENT, OnMoment)
ON_COMMAND(ID_FILLHOLES, OnFillholes)
ON_COMMAND(ID_REGDESCR, OnRegdescr)
ON_COMMAND(ID_EYEEXTRACT, OnEyeextract)
ON_COMMAND(ID_MENUITEMINTANDSD, OnMenuitemintandsd)
ON_COMMAND(ID_TEMPTEST, OnTemptest)
ON_COMMAND(ID_BWDISPLAY, OnBwdisplay)
ON_COMMAND(ID_REGBWDISPLAY, OnRegbwdisplay)
ON_COMMAND(ID_EYEPAIRS, OnEyepairs)
ON_COMMAND(ID_FILE_SAVE, OnFileSave)
ON_COMMAND(ID_PROJECTIONTEST, OnProjectiontest)
ON_COMMAND(ID_YCBCR, OnYcbcr)
ON_COMMAND(ID_HIGHBOOST, OnHighboost)
ON_COMMAND(ID_GRAYSCALEDILATE, OnGrayscaledilate)
ON_COMMAND(ID_GRAYSCALEEROSION, OnGrayscaleerosion)
ON_COMMAND(ID_FilterOpen, OnFilterOpen)
ON_COMMAND(ID_REGIONFILTER, OnRegionfilter)
ON_COMMAND(ID_EDIT_COPY, OnEditCopy)
ON_COMMAND(ID_FILTERFEATURE, OnFilterfeature)
ON_COMMAND(ID_HUESEG, OnHueseg)
ON_COMMAND(ID_LOCSEG, OnLocseg)
ON_COMMAND(ID_HISTOGRAM, OnHistogram)
ON_COMMAND(ID_STATISTICAL, OnStatistical)
ON_COMMAND(ID_TESTCLASSIFY, OnTestclassify)
ON_COMMAND(ID_VISIONIMAGE, OnVisionimage)
ON_COMMAND(ID_HISTEQULIZ, OnHistequliz)
ON_COMMAND(ID_MOMENTSEG, OnMomentseg)
ON_COMMAND(ID_IMAGEENHANCE, OnImageenhance)
ON_COMMAND(ID_ITERTIVE, OnItertive)
ON_COMMAND(ID_MOUTHDEF, OnMouthdef)
ON_COMMAND(ID_MEANFILTERING, OnMeanfiltering)
ON_COMMAND(ID_IMGADJUST, OnImgadjust)
ON_WM_PAINT()
ON_COMMAND(ID_GAUSS, OnGauss)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CImageProcessView construction/destruction
CImageProcessView::CImageProcessView()
{
// TODO: add construction code here
myP=NULL;
}
CImageProcessView::~CImageProcessView()
{
if(myP!=NULL) delete myP;
}
BOOL CImageProcessView::PreCreateWindow(CREATESTRUCT& cs)
{
// TODO: Modify the Window class or styles here by modifying
// the CREATESTRUCT cs
return CView::PreCreateWindow(cs);
}
/////////////////////////////////////////////////////////////////////////////
// CImageProcessView drawing
void CImageProcessView::OnDraw(CDC* pDC)
{
CImageProcessDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
// TODO: add draw code for native data here
}
/////////////////////////////////////////////////////////////////////////////
// CImageProcessView diagnostics
#ifdef _DEBUG
void CImageProcessView::AssertValid() const
{
CView::AssertValid();
}
void CImageProcessView::Dump(CDumpContext& dc) const
{
CView::Dump(dc);
}
CImageProcessDoc* CImageProcessView::GetDocument() // non-debug version is inline
{
ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CImageProcessDoc)));
return (CImageProcessDoc*)m_pDocument;
}
#endif //_DEBUG
/////////////////////////////////////////////////////////////////////////////
// CImageProcessView message handlers
void CImageProcessView::OnButtongray()
{
BYTE R,G,B;
for(int i=0; i<myP->myPHeight; i++)
{
for(int j=0; j<myP->myPWidth; j++)
{
R=(BYTE)myP->myHSIArray[i*(myP->myPWidth)+j].I;
G=R;
B=R;
// G=0.299*R+0.587*G+0.114*B;
myP->myPArray[i*(myP->myPWidth)+j]=RGB(R,G,B);
}
}
CClientDC dc(this);
DrawCenterDC(&dc);
ReleaseDC(&dc);
}
bool CImageProcessView::IsOpen=false;
void CImageProcessView::OnFileOpen()
{
//founder: Jungle
//** date: 2001
CString fName;
CFileDialog fDlg(true,_T(""),_T("*.bmp"),OFN_HIDEREADONLY,_T("24bit(*.bmp)|*.bmp|"));
//CFileDialog fDlg(true);
fDlg.DoModal();
fName=fDlg.GetFileName();
if(fName==CString("")) return;
myP=new ImagePr;
myP->ReadDIB(fName);
myP->HSItrans('t');
//draw it
CClientDC dc(this);
DrawCenterDC(&dc);
ReleaseDC(&dc);
IsOpen=1;
}
void CImageProcessView::DrawCenterDC(CDC *pDC)
{
//founder: Jungle
//** date: 2001
int i,j;
CRect tRect;
CPoint tCPoint;
GetClientRect(&tRect);
//SendMessage(WM_PAINT);---- Cannot refresh!255,255,255
pDC->FillSolidRect(tRect,RGB(0,0,0));//Set background and refresh
tCPoint=tRect.CenterPoint();
tCPoint-=CSize(myP->myPWidth/2,myP->myPHeight/2);
for(i=0; i<(int)myP->myPHeight; i++)
for(j=0; j<(int)myP->myPWidth; j++)
pDC->SetPixel(j+tCPoint.x , i+tCPoint.y , myP->myPArray[i*(myP->myPWidth)+j]);
}
void CImageProcessView::OnButtontest()
{
CDC * pDC=GetDC();
int i,j;
CRect tRect;
CPoint tCPoint;
GetClientRect(&tRect);
//SendMessage(WM_PAINT);---- Cannot refresh!
pDC->FillSolidRect(tRect,RGB(255,255,255));//Set background and refresh
tCPoint=tRect.CenterPoint();
tCPoint-=CSize(myP->myPWidth/2,myP->myPHeight/2);
//always display the matrix "myPArray"
for(i=0; i<(int)myP->myPHeight; i++) //占据屏幕的中心位置显示。
for(j=0; j<(int)myP->myPWidth; j++)
pDC->SetPixel(j+tCPoint.x , i+tCPoint.y , myP->RGBImage[i*(myP->myPWidth)+j]);
//delete []myP->RGBImage;
}
void CImageProcessView::OnPaint()
{
CPaintDC dc(this); // device context for painting
if(myP!=NULL)
{
DrawCenterDC(&dc);
ReleaseDC(&dc);
}
// Do not call CView::OnPaint() for painting messages
}
void CImageProcessView::OnMenuitemsobel()
{
myP->sobel();
CClientDC dc(this);
DrawCenterDC(&dc);
ReleaseDC(&dc);
}
void CImageProcessView::OnMenuitemvisionsobel()
{
myP->visionSobel();
CClientDC dc(this);
DrawCenterDC(&dc);
ReleaseDC(&dc);
}
void CImageProcessView::OnSkinclassify()
{
myP->skinclassify();
CClientDC dc(this);
DrawCenterDC(&dc);
ReleaseDC(&dc);
}
void CImageProcessView::OnBUTTONIngSheen()
{
myP->IngSheen();
CClientDC dc(this);
DrawCenterDC(&dc);
ReleaseDC(&dc);
}
void CImageProcessView::OnFirstclassify()
{
if(!IsOpen)
{
AfxMessageBox("you must open a file first!");
return;
}
myP->FirstClassify();
CClientDC dc(this);
DrawCenterDC(&dc);
ReleaseDC(&dc);
}
void CImageProcessView::OnSmalldel()
{
myP->SmallRegionDel();
CClientDC dc(this);
DrawCenterDC(&dc);
ReleaseDC(&dc);
//get the excuation time.
CClientDC dc1(this);
char strtime[20];
_itoa(int(myP->finish-myP->start)*1000/CLOCKS_PER_SEC,strtime,10 );
dc1.TextOut(30,20,"excuation time in milliseconds:");
dc1.TextOut(300,20,strtime);
ReleaseDC(&dc1);
}
void CImageProcessView::OnMoment()
{
if(!IsOpen)
{
AfxMessageBox("you must open a file first!");
return;
}
clock_t start,finish;
start=clock();
myP->MomentDescription();
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::OnFillholes()
{
myP->FillHole();
CClientDC dc(this);
DrawCenterDC(&dc);
ReleaseDC(&dc);
}
void CImageProcessView::OnRegdescr()
{
if(!IsOpen)
{
AfxMessageBox("you must open a file first!");
return;
}
clock_t start,finish;
start=clock();
myP->EyeLabeling();
//myP->segmentByHSI();
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::OnEyeextract()
{
if(!IsOpen)
{
AfxMessageBox("you must open a file first!");
return;
}
myP->EyeExtraction();
CClientDC dc(this);
DrawCenterDC(&dc);
ReleaseDC(&dc);
}
void CImageProcessView::OnMenuitemintandsd()
{
myP->stdOfReg();
myP->binarize('n');
CClientDC dc(this);
CRect tRect;
CPoint tCPoint;
GetClientRect(&tRect);
tCPoint=tRect.CenterPoint();
tCPoint-=CSize(myP->myPWidth/2,myP->myPHeight/2);
dc.TextOut(0,0,"order:std of int,sat * 100, hue, ratio * 100");
//dc.TextOut(0,20,"std of sat * 100");
int i;
char str[20],strInt[20],strThresh[20];
char strsat[20],strHue[20];
char strnum[20];
for(i=1;i<=myP->NumOfLabel;i++)
{
_itoa(int((myP->sdOfFaceReg[i-1])),str,10 );
_itoa(int(myP->meanInt[i-1]),strInt,10 );
_itoa(int(myP->Thresh[i-1]),strThresh,10);
_itoa(int((myP->SatSdOfFaceReg[i-1])*100),strsat,10);
_itoa(int((myP->HueSdOfFaceReg[i-1])),strHue,10);
_itoa(int((myP->num_lowthresh[i-1])*100),strnum,10);
dc.TextOut(myP->IntCentdx[i-1]+tCPoint.x,myP->IntCentdy[i-1]+tCPoint.y,str);
//dc.TextOut(myP->IntCentdx[i-1]+tCPoint.x,myP->IntCentdy[i-1]+20+tCPoint.y,strInt);
//dc.TextOut(myP->IntCentdx[i-1]+tCPoint.x,myP->IntCentdy[i-1]+40+tCPoint.y,strThresh);
dc.TextOut(myP->IntCentdx[i-1]+tCPoint.x,myP->IntCentdy[i-1]+20+tCPoint.y,strsat);
dc.TextOut(myP->IntCentdx[i-1]+tCPoint.x,myP->IntCentdy[i-1]+40+tCPoint.y,strHue);
dc.TextOut(myP->IntCentdx[i-1]+tCPoint.x,myP->IntCentdy[i-1]+60+tCPoint.y,strnum);
}
ReleaseDC(&dc);
}
void CImageProcessView::OnTemptest()
{
if(!IsOpen)
{
AfxMessageBox("you must open a file first!");
return;
}
myP->ImageEnhance();
CClientDC dc(this);
DrawCenterDC(&dc);
ReleaseDC(&dc);
}
void CImageProcessView::OnBwdisplay()
{
myP->bwdisplay();
CClientDC dc(this);
DrawCenterDC(&dc);
ReleaseDC(&dc);
}
void CImageProcessView::OnRegbwdisplay()
{
myP->RegBwDisplay();
CClientDC dc(this);
DrawCenterDC(&dc);
ReleaseDC(&dc);
}
void CImageProcessView::OnEyepairs()
{
if(!IsOpen)
{
AfxMessageBox("you must open a file first!");
return;
}
clock_t start,finish;
start=clock();
myP->EyeRegDescription();
/*//CDC *pDC=GetDC();
RECT rect={20,30,180,230};
pDC->DrawEdge(&rect,BDR_RAISEDINNER,BF_RECT);*/
int l,label;
int number;
CDC *pDC=GetDC();
int i,j;
CRect tRect;
CPoint tCPoint;
GetClientRect(&tRect);
pDC->FillSolidRect(tRect,RGB(0,0,0));//Set background and refresh
tCPoint=tRect.CenterPoint();
tCPoint-=CSize(myP->myPWidth/2,myP->myPHeight/2);
//显示特征提取后的图
for(i=0; i<(int)myP->myPHeight; i++)
for(j=0; j<(int)myP->myPWidth; j++)
pDC->SetPixel(j+tCPoint.x , i+tCPoint.y , myP->myPArray[i*(myP->myPWidth)+j]);
//显示确定的人脸
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
for(l=0; l<myP->NumOfValidSkinReg; l++)
{
number=myP->eyeRegion[l].numOfEyes;
label=myP->eyeRegion[l].FcRegLabel;
//judge every conditions
for(i=0; i<number; i++)//1
{
for(j=i+1; j<number; j++)
{
if(*(myP->eyeRegion[l].eyesLocation+i*number+j))
{
pDC->MoveTo((myP->eyeRegion[l].pupilCol)[i]+tCPoint.x,(myP->eyeRegion[l].pupilRow)[i]+tCPoint.y);
pDC->LineTo((myP->eyeRegion[l].pupilCol)[j]+tCPoint.x,(myP->eyeRegion[l].pupilRow)[j]+tCPoint.y);
}
}
}
delete []myP->eyeRegion[l].eyesLocation;
}
pDC->SelectObject(pOldpen);
delete []myP->eyeRegion;// before this,all the array of it must be deleted.
finish=clock();
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -