📄 liveviewdlg.h
字号:
// LiveViewDlg.h : header file
//
#if !defined(AFX_LIVEVIEWDLG_H__1E772945_A5CA_4B5D_AFB4_32A052BF0D66__INCLUDED_)
#define AFX_LIVEVIEWDLG_H__1E772945_A5CA_4B5D_AFB4_32A052BF0D66__INCLUDED_
#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
#include "Utilities.h"
#include <queue>
#include "bcam.h"
#include "BCameraSet.h"
#include "BcamUtility.h"
#include "MyQuery.h"
#include "WhiteBalancer.h"
#include "Globe.h"
#include "DecisionMakingx.h"
#include "Comm.h"
/////////////////////////////////////////////////////////////////////////////
// CLiveViewDlg dialog
using namespace std;
using namespace Bcam;
/////////////////////////////////////////////////++
const unsigned int NUM_BUFFERS = 5;//! 使用图像缓冲区的数量
const bool USE_ONESHOT = false;// 单帧采集还是连续采集,表明是连续采集
const UINT WM_GRAB_FINISHED = WM_USER+3;//! 当每帧图像采集完成时由采集线程发出的消息
//const UINT WM_GRAB_FINISHED = WM_USER+100;
const UINT WM_GRAB_STOPPED = WM_USER + 1;//! 当用户要终止采集时由采集线程发出的消息
const UINT WM_ERROR = WM_USER +2; //! 当采集发生错误时由采集线程发出的消息
const UINT ID_TIMER_DISPLAY = 1001;// 刷新窗体状态栏显示的定时器ID
const UINT TIMER_SPACE_NUM = 500;// 定时器的时间间隔为1秒
const UINT MYQUEUE_LENGTH = 50;// 循环链队列的长度
typedef struct tagGroundInfo{//一个点的坐标映射和标志
int x; //x坐标映射
int y; //y坐标映射
bool flag; //该点是否为场地内的点的标志:1在场内,0不在场内
}GroundInfo;
typedef struct tagGround{//场地参数结构体,用于记录场地的各种参数
GroundInfo groundInfo[640][480]; //图象内每个点的坐标映射和标志
CPoint Center; //场地中心点
CPoint LeftTop; //场地左上角
CPoint RightBottom; //场地右下角
CPoint GateLeftTop; //门区左上角
CPoint GateRightBottom; //门区右下角
double M; //变形参数M
double E; //变形参数E
public:
BITMAP btp;
CRect rect;
}Ground;
typedef struct
{
int X; // x coordinate of the object center.
int Y; // y coordinate of the object center.
int Size; //number of pixels
RECT Rect; // circumscribed rectangle.
}OBJECT_T;
/////////////////////////////////////////////////--
#define CATCH_MSGBOX( Caption ) \
catch( BcamException &e ) \
{ \
CString Buffer, B; \
Buffer += (B.Format("Exception 0x%X occurred\n", e.Error() ), B); \
Buffer += (B.Format("Message = %s\n", e.Description() ), B); \
Buffer += (B.Format("Context = %s\n", e.Context()), B); \
MessageBox(Buffer, _T(Caption), MB_OK | MB_ICONEXCLAMATION); \
} \
catch (...) \
{ \
BcamException e(DISP_E_EXCEPTION, "CLiveViewDlg::OnGrabLive"); \
CString Buffer, B; \
Buffer += (B.Format("Exception 0x%X occurred\n", e.Error() ), B); \
Buffer += (B.Format("Message = %s\n", e.Description() ), B); \
Buffer += (B.Format("Context = %s\n", e.Context()), B); \
MessageBox(Buffer, _T(Caption), MB_OK | MB_ICONEXCLAMATION); \
}
#define WAIT_OBJECT_0 ((STATUS_WAIT_0 ) + 0 )
class CLiveViewDlg : public CDialog
{
// Construction
public:
int JudgeColor(int a,int b);
int FindRobotID(CPoint RP1,CPoint RP2);
bool FindBlackID(int m,int n,int Num);
int screenBuffer(int a, int b, RGBTRIPLE *P);
bool push(int x, int y);
void emptyStack();
bool pop(int &x, int &y);
void StartGame();
void DrawBall(CDC*pDC);
void DrawRobot(CDC *pDC);
void IdentifyBall();
void IdentifyRobot();
void Identify();
bool SearchLUT(int tab,RGBTRIPLE*pStart,int *LUT,int SizeMin,int SizeMax,int Left,int Top,int Right,int Bottom,int MaskColor);
bool IdentifySearchLUT(int tab,RGBTRIPLE*pStart,int *LUT,int SizeMin,int SizeMax,int Left,int Top,int Right,int Bottom,int MaskColor);
void IdentifyTest();
//--------------用于采集和调节参数的函数和变量--------------//
void GetFrameRate(double& acquired, double& displayed);
void GetParaFromIniFile();
void InitGlobVar();
void SetVVal(UINT uV);
void SetUVal(UINT uU);
void SetShutterVal(UINT uShutter);
void SetGainVal(UINT uGain);
void SetBrightnessVal(UINT uBright);
CBcam m_Bcam; //! BCAM对象用来控制摄像机
CBCameraSet *m_pBCameraSet ;
CMyQueue* m_pMyQueue;// 循环链队列对象,存储采集图像的数据
CSize m_ImageSize; //! 采集图像的大小
DCSColorCode m_ColorCode;
bool m_bConnectBcam;// 是否连接摄像机标志
bool m_LiveGrabbing;//! 标记是否正在采集,True是采集正在进行
char* m_ptrBitmaps[NUM_BUFFERS];//! 指针数组,每个数组成员是指向一个图像缓冲区的指针
char* m_pSingleBitmap;//单帧采的缓存
PBITMAPINFO m_ptrBmpInfo; //! 指针,保存每帧图像的BitmapInfo,在回显图像时使用
PBYTE m_pDispBitmap,m_pBitmap,m_pDispSingle;
CThread m_GrabThread; //! 采集线程
CThread m_DispThread;//! 显示线程
static DWORD WINAPI GrabThreadProc(void* pParameter);//! 采集线程中m_GrabThreadThe使用的回调函数
static DWORD WINAPI DispThreadProc(void* pParameter);// 显示线程
UINT m_nBrightness;// 亮度
UINT m_nGain;//增溢
UINT m_nShutter;//快门
UINT m_nU;
UINT m_nV;
CStopWatch m_DisplayWatch; /// timer to measure the time needed to display one buffer
CStopWatch m_AcquisitionWatch;/// timer to measure the time needed to acquire one buffer
CMovingAvg<double, 20> m_AcquisitionAvg; /// Moving average of time needed to acquire one buffer
CMovingAvg<double, 20> m_DisplayAvg;/// Moving average of time needed to display one buffer
CCriticalSection m_CritSect;// 临界对象,同步线程使用
BOOL m_bIsDispImage; // 是否显示图像
bool m_bOCROk;
int m_nLostFrame;//丢失的帧数
CEvent m_evtNewBufferAvailable; /// signals that a new buffer is available to be processed by the display thread
CEvent m_evtTerminate; /// signals that the display thread is to be terminated
CWhiteBalancer m_WhiteBalancer;//白平衡对象
bool m_bEnabledWhiteBalancer;// 是否做白平衡状态标志,true:做,false:不做
//--------------------------------------------------------------------------------------//
CDC* GetStaticDC(int Object);
void ColorAnalyse();
void ColorAnalyse1();
void Filter();
void Filter1();
int SetSelect;
CRect m_Rect,m_Rect1,m_Rect2;
int SelectCount; //选择计数器
int PointCount; //放大采色点计数器
CPoint TempSelect[6];
CPoint LocalPoint[10];//扩大采色时用来存放最多十个点
CDC destDC;
CDC groundDC;
COLORREF ObjectColor[7];
COLORREF ObjectColorBK;
CString PathName;
bool m_colortest;
BOOL m_test;
BOOL m_start;
BOOL InitOK;
RobotInford robotInfor[11],robotBk[11];
double NormalTheta[11];
CPoint m_Target[7];
double m_theta;
CDecisionMakingx m_DecisionMakingx;
Ccomm m_RobotComm;
dbPOINT Gotopoint;
CPoint TeamTarget[3];
dbPOINT PreRobotInfor[3];
RGBTRIPLE*m_pIdentify;
bool m_stop;
bool m_savePara;
int m_xLeft,m_xRight,m_yTop,m_yBottom;
int BlackSum[4];
CLiveViewDlg(CWnd* pParent = NULL); // standard constructor
// Dialog Data
//{{AFX_DATA(CLiveViewDlg)
enum { IDD = IDD_LIVEVIEW_DIALOG };
CStatic m_local;
CStatic m_smem2;
CButton m_save;
CStatic m_steam;
CStatic m_smem5;
CStatic m_smem4;
CStatic m_smem3;
CStatic m_smem1;
CStatic m_sball;
CComboBox m_strategyselect;
CStatic m_display;
int m_brightness;
int m_gain;
int m_shutter;
int m_slidegain;
int m_v;
int m_u;
int m_slideshutter;
int m_slideu;
int m_slidev;
int m_slidebrightness;
double m_caprate;
double m_disprate;
int m_setselect;
int m_attack;
int m_area;
int m_kick;
int m_lostframe;
BOOL m_nesample;
BOOL m_nefilter;
int m_robotnum;
int m_rightvalue;
int m_leftvalue;
int m_object;
int m_change1;
int m_change2;
BOOL m_SelectRect;
BOOL m_CorrectPatch;
int m_length;
//}}AFX_DATA
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CLiveViewDlg)
protected:
virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
//}}AFX_VIRTUAL
// Implementation
protected:
HICON m_hIcon;
// Generated message map functions
//{{AFX_MSG(CLiveViewDlg)
virtual BOOL OnInitDialog();
afx_msg void OnSysCommand(UINT nID, LPARAM lParam);
afx_msg void OnPaint();
afx_msg HCURSOR OnQueryDragIcon();
afx_msg void OnCaptrue();
afx_msg LRESULT OnGrabFinished(WPARAM wParam, LPARAM lParam);
afx_msg LRESULT OnGrabStopped(WPARAM wParam, LPARAM lParam);
afx_msg LRESULT OnError(WPARAM wParam, LPARAM lParam);
afx_msg void OnStop();
afx_msg void OnReleasedcaptureSliderBrightness(NMHDR* pNMHDR, LRESULT* pResult);
afx_msg void OnReleasedcaptureSliderGain(NMHDR* pNMHDR, LRESULT* pResult);
afx_msg void OnReleasedcaptureSliderShutter(NMHDR* pNMHDR, LRESULT* pResult);
afx_msg void OnReleasedcaptureSliderU(NMHDR* pNMHDR, LRESULT* pResult);
afx_msg void OnReleasedcaptureSliderV(NMHDR* pNMHDR, LRESULT* pResult);
afx_msg void OnChangeEditBrightness();
afx_msg void OnChangeEditGain();
afx_msg void OnChangeEditShutter();
afx_msg void OnChangeEditU();
afx_msg void OnChangeEditV();
afx_msg void OnSavepara();
afx_msg void OnTimer(UINT nIDEvent);
afx_msg void OnGrabsingle();
afx_msg void OnLButtonDown(UINT nFlags, CPoint point);
afx_msg void OnRadioColorselect();
afx_msg void OnRadioBoundset();
afx_msg void OnMouseMove(UINT nFlags, CPoint point);
afx_msg void OnBoundset();
afx_msg void OnLoad();
afx_msg void OnSave();
afx_msg void OnSaveas();
afx_msg void OnColorsampling();
afx_msg void OnColortest();
afx_msg void OnColorfilter();
afx_msg void OnClear();
afx_msg void OnIdentifytest();
virtual void OnOK();
afx_msg void OnInitial();
afx_msg void OnStart();
afx_msg void OnEnlarge();
afx_msg void OnNewsample();
afx_msg void OnNewfilter();
afx_msg void OnZero();
afx_msg void OnDestroy();
afx_msg void OnForth();
afx_msg void OnBack();
afx_msg void OnLeft();
afx_msg void OnRight();
afx_msg void OnStoprobot();
afx_msg void OnWhitebalance();
afx_msg void OnColorexchange();
afx_msg void OnReback();
afx_msg void OnButtonReturn();
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
};
//{{AFX_INSERT_LOCATION}}
// Microsoft Visual C++ will insert additional declarations immediately before the previous line.
#endif // !defined(AFX_LIVEVIEWDLG_H__1E772945_A5CA_4B5D_AFB4_32A052BF0D66__INCLUDED_)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -