📄 vehicletracedlg.cpp
字号:
// VehicleTraceDlg.cpp : implementation file
//
#include "stdafx.h"
#include "VehicleTrace.h"
#include "VehicleTraceDlg.h"
#include "HalconCpp.h"
#include <math.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();
// 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()
/////////////////////////////////////////////////////////////////////////////
// CVehicleTraceDlg dialog
CVehicleTraceDlg::CVehicleTraceDlg(CWnd* pParent /*=NULL*/)
: CDialog(CVehicleTraceDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CVehicleTraceDlg)
m_edit_xw = _T("50,200,200,50,");
m_edit_yw = _T("5,5,20,20,");
m_strPath = _T("E:\\VC++\\程序\\程序练习\\实验1\\");
FrameTime =0.04;
//}}AFX_DATA_INIT
// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
FrameSerialNum=0;
isPlay=false;
}
void CVehicleTraceDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CVehicleTraceDlg)
DDX_Control(pDX, IDC_BTN_CALIBRATION, m_btncalibrate);
DDX_Control(pDX, IDCONTINUE, m_btncontinue);
DDX_Control(pDX, IDEND, m_btnend);
DDX_Control(pDX, IDSTOP, m_btnstop);
DDX_Control(pDX, IDSTART, m_btnstart);
DDX_Text(pDX, IDC_EDIT_XW, m_edit_xw);
DDX_Text(pDX, IDC_EDIT_YW, m_edit_yw);
DDX_Text(pDX, IDC_EDIT_PATH, m_strPath);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CVehicleTraceDlg, CDialog)
//{{AFX_MSG_MAP(CVehicleTraceDlg)
ON_WM_SYSCOMMAND()
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
ON_BN_CLICKED(IDSTART, OnStart)
ON_WM_DESTROY()
ON_WM_CANCELMODE()
ON_WM_TIMER()
ON_WM_CAPTURECHANGED()
ON_BN_CLICKED(IDSTOP, OnStop)
ON_BN_CLICKED(IDCONTINUE, OnContinue)
ON_BN_CLICKED(IDEND, OnEnd)
ON_BN_CLICKED(IDSHOWPIC, OnShowpic)
ON_BN_CLICKED(IDC_BTN_CALIBRATION, OnBtnCalibration)
ON_BN_CLICKED(IDC_BTN_BROWNSE, OnBtnBrownse)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CVehicleTraceDlg message handlers
BOOL CVehicleTraceDlg::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
// Get the frame extents.
m_btncontinue.EnableWindow(false);
m_btnstop.EnableWindow(false);
m_btnend.EnableWindow(false);
m_btncalibrate.EnableWindow(false);
return TRUE; // return TRUE unless you set the focus to a control
}
void CVehicleTraceDlg::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 CVehicleTraceDlg::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 CVehicleTraceDlg::OnQueryDragIcon()
{
return (HCURSOR) m_hIcon;
}
/************************************************************************************/
/************************************************************************************/
void CVehicleTraceDlg::OnStart()
{
// 读取视频文件的文件名 (avi格式)
HTuple aviName;
CFileFind finder;
CString avifile=m_strPath+_T("\\*.avi");
BOOL flagavi= finder.FindFile(avifile);
if (flagavi)
{
finder.FindNextFile(); // 在调用函数getfilepath()之前一定要findnextfile()函数!
aviName = HTuple(finder.GetFilePath());
}
else
{
MessageBox("当前目录不存在avi文件!请将该文件拷至指定目录下...");
return;
}
// 读取相应的背景文件名 (图片tif或bmp格式)
HTuple Background;
CString Backgroundfile=m_strPath+_T("\\*.tif");
BOOL flagBackground= finder.FindFile(Backgroundfile);
if(flagBackground)
{
finder.FindNextFile(); // 在调用函数getfilepath()之前一定要findnextfile()函数!
Background=HTuple(finder.GetFilePath());
}
else
{
Backgroundfile=m_strPath+_T("\\*.bmp");
flagBackground= finder.FindFile(Backgroundfile);
if(flagBackground)
{
finder.FindNextFile();
Background=HTuple(finder.GetFilePath());
}
else
{
MessageBox("当前目录不存在背景图像文件!请将该文件(tif或bmp)拷至指定目录下...");
return;
}
}
// GetClientRect(&m_rWindowExtents);
open_framegrabber("File",1,1,0,0,0,0,"default",-1,"default",-1,"default",
aviName,"default",-1,1,&m_lFGHandle);
// grab_image(&Image,m_lFGHandle);
// 读取背景图像文件并创建背景图像
read_image(&Image,Background);
::get_image_pointer1(Image,_,_,&m_lWidth,&m_lHeight);
::zoom_image_factor(Image,&ImageZoomed,HTuple(0.5),HTuple(0.5),HTuple("constant"));
::create_bg_esti(ImageZoomed,HTuple(0.7),HTuple(0.7),HTuple("fixed"),HTuple(0.001),HTuple(0.03),HTuple("on"),HTuple(8.0),HTuple(10),HTuple(3.25),HTuple(15),&BgEstiHandle);
// Open the HALCON window that will be used to display the results.
long frame_window;
frame_window = (long)m_hWnd; // 注意m_hWnd!!
m_lWindowRow = 1;
m_lWindowColumn = 1;
// 注意tuple类型与vc中各变量类型的转换方法**********************************!!!
m_lWindowWidth = long(m_lWidth[0]); // m_lWidth在上面get_image_pointer1中被赋值,为HTuple型。
m_lWindowHeight = long(m_lHeight[0]); // m_lHeight在上面get_image_pointer1中被赋值,为HTuple型。
//在窗体上开一个显示图像的窗口,并给m_lpWindowID赋值
set_window_attr("border_width",0);
set_check("~father");
::open_window(m_lWindowRow,m_lWindowColumn,m_lWindowWidth,m_lWindowHeight,
frame_window,"visible","",&m_lpWindowID);
set_check("father");
set_line_width(m_lpWindowID,3);
::set_draw(m_lpWindowID,HTuple("margin"));
::set_colored(m_lpWindowID,HTuple(12));
set_part(m_lpWindowID,0,0,m_lHeight-1,m_lWidth-1); //确定图像被显示的区域
disp_obj(Image,m_lpWindowID); //在图片窗口中显示图片,注意和set_part连用!!
// 读取感兴趣的区域region并显示出来
HTuple regName;
CString regfile=m_strPath+_T("\\*.reg");
BOOL flagreg= finder.FindFile(regfile);
if (flagreg)
{
finder.FindNextFile(); // 在调用函数getfilepath()之前一定要findnextfile()函数!
regName = HTuple(finder.GetFilePath());
::read_region(&XingRegion,regName);
}
else
{
MessageBox("当前目录不存在region文件!请手动指定(左健指定位置,右健结束)...");
::draw_region(&XingRegion,m_lpWindowID);
}
finder.Close();
disp_obj(XingRegion,m_lpWindowID); //显示感兴趣的区域
set_check("~father");
::open_window(m_lWindowWidth,1,m_lWindowWidth,m_lWindowHeight,
frame_window,"visible","",&m_TrackWindowID);
set_check("father");
set_part(m_TrackWindowID,0,0,m_lHeight-1,m_lWidth-1);
disp_obj(XingRegion,m_TrackWindowID);
m_nIdEvent = SetTimer(1, 50,NULL); //设定时钟!
ASSERT(m_nIdEvent);
set_system("do_low_error","false");
m_btnstart.EnableWindow(false);
m_btnstop.EnableWindow(true);
m_btncontinue.EnableWindow(true);
m_btnend.EnableWindow(true);
m_btncalibrate.EnableWindow(true);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -