📄 tryshotdlg.cpp
字号:
}
// The system calls this to obtain the cursor to display while the user drags
// the minimized window.
HCURSOR CTryshotDlg::OnQueryDragIcon()
{
return (HCURSOR) m_hIcon;
}
CTryshotDlg::~CTryshotDlg()
{
DestroyGraph();
delete []m_pBmem;
delete []m_pBback;
delete []m_pTemp;
if (cb.pBuffer!=NULL)
{
delete []cb.pBuffer;
cb.pBuffer=NULL;
}
delete []pnCtrlVal;
}
void CTryshotDlg::CreateGraph()
{
DestroyGraph();
BOOL bflg=FALSE;
mFilterGraph = new CDXConstruction();
if (mFilterGraph->Create())
{
// Render the source clip
bflg=mFilterGraph->RenderCaptureLink(&mCB);
// Set video window and notification window
bflg=mFilterGraph->SetDisplayWindow(mVideoWindow.GetSafeHwnd());
// 首先由mVideoWindow取得自身的句柄
//再由函数
bflg=mFilterGraph->SetNotifyWindow(this->GetSafeHwnd());
// Show the first frame
bflg=mFilterGraph->Run();
}
}
void CTryshotDlg::DestroyGraph()
{
if (mFilterGraph)
{
// Stop the filter graph first
mFilterGraph->Stop();
mFilterGraph->SetNotifyWindow(NULL);
delete mFilterGraph;
mFilterGraph = NULL;
}
}
BOOL CTryshotDlg::OnEraseBkgnd(CDC* pDC)
{
CRect rc;
mVideoWindow.GetWindowRect(&rc);
ScreenToClient(&rc);
pDC->ExcludeClipRect(&rc);
return CDialog::OnEraseBkgnd(pDC);
}
BOOL CTryshotDlg::Play()
{
if (mFilterGraph)
{
return mFilterGraph->Run();
}
return FALSE;
}
BOOL CTryshotDlg::Stop()
{
if (mFilterGraph)
{
return mFilterGraph->Stop();
}
return FALSE;
}
//--进行采集--
void CTryshotDlg::OnOK()
{
// TODO: Add extra validation here
int k=m_CaptureNumb;
CString str_fname,strtime;
HWND hwnd_nmb=NULL;
//------strperson_numb,strLefthandorRighthand,strFirsttimeorSecondtime-------
if (!b_havesettingPersonalInformation)
{
CPersonalInfoDlg dlg;
if (dlg.DoModal()==IDOK)
{
dlg.getdatapoint(&strfilename);
b_havesettingPersonalInformation=TRUE;
}
}
if (b_havesettingPersonalInformation)
{
//文件名规则 "semi_第几个人的手掌_左手右手第一次第二次_序号时间.bmp"
//即 semi_001_LF_001070406.bmp
//取流水号和时间
strtime=GetSysDate();
for (int nIndex=0;nIndex<k;nIndex++)
{
str_fname.Empty();
//-----每个人照10次,每次照3张,一共30张
if ((m_naccumul>=1) || (m_naccumul<=9))
{
photonumboftheperson.Format("00%d",m_naccumul);
}
else if ((m_naccumul>=10) || (m_naccumul<=99))
{
photonumboftheperson.Format("0%d",m_naccumul);
}
else
{
photonumboftheperson.Format("100");
AfxMessageBox("采集文件序号超过限制!");
}
//semi_000_20074616320.bmp
str_fname=strfilename+photonumboftheperson+"_"+strtime+".bmp";//
switch (nIndex)
{
case 0:
GetDlgItem(IDC_VW1,&hwnd_nmb);
break;
case 1:
GetDlgItem(IDC_VW2,&hwnd_nmb);
break;
case 2:
GetDlgItem(IDC_VW3,&hwnd_nmb);
break;
case 3:
GetDlgItem(IDC_VW4,&hwnd_nmb);
break;
default:
GetDlgItem(IDC_VW0,&hwnd_nmb);
break;
}
if (nIndex==1)
{
Flash_Light();
Sleep(500);
}
Get_a_pic(str_fname,(m_pBmem+lWidth*lHeight*3*nIndex),hwnd_nmb);
if (nIndex==1)
{
Close_Light();
Sleep(500);
}
m_naccumul++;
}
}
else
{
CString str;
str.Format("采集参数设置不全,请重设!");
AfxMessageBox(str);
}
//----------------只进行采集后续工作用matlab-------------------
// 这里要更改_______将序号换成人的名字 [10/10/2006]
// HWND *phwndgp=new HWND[4];;
// GetDlgItem(IDC_VW5,(phwndgp+0));
// GetDlgItem(IDC_VW6,(phwndgp+1));
// GetDlgItem(IDC_VW7,(phwndgp+2));
// GetDlgItem(IDC_VW8,(phwndgp+3));
// int n=ppr.rec(m_pBmem,m_CaptureNumb,m_pBback,phwndgp);
// delete []phwndgp;
// CString str;
// str.Format("是第%d个人的掌纹",n);
// AfxMessageBox(str);
}
BOOL CTryshotDlg::Get_a_pic(CString strfname,BYTE * pD, HWND hwnd_nmb)
{
BOOL brlt=FALSE;
// Flash_Light();
brlt=mFilterGraph->Get_Photo(strfname,pD,hwnd_nmb);
// Close_Light();
return brlt;
}
void CTryshotDlg::OnSetphotonumb()
{
// TODO: Add your control notification handler code here
UpdateData(TRUE);
}
//--------系统初始化|或者性能下降时自动校正系统-----------
void CTryshotDlg::OnEmend()
{
CString str_fname,strcurrenttime;
str_fname.Empty();
str_fname=GetSysDate()+"background.bmp";
HWND hwnd=NULL;
GetDlgItem(IDC_VW4,&hwnd);
Get_a_pic(str_fname,m_pBback,hwnd);//先取得一幅背景图片做为参考背景
GetDlgItem(IDC_PHOTO_NUMB)->EnableWindow(TRUE);//--这两项是设置采集照片的数量框和按钮可用
GetDlgItem(IDC_SETPHOTONUMB)->EnableWindow(TRUE);
g_bOneShot=TRUE;//同时开始检测动目标_____启动回调函数_____当有动目标检测到时将两个按钮激活
//当动目标移开,按钮变灰失去作用
//_______________主要是校正肤色情况_______________//
}
//---------处理窗口刷新的问题-------------
void CTryshotDlg::refreshsubwnd()
{
BITMAPINFOHEADER bih;
memset(&bih,0,sizeof(BITMAPINFOHEADER));
bih.biSize=sizeof(bih);
bih.biWidth=lWidth;
bih.biHeight=lHeight;
bih.biPlanes=1;
bih.biBitCount=24;
HWND hwnd_nmb=NULL;
for (int nIndex=0;nIndex<m_CaptureNumb;nIndex++)
{
switch (nIndex)
{
case 0:
GetDlgItem(IDC_VW1,&hwnd_nmb);
break;
case 1:
GetDlgItem(IDC_VW2,&hwnd_nmb);
break;
case 2:
GetDlgItem(IDC_VW3,&hwnd_nmb);
break;
case 3:
GetDlgItem(IDC_VW4,&hwnd_nmb);
break;
default:
GetDlgItem(IDC_VW0,&hwnd_nmb);
break;
}
mFilterGraph->DisplayCapturedBits((m_pBmem+nIndex*lWidth*lHeight*3),
&bih,
hwnd_nmb);
}
}
LRESULT CTryshotDlg::WindowProc(UINT message, WPARAM wParam, LPARAM lParam)
{
if (message == WM_CAPTURE_BITMAP)
{
if (mCB.IsHandMoving(cb.dblSampleTime, cb.pBuffer, cb.lBufferSize,m_pBback))
{
//---当检测到手在视野内,就激活识别按钮等待采集识别指令
GetDlgItem(IDOK)->EnableWindow(TRUE);
}
else
{
GetDlgItem(IDOK)->EnableWindow(FALSE);
}
g_bOneShot=TRUE;//-----没有检测到手型动目标,继续检测接下来的帧
}
return CDialog::WindowProc(message, wParam, lParam);
}
void CTryshotDlg::OnLoadPic()
{
CString str_fname;
HWND hwnd_nmb=NULL;
str_fname.Format("Load_pic.bmp");
GetDlgItem(IDC_VW1,&hwnd_nmb);
//将照片读入m_pBmem中,由rec进行提取
CFile file;
CFileException fe;
if (!file.Open(str_fname, CFile::modeRead | CFile::shareDenyWrite, &fe))
{
return;
}
BITMAPFILEHEADER bmfHeader;
DWORD dwBitsSize;
dwBitsSize = file.GetLength();// 尝试读取DIB文件头
if (file.Read((LPSTR)&bmfHeader, sizeof(bmfHeader)) != sizeof(bmfHeader))
{
return;
}
if (bmfHeader.bfType != DIB_HEADER_MARKER)// 判断是否是DIB对象,检查头两个字节是否是"BM"
{
return;// 非DIB对象,返回NULL。
}
BITMAPINFOHEADER bmifHeader;
if (file.Read((LPSTR)&bmifHeader,sizeof(bmifHeader))!=sizeof(bmifHeader))
{
return;
}
if (file.Read(m_pBmem,bmifHeader.biWidth*bmifHeader.biHeight*3)
!=(UINT)(bmifHeader.biWidth*bmifHeader.biHeight*3))
{
return;
}
file.Close();
//////////////////////////////////////////////////////////////////////////
HWND O_hwnd;
GetDlgItem(IDC_VW1,&O_hwnd);
displaypic(m_pBmem,O_hwnd);//将照片显示在IDC_VW1
HWND *phwndgp=new HWND[4];;
GetDlgItem(IDC_VW5,(phwndgp+0));
GetDlgItem(IDC_VW6,(phwndgp+1));
GetDlgItem(IDC_VW7,(phwndgp+2));
GetDlgItem(IDC_VW8,(phwndgp+3));
int n=ppr.rec(m_pBmem,1,m_pBback,phwndgp);
delete []phwndgp;
CString str;
str.Format("是第%d个人的掌纹",n);
AfxMessageBox(str);
}
void CTryshotDlg::displaypic(BYTE *pD, HWND o_hwnd)
{
BITMAPINFOHEADER bih;
memset(&bih,0,sizeof(BITMAPINFOHEADER));
bih.biSize=sizeof(bih);
bih.biWidth=lWidth;
bih.biHeight=lHeight;
bih.biPlanes=1;
bih.biBitCount=24;
if (!o_hwnd || !pD)
return;
RECT rc;
::GetWindowRect( o_hwnd, &rc );
long lStillWidth = rc.right - rc.left;
long lStillHeight = rc.bottom - rc.top;
HDC hdcStill = ::GetDC( o_hwnd );
PAINTSTRUCT ps;
::BeginPaint(o_hwnd, &ps);
SetStretchBltMode(hdcStill, COLORONCOLOR);
StretchDIBits( hdcStill, 0, 0,
lStillWidth, lStillHeight,
0, 0, lWidth, lHeight,
pD,
(BITMAPINFO*) &bih,
DIB_RGB_COLORS,
SRCCOPY );
::EndPaint(o_hwnd, &ps);
::ReleaseDC( o_hwnd, hdcStill );
}
BOOL CTryshotDlg::Flash_Light()
{
BOOL brlt=TRUE;
BYTE nSetVal = *(pnCtrlVal+1);
PriWritePort(14,nSetVal);
return brlt;
}
BOOL CTryshotDlg::Close_Light()
{
BOOL brlt=TRUE;
BYTE nSetVal = *(pnCtrlVal+7);
PriWritePort(14,nSetVal);
return brlt;
}
void CTryshotDlg::OnButtonInputname()
{
// TODO: Add your control notification handler code here
CPersonalInfoDlg dlg;
if (dlg.DoModal()==IDOK)
{
dlg.getdatapoint(&strfilename);
b_havesettingPersonalInformation=TRUE;
GetDlgItem(IDC_EMEND)->EnableWindow(TRUE);
}
}
CString CTryshotDlg::GetSysDate()
{
CTime tm = CTime::GetCurrentTime();
// int year = tm.GetYear();
int month = tm.GetMonth();
int day = tm.GetDay();
// int hour = tm.GetHour();
// int min = tm.GetMinute();
// int sec = tm.GetSecond();
CString systime = "";
systime.Format("%d%d",//"%d%d%d%d%d%d",
month,day);//year,month,day,hour,min,sec);
return systime;
}
void CTryshotDlg::OnButtonTestlight()
{
// TODO: Add your control notification handler code here
if (b_TestLightFlag)
{
//灯开了就关掉
BYTE nSetVal=*(pnCtrlVal+7);
PriWritePort(14,nSetVal);
b_TestLightFlag=FALSE;
}
else
{
BYTE nSetVal = *(pnCtrlVal+1);
PriWritePort(14,nSetVal);
b_TestLightFlag=TRUE;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -