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

📄 pftrackdlg.cpp

📁 毕设终于作完了 虽然老师说行为分析做得很没意义
💻 CPP
📖 第 1 页 / 共 2 页
字号:
// PfTrackDlg.cpp : implementation file
//

#include "stdafx.h"
#include "PfTrack.h"
#include "PfTrackDlg.h"
#include "PathDlg.h"
#include "VideoWnd.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CAboutDlg dialog used for App About

class CAboutDlg : public CDialog
{
public:
	CAboutDlg();
  //   CVideoWnd videownd;
// Dialog Data
	//{{AFX_DATA(CAboutDlg)
	enum { IDD = IDD_ABOUTBOX };
	//}}AFX_DATA

	// ClassWizard generated virtual function overrides
	//{{AFX_VIRTUAL(CAboutDlg)
	protected:
	virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV support
	//}}AFX_VIRTUAL

// Implementation
protected:
	//{{AFX_MSG(CAboutDlg)
	//}}AFX_MSG
	DECLARE_MESSAGE_MAP()
};

CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
{
	//{{AFX_DATA_INIT(CAboutDlg)
	//}}AFX_DATA_INIT
}

void CAboutDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CAboutDlg)
	//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
	//{{AFX_MSG_MAP(CAboutDlg)
		// No message handlers
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CPfTrackDlg dialog

CPfTrackDlg::CPfTrackDlg(CWnd* pParent /*=NULL*/)
	: CDialog(CPfTrackDlg::IDD, pParent)
{
	//{{AFX_DATA_INIT(CPfTrackDlg)
		// NOTE: the ClassWizard will add member initialization here
	//}}AFX_DATA_INIT
	// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
	m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}

void CPfTrackDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CPfTrackDlg)
		// NOTE: the ClassWizard will add DDX and DDV calls here
	//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CPfTrackDlg, CDialog)
	//{{AFX_MSG_MAP(CPfTrackDlg)
	ON_WM_SYSCOMMAND()
	ON_WM_PAINT()
	ON_WM_QUERYDRAGICON()
	ON_BN_CLICKED(IDC_BUTTON_PATH, OnButtonPath)
	ON_BN_CLICKED(ID_OPENVIDEO, OnOpenvideo)
	ON_BN_CLICKED(IDC_BUTTON_TRACK, OnButtonTrack)
	ON_BN_CLICKED(IDC_BUTTON_ANALYSE, OnAnalyse)
//	ON_BN_CLICKED(IDC_BUTTON1, OnOpenVideo)
	ON_BN_CLICKED(IDC_OpenFile, OnOpenFile)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CPfTrackDlg message handlers

BOOL CPfTrackDlg::OnInitDialog()
{
	CDialog::OnInitDialog();

	// Add "About..." menu item to system menu.

	// IDM_ABOUTBOX must be in the system command range.
	ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
	ASSERT(IDM_ABOUTBOX < 0xF000);

	CMenu* pSysMenu = GetSystemMenu(FALSE);
	if (pSysMenu != NULL)
	{
		CString strAboutMenu;
		strAboutMenu.LoadString(IDS_ABOUTBOX);
		if (!strAboutMenu.IsEmpty())
		{
			pSysMenu->AppendMenu(MF_SEPARATOR);
			pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
		}
	}

	// Set the icon for this dialog.  The framework does this automatically
	//  when the application's main window is not a dialog
	SetIcon(m_hIcon, TRUE);			// Set big icon
	SetIcon(m_hIcon, FALSE);		// Set small icon
	
	// TODO: Add extra initialization here
	//获取控件 调整位置和大小

	GetDlgItem(IDC_VIDEOSHOW)->MoveWindow(10,20,320,240);
    GetDlgItem(IDC_SHOWPATH)->MoveWindow(350,20,320,240);
	//将图像放到容器中 
	videownd.SubclassDlgItem(IDC_VIDEOSHOW,this);

//  videownd.videostate=0;
//	设置状态0为初始状态
	videownd.state=0;

	//绘制背景
	videownd.DrawBackGround();
   DrawScene();
	return TRUE;  // return TRUE  unless you set the focus to a control
}

void CPfTrackDlg::OnSysCommand(UINT nID, LPARAM lParam)
{
	if ((nID & 0xFFF0) == IDM_ABOUTBOX)
	{
		CAboutDlg dlgAbout;
		dlgAbout.DoModal();
	}
	else
	{
		CDialog::OnSysCommand(nID, lParam);
	}
}

// If you add a minimize button to your dialog, you will need the code below
//  to draw the icon.  For MFC applications using the document/view model,
//  this is automatically done for you by the framework.

void CPfTrackDlg::OnPaint() 
{
	if (IsIconic())
	{
		CPaintDC dc(this); // device context for painting

		SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);

		// Center icon in client rectangle
		int cxIcon = GetSystemMetrics(SM_CXICON);
		int cyIcon = GetSystemMetrics(SM_CYICON);
		CRect rect;
		GetClientRect(&rect);
		int x = (rect.Width() - cxIcon + 1) / 2;
		int y = (rect.Height() - cyIcon + 1) / 2;

		// Draw the icon
		dc.DrawIcon(x, y, m_hIcon);
	}
	else
	{
		CDialog::OnPaint();
	}
	//////////////////////////////////////
 

}

// The system calls this to obtain the cursor to display while the user drags
//  the minimized window.
HCURSOR CPfTrackDlg::OnQueryDragIcon()
{
	return (HCURSOR) m_hIcon;
}

void CPfTrackDlg::OnButtonPath() 
{
	// TODO: Add your control notification handler code here
	videownd.state=3;
    //  CPathDlg pathdlg;
	 // pathdlg.DoModal();

	CRect conRect;
	//获得ID号为IDC_SHOWPATH的控件的CWND指针
	//并使用它获得相应的设备环境
    CWnd *pwnd=GetDlgItem(IDC_SHOWPATH);
	CDC *pdc=pwnd->GetDC();
	//获得该控件的矩形区域
	::GetClientRect(pwnd->m_hWnd, conRect);
	 //将索引值为NULL_BRUSH库对象选进设备环境
//	CPen   pen(PS_DASH,1,RGB(0,0,255)); 
	
	///////////////////////////////////////////
	CPen pen;
	pen.CreatePen(PS_SOLID,5,RGB(125,125,0));
	CPen* pOldPe=(CPen*)pdc->SelectObject(&pen);

     pdc->SelectStockObject(NULL_BRUSH);
	//pdc->SelectStockObject(NULL_BRUSH);
	//设置视口原点
	////////////////////////////////////////////////////////////////////////
	//绘制草地区域
	pdc->FillSolidRect(CRect(0,200,320,240),RGB(100,200,0)); 
	//绘制停车场位置
	pdc->FillSolidRect (CRect(0,0,320,100),RGB(200,200,0));
	//绘制车辆
	pdc->FillSolidRect (CRect(20,20,80,90),RGB(0,0,0));
	pdc->FillSolidRect (CRect(120,20,180,90),RGB(0,0,0));
	pdc->FillSolidRect (CRect(220,20,280,90),RGB(0,0,0));
	//////////////////////////////////////////////////////////////////////////
    
	videownd.getcount=videownd.getcount+1;
	for (int i=videownd.getcount;i<videownd.count-1;i++)
	{
		pdc->FillSolidRect(CRect(videownd.center[i][0]-3,   videownd.center[i][1]-3,   videownd.center[i][0]+3,   videownd.center[i][1]+3),RGB(125,125,0)); 
     	//pdc->SetPixel(videownd.center[i][0],videownd.center[i][1],RGB(255,0,0));
			pdc->MoveTo(videownd.center[i][0],videownd.center[i][1]);
         	pdc->LineTo(videownd.center[i+1][0],videownd.center[i+1][1]);
	}

 ////只作水平方向的分析
	pdc->FillSolidRect(CRect(videownd.center[videownd.count-1][0]-3,   videownd.center[videownd.count-1][1]-3,   videownd.center[videownd.count-1][0]+3,   videownd.center[videownd.count-1][1]+3),RGB(0,250,0)); 
	pdc->FillSolidRect(CRect(videownd.center[videownd.getcount][0]-3,   videownd.center[videownd.getcount][1]-3,   videownd.center[videownd.getcount][0]+3,   videownd.center[videownd.getcount][1]+3),RGB(250,0,0)); 
	//////////////////////////////////////////
	//从什么时候开始画矩形的问题以后再讨论
	///////////////////////////////////////
	distant=fabs(videownd.center[videownd.count-1][0]-videownd.center[videownd.getcount][0]);///20有待考虑////////
    CString str;
//	str.Format("%d",distant);
   // GetDlgItem(IDC_SHOWANALYSIS)->SetWindowText(str);

	velocity=float(distant)/float(videownd.count);
	//str.Format("%f",velocity);
	str.Format("%f",float(distant));
    GetDlgItem(IDC_SHOWANALYSIS)->SetWindowText(str);

	
	
}

void CPfTrackDlg::OnOpenvideo() 
{
	// TODO: Add your control notification handler code here

   videownd.VideoCatch();
}

void CPfTrackDlg::OnButtonTrack() 
{
	// TODO: Add your control notification handler code here
	//状态为初始状态打开摄像头
	if(videownd.state==0)
	{
	  ::AfxMessageBox("请先打开摄像头!");
        return;
	}
    else
	{//状态为正在跟踪时

	  	if(videownd.state==2)
		{
	       ::AfxMessageBox("正在跟踪!");
           return;
		}
	}
	//设置状态为跟踪状态
	videownd.state=2;
   ///////////////////////////////////////////////////////////////// 
	//粒子初始化
	videownd.DP=2;
	videownd.MP=2;
	videownd.SamplesNum=300;
	videownd.ConDens=cvCreateConDensation( videownd.DP, videownd.MP, videownd.SamplesNum );
    videownd.lowerBound = cvCreateMat(2, 1, CV_32F);
    videownd.upperBound = cvCreateMat(2, 1, CV_32F);

    cvmSet( videownd.lowerBound, 0, 0, 0.0 ); cvmSet( videownd.upperBound, 0, 0, 320.0 );//////////////////
    cvmSet( videownd.lowerBound, 1, 0, 0.0 ); cvmSet( videownd.upperBound, 1, 0, 240.0 );////////////////

    cvConDensInitSampleSet(videownd.ConDens, videownd.lowerBound, videownd.upperBound);
   
    for(int i=0; i < videownd.SamplesNum; i++){
        videownd.ConDens->flSamples[i][0]+=160.0;
        videownd.ConDens->flSamples[i][1]+=120.0;
    }
  
   videownd.ConDens->DynamMatr[0]=1.0;videownd.ConDens->DynamMatr[1]=0.0;
   videownd.ConDens->DynamMatr[2]=0.0;videownd.ConDens->DynamMatr[3]=1.0;
///////////////////////////////////////////////////////////////////////////

   /////////////////////////////////////////////

	videownd.PFTrack();
}

//DEL void CPfTrackDlg::DrawPath()
//DEL {
//DEL   	CPathDlg pathDlg;
//DEL 	pathDlg.DoModal();
//DEL }

void CPfTrackDlg::OnAnalyse() 
{
	// TODO: Add your control notification handler code here
	//设置状态为分析状态
	videownd.state=4;
	CString str;
	CWnd *pwnd=GetDlgItem(IDC_SHOWANALYSIS);
	pwnd->SetWindowText("");
    /////////////无场景分析

	////////////////////////////
	//有场景分析
	//在草坪区域
	if(videownd.center[videownd.count-1][1]>200)

⌨️ 快捷键说明

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