📄 videodlg.cpp
字号:
// VideoDlg.cpp : implementation file
//
#include "stdafx.h"
#include "Robocup.h"
#include "VideoDlg.h"
#include "Global.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CVideoDlg dialog
CVideoDlg *CVideoDlg::m_pVideoDlg=NULL;
CVideoDlg::CVideoDlg(CWnd* pParent /*=NULL*/)
: CDialog(CVideoDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CVideoDlg)
m_brt_edit = _T("");
m_con_edit = _T("");
m_hue_edit = _T("");
m_sat_edit = _T("");
m_time = 0;
m_yuv_u = 0;
m_yuv_v = 0;
m_yuv_y = 0;
m_u_high = 0;
m_u_low = 0;
m_v_high = 0;
m_v_low = 0;
m_y_high = 0;
m_y_low = 0;
m_x = 0;
m_y = 0;
m_FrameWidth = 320;
m_FrameHeight = 240;
m_bIsLBDown = FALSE;
m_FieldRect = CRect(0, 0, 0, 0);
m_pConfigDlg = NULL;
m_TotalSeconds = 0;
m_FrameCount = -1;
m_EndTime = 0;
m_StartTime = 0;
flag=FALSE;
m_lable1x = 0;
m_lable2x = 0;
m_lable3x = 0;
m_lable1y = 0;
m_lable2y = 0;
m_lable3y = 0;
m_angle = 0;
m_k = 0;
//}}AFX_DATA_INIT
sum=10;
m_IsSnapToMem=false;
m_IsGetFieldRectChecked=false;
for(i=0;i<5;i++)
{
MyTeamRectNum[i] = 0;
TheirTeamRectNum[i] = 0;
for(j=0;j<10;j++)
{
for(k=0;k<2;k++)
{
My_LableCentreGravity[j][k] = 0;
Their_LableCentreGravity[j][k] = 0;
Ball_CentreGravity[j][k] = 0;
My_CentreGravity[i][k] = 0;
}
}
}
initYuv();
}
void CVideoDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CVideoDlg)
/* DDX_Control(pDX, IDC_YUV_YL, m_yuv_yl);
DDX_Control(pDX, IDC_YUV_YH, m_yuv_yh);
DDX_Control(pDX, IDC_YUV_VL, m_yuv_vl);
DDX_Control(pDX, IDC_YUV_VH, m_yuv_vh);
DDX_Control(pDX, IDC_YUV_UL, m_yuv_ul);
DDX_Control(pDX, IDC_YUV_UH, m_yuv_uh);*/
DDX_Control(pDX, IDC_SAT_SCROLLBAR, m_sat_scrollbar);
DDX_Control(pDX, IDC_HUE_SCROLLBAR, m_hue_scrollbar);
DDX_Control(pDX, IDC_CON_SCROLLBAR, m_con_scrollbar);
DDX_Control(pDX, IDC_BRT_SCROLLBAR, m_brt_scrollbar);
DDX_Text(pDX, IDC_BRT_EDIT, m_brt_edit);
DDX_Text(pDX, IDC_CON_EDIT, m_con_edit);
DDX_Text(pDX, IDC_HUE_EDIT, m_hue_edit);
DDX_Text(pDX, IDC_SAT_EDIT, m_sat_edit);
DDX_Text(pDX, IDC_time, m_time);
DDX_Text(pDX, IDC_YUV_U, m_yuv_u);
DDX_Text(pDX, IDC_YUV_V, m_yuv_v);
DDX_Text(pDX, IDC_YUV_Y, m_yuv_y);
DDX_Text(pDX, IDC_U_HIGH, m_u_high);
DDX_Text(pDX, IDC_U_LOW, m_u_low);
DDX_Text(pDX, IDC_V_HIGH, m_v_high);
DDX_Text(pDX, IDC_V_LOW, m_v_low);
DDX_Text(pDX, IDC_Y_HIGH, m_y_high);
DDX_Text(pDX, IDC_Y_LOW, m_y_low);
DDX_Text(pDX, IDC_X, m_x);
DDX_Text(pDX, IDC_Y, m_y);
DDX_Text(pDX, IDC_EDIT9, m_lable1x);
DDX_Text(pDX, IDC_EDIT10, m_lable2x);
DDX_Text(pDX, IDC_EDIT11, m_lable3x);
DDX_Text(pDX, IDC_EDIT12, m_lable1y);
DDX_Text(pDX, IDC_EDIT13, m_lable2y);
DDX_Text(pDX, IDC_EDIT14, m_lable3y);
DDX_Text(pDX, IDC_EDIT15, m_angle);
DDX_Text(pDX, IDC_EDIT16, m_k);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CVideoDlg, CDialog)
//{{AFX_MSG_MAP(CVideoDlg)
ON_WM_LBUTTONDOWN()
ON_WM_LBUTTONUP()
ON_WM_MOUSEMOVE()
ON_BN_CLICKED(IDC_SnapToMem, OnSnapToMem)
ON_BN_CLICKED(IDC_DISPLAY, OnDisplay)
ON_BN_CLICKED(IDC_STOPDISP, OnStopdisp)
ON_BN_CLICKED(IDC_DEFAULT, OnDefault)
ON_WM_HSCROLL()
ON_BN_CLICKED(IDC_BUTTON1, OnButton1)
ON_WM_TIMER()
ON_BN_CLICKED(IDC_BUTTON3, OnButton3)
ON_BN_CLICKED(IDC_BUTTON4, OnButton4)
ON_WM_RBUTTONDOWN()
ON_BN_CLICKED(IDC_BUTTON5, OnButton5)
ON_BN_CLICKED(IDC_GET, OnGet)
ON_BN_CLICKED(IDC_InitYUVClass, OnInitYUVClass)
ON_BN_CLICKED(IDC_READ, OnRead)
ON_WM_SIZE()
ON_WM_DESTROY()
ON_WM_DELETEITEM()
ON_BN_CLICKED(IDC_SAVE, OnSave)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CVideoDlg message handlers
void CVideoDlg::InitVideo()
{
hcg400 = BeginCG400(1);
if (hcg400 == 0)
{
MessageBox("启动视频窗口错误!");
return;
}
CRect rect;
CRect ClientRect;
GetClientRect(&ClientRect);
ClientToScreen(&ClientRect);
CG400SetDispMode(hcg400,FRAME);
// CG400SetColorSpace(hcg400,YUV422);
CG400SetColorSpace(hcg400,RGB8888);//设置图像卡输出的彩色空间格式:32位
CG400SetInpVideoWindow(hcg400,0,0,640,480);
// CG400SetInpVideoWindow(hcg400,0,0,640,480);
CG400SetDispWindow(hcg400,ClientRect.left, ClientRect.top,640,480);
CG400SetVideoStandard(hcg400,NTSC);
CG400Capture(hcg400,true);
}
BOOL CVideoDlg::OnInitDialog()
{
CDialog::OnInitDialog();
m_brt_scrollbar.SetScrollRange(0,255);
m_con_scrollbar.SetScrollRange(0,255);
m_hue_scrollbar.SetScrollRange(0,255);
m_sat_scrollbar.SetScrollRange(0,255);
/* m_yuv_yh.SetScrollRange(0,255);
m_yuv_uh.SetScrollRange(0,255);
m_yuv_vh.SetScrollRange(0,255);
m_yuv_yl.SetScrollRange(0,255);
m_yuv_ul.SetScrollRange(0,255);
m_yuv_vl.SetScrollRange(0,255);*/
OnDefault() ;
MoveWindow(0, 0, 649,740);
InitVideo();
return TRUE;
}
BEGIN_EVENTSINK_MAP(CVideoDlg, CDialog)
//{{AFX_EVENTSINK_MAP(CVideoDlg)
//}}AFX_EVENTSINK_MAP
END_EVENTSINK_MAP()
BOOL CVideoDlg::ScanNearRect(CRect rect,
double percent,
byte Upper[],
byte Lower[],
int ReturnCentrePoint[],
int colnum)
{//判断在rect矩形框里符合采样标准的点是否达到设定的百分比percent,
//如果达到,返回ture,并把求出的重心放在ReturnCentrePoint中,
//如果没有达到,返回false,ReturnCentrePoint无意义
int i, j;
byte Get_RGB[3];
int count;
int total;
int limit;
int rowSum;
int colSum;
count = 0;
rowSum = 0;
colSum = 0;
total = rect.Width() * rect.Height();
limit = (int)(total * percent);
/* if(rect.left < m_FieldRect.left)
rect.left = m_FieldRect.left ;
if(rect.top < m_FieldRect.top)
rect.top = m_FieldRect.top ;
if(rect.right > m_FieldRect.right)
rect.right = m_FieldRect.right ;
if(rect.bottom > m_FieldRect.bottom)
rect.bottom = m_FieldRect.bottom ;*/
if(rect.left < 1)
rect.left = 0 ;
if(rect.top < 1)
rect.top = 0 ;
if(rect.right > 639)
rect.right = 639 ;
if(rect.bottom > 479)
rect.bottom = 479 ;
for(i = rect.left; i < rect.right; i++)
for(j = rect.top; j < rect.bottom; j++)
{
GetPixelColor(i, j, Get_RGB);
RGB_TO_YUV(Get_RGB,Col_YUV);
//if(IsMeetRestrict(Col_YUV,Upper, Lower))
if(YUVClass[Col_YUV[2]][colnum][2]
&&YUVClass[Col_YUV[1]][colnum][1]
&&YUVClass[Col_YUV[0]][colnum][0])
{
rowSum += j;
colSum += i;
count++;
}
};
if(count > limit)
{
ReturnCentrePoint[0] = (int)(rowSum / count);
ReturnCentrePoint[1] = (int)(colSum / count);
}
else
{
return FALSE;
}
return TRUE;
}
BOOL CVideoDlg::IsMeetRestrict(byte Col_RGB[],
byte Upper[],
byte Lower[])
{
BOOL bResult = FALSE;
// int Total;
if(Col_RGB[2] >= Lower[0] && Col_RGB[2] <= Upper[0])
{//红分量比例约束
if(Col_RGB[1] >= Lower[1] && Col_RGB[1] <= Upper[1])
{//绿分量比例约束
//Total = Col_RGB[0] + Col_RGB[1] + Col_RGB[2];
if(Col_RGB[0] >= Lower[2] && Col_RGB[0] <= Upper[2])//三分量总值约束
bResult = TRUE;
}
}
return bResult;
}
void CVideoDlg::SetConfigDlg(CConfigDlg *pConfigDlg)
{
m_pConfigDlg = pConfigDlg;
}
void CVideoDlg::OnLButtonDown(UINT nFlags, CPoint point)
{
m_x=point.x;
m_y=point.y;
UpdateData(false);
if((point.x<640)&&(point.y<480))
{
m_bIsLBDown = TRUE;
m_pConfigDlg->UpdateData(true);
if (m_pConfigDlg->m_bMY_door)
{
my_Door.left = point.x;
my_Door.top = point.y;
my_Door.right = point.x;
my_Door.bottom = point.y;
SetTimer(3, 50, NULL);
}
else
if (m_pConfigDlg->m_bTh_door)
{
th_Door.left = point.x;
th_Door.top = point.y;
th_Door.right = point.x;
th_Door.bottom = point.y;
SetTimer(3, 50, NULL);
}
else
if(m_pConfigDlg->m_bCheckGetFieldRect)
{
m_FieldRect.left = point.x;
m_FieldRect.top = point.y;
m_FieldRect.right = point.x;
m_FieldRect.bottom = point.y;
SetTimer(3, 50, NULL);
}
else
if (m_pConfigDlg->m_rect_sample)
{
sample_rect.left = point.x;
sample_rect.top = point.y;
sample_rect.right = point.x;
sample_rect.bottom = point.y;
SetTimer(3, 50, NULL);
}
else
{
unsigned char R, G, B;
GetPixelColor(point.x, point.y, Get_RGB);
R = Get_RGB[2];
G = Get_RGB[1];
B = Get_RGB[0];
RGB_TO_YUV(Get_RGB,Col_YUV);
m_yuv_y=Col_YUV[2];
m_yuv_u=Col_YUV[1];
m_yuv_v=Col_YUV[0];
UpdateData(false);
CString str1, str2, str3;
str1.Format("R=%d, G=%d, B=%d",R, G, B);
m_pConfigDlg->m_ColorInfo.SetWindowText(str1);
str2.Format("x=%d, y=%d", point.x, point.y);
m_pConfigDlg->m_CoorInfo.SetWindowText(str2);
str3.Format("总值:%d", (R+G+B));
m_pConfigDlg->m_MeanRGBInfo.SetWindowText(str3);
m_pConfigDlg->m_red = Col_YUV[2];
m_pConfigDlg->m_green = Col_YUV[1];
m_pConfigDlg->m_blue = Col_YUV[0];
m_pConfigDlg->showcolour(R,G,B);
}
}
CDialog::OnLButtonDown(nFlags, point);
}
void CVideoDlg::GetPixelColor(int X, int Y,byte Col_RGB[])
{
if((X<0)||(X>=639)) return;
if ((Y<0)||(Y>=479)) return;
int a;
a=Y*640*3+X*3;
Col_RGB[2] =(byte)colour[a+2];//R
Col_RGB[1] =(byte)colour[a+1];//G
Col_RGB[0] =(byte)colour[a+0];//B
}
void CVideoDlg::OnLButtonUp(UINT nFlags, CPoint point)
{
if((point.x<640)&&(point.y<480))
{
if (m_pConfigDlg->m_bMY_door && m_bIsLBDown)
{
my_Door.right = point.x;
my_Door.bottom = point.y;
if(my_Door.right < my_Door.left)
my_Door.right = my_Door.left;
if(my_Door.bottom < my_Door.top)
my_Door.bottom = my_Door.top;
KillTimer(3);
DrawFieldRect(my_Door);
m_pConfigDlg->m_bMY_door=false;
m_pConfigDlg->UpdateData(false);
// SetTimer(3, 50, NULL);
}
if (m_pConfigDlg->m_bTh_door && m_bIsLBDown)
{
th_Door.right = point.x;
th_Door.bottom = point.y;
if(th_Door.right < th_Door.left)
th_Door.right = th_Door.left;
if(th_Door.bottom < th_Door.top)
th_Door.bottom = th_Door.top;
KillTimer(3);
DrawFieldRect(th_Door);
m_pConfigDlg->m_bTh_door=false;
m_pConfigDlg->UpdateData(false);
// SetTimer(3, 50, NULL);
}
if(m_pConfigDlg->m_bCheckGetFieldRect && m_bIsLBDown)
{
m_FieldRect.right = point.x;
m_FieldRect.bottom = point.y;
if(m_FieldRect.right < m_FieldRect.left)
m_FieldRect.right = m_FieldRect.left;
if(m_FieldRect.bottom < m_FieldRect.top)
m_FieldRect.bottom = m_FieldRect.top;
KillTimer(3);
CG400Capture(hcg400,false);
DrawFieldRect(m_FieldRect);
OnSnapToMem();
InitTeam();
m_pConfigDlg->m_bCheckCapRect=true;
m_pConfigDlg->m_bCheckGetFieldRect=false;
m_pConfigDlg->UpdateData(false);
}
if (m_pConfigDlg->m_rect_sample && m_bIsLBDown)
{
sample_rect.right = point.x;
sample_rect.bottom = point.y;
if(sample_rect.right < sample_rect.left)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -