📄 liveviewdlg.cpp
字号:
}
void CLiveViewDlg::SetVVal(UINT uV)
{
m_v = uV;
m_slidev = uV;
UpdateData(FALSE);
m_nV=uV;
if(m_bConnectBcam)
{
if(m_LiveGrabbing)
{
if ( m_ColorCode != DCSColor_Mono8 )
{
m_Bcam.WhiteBalance.Raw.VRValue.SetAsync(uV);
}
else
m_pBCameraSet->SetBGain(uV / 100.0);
}
}
}
void CLiveViewDlg::OnReleasedcaptureSliderBrightness(NMHDR* pNMHDR, LRESULT* pResult)
{
// TODO: Add your control notification handler code here
UpdateData(TRUE);
SetBrightnessVal(m_slidebrightness);
*pResult = 0;
}
void CLiveViewDlg::OnReleasedcaptureSliderGain(NMHDR* pNMHDR, LRESULT* pResult)
{
// TODO: Add your control notification handler code here
UpdateData(TRUE);
SetGainVal(m_slidegain);
*pResult = 0;
}
void CLiveViewDlg::OnReleasedcaptureSliderShutter(NMHDR* pNMHDR, LRESULT* pResult)
{
// TODO: Add your control notification handler code here
UpdateData(TRUE);
SetShutterVal(m_slideshutter);
*pResult = 0;
}
void CLiveViewDlg::OnReleasedcaptureSliderU(NMHDR* pNMHDR, LRESULT* pResult)
{
// TODO: Add your control notification handler code here
UpdateData(TRUE);
SetUVal(m_slideu);
*pResult = 0;
}
void CLiveViewDlg::OnReleasedcaptureSliderV(NMHDR* pNMHDR, LRESULT* pResult)
{
// TODO: Add your control notification handler code here
UpdateData(TRUE);
SetVVal(m_slidev);
*pResult = 0;
}
void CLiveViewDlg::OnChangeEditBrightness()
{
// TODO: If this is a RICHEDIT control, the control will not
// send this notification unless you override the CDialog::OnInitDialog()
// function and call CRichEditCtrl().SetEventMask()
// with the ENM_CHANGE flag ORed into the mask.
// TODO: Add your control notification handler code here
UpdateData(TRUE);
SetBrightnessVal(m_brightness);
}
void CLiveViewDlg::OnChangeEditGain()
{
// TODO: If this is a RICHEDIT control, the control will not
// send this notification unless you override the CDialog::OnInitDialog()
// function and call CRichEditCtrl().SetEventMask()
// with the ENM_CHANGE flag ORed into the mask.
// TODO: Add your control notification handler code here
UpdateData(TRUE);
SetGainVal(m_gain);
}
void CLiveViewDlg::OnChangeEditShutter()
{
// TODO: If this is a RICHEDIT control, the control will not
// send this notification unless you override the CDialog::OnInitDialog()
// function and call CRichEditCtrl().SetEventMask()
// with the ENM_CHANGE flag ORed into the mask.
// TODO: Add your control notification handler code here
UpdateData(TRUE);
SetShutterVal(m_shutter);
}
void CLiveViewDlg::OnChangeEditU()
{
// TODO: If this is a RICHEDIT control, the control will not
// send this notification unless you override the CDialog::OnInitDialog()
// function and call CRichEditCtrl().SetEventMask()
// with the ENM_CHANGE flag ORed into the mask.
// TODO: Add your control notification handler code here
UpdateData(TRUE);
SetUVal(m_u);
}
void CLiveViewDlg::OnChangeEditV()
{
// TODO: If this is a RICHEDIT control, the control will not
// send this notification unless you override the CDialog::OnInitDialog()
// function and call CRichEditCtrl().SetEventMask()
// with the ENM_CHANGE flag ORed into the mask.
// TODO: Add your control notification handler code here
UpdateData(TRUE);
SetVVal(m_v);
}
void CLiveViewDlg::InitGlobVar()
{
char lpValue[MAX_PATH];
memset(lpValue, 0, sizeof(lpValue));
::GetCurrentDirectory(sizeof(lpValue)-1, lpValue);
g_strCurPath = lpValue;
g_strINIFileName = g_strCurPath+"\\PickWaster.ini";
}
void CLiveViewDlg::GetParaFromIniFile()
{
//读取INI文件中的摄像机参数
//亮度
m_nBrightness = ::GetPrivateProfileInt("CAMERAPARA", "BRIGHTNESS", 128, g_strINIFileName);
//增溢
m_nGain = ::GetPrivateProfileInt("CAMERAPARA", "GAIN", 255, g_strINIFileName);
//快门
m_nShutter = ::GetPrivateProfileInt("CAMERAPARA", "SHUTTER", 20, g_strINIFileName);
//U
m_nU = ::GetPrivateProfileInt("CAMERAPARA", "U", 105, g_strINIFileName);
//V
m_nV = ::GetPrivateProfileInt("CAMERAPARA", "V", 68, g_strINIFileName);
}
void CLiveViewDlg::OnSavepara()
{
// TODO: Add your control notification handler code here
m_savePara=true;
CString brightness;
brightness.Format("%d", m_nBrightness);
::WritePrivateProfileString("CAMERAPARA", "BRIGHTNESS", brightness, g_strINIFileName);
CString gain;
gain.Format("%d", m_nGain);
::WritePrivateProfileString("CAMERAPARA", "GAIN", gain, g_strINIFileName);
CString shutter;
shutter.Format("%d", m_nShutter);
::WritePrivateProfileString("CAMERAPARA", "SHUTTER", shutter, g_strINIFileName);
CString u;
u.Format("%d", m_nU);
::WritePrivateProfileString("CAMERAPARA", "U", u, g_strINIFileName);
CString v;
v.Format("%d", m_nV);
::WritePrivateProfileString("CAMERAPARA", "V", v, g_strINIFileName);
MessageBox("摄象机参数保存完毕!");
}
void CLiveViewDlg::OnTimer(UINT nIDEvent)
{
// TODO: Add your message handler code here and/or call default
switch(nIDEvent)
{
case ID_TIMER_DISPLAY:
{
double fps_acquired = 0;
double fps_displayed = 0;
GetFrameRate(fps_acquired, fps_displayed);
m_caprate=fps_acquired;
m_disprate=fps_displayed;
m_lostframe=m_nLostFrame;
UpdateData(FALSE);
break;
}
default:
break;
}
CDialog::OnTimer(nIDEvent);
}
void CLiveViewDlg::GetFrameRate(double &acquired, double &displayed)
{
assert ( m_LiveGrabbing );
double avg = m_AcquisitionAvg.Avg();
acquired = avg == 0 ? 0.0 : 1.0 / avg;
avg = m_DisplayAvg.Avg();
displayed = avg == 0 ? 0.0 : 1.0 / avg;
m_AcquisitionAvg.Reset();
m_DisplayAvg.Reset();
}
void CLiveViewDlg::OnGrabsingle()
{
try
{
// TODO: Add your control notification handler code here
if(CBcam::DeviceNames().size() == 0)
{
MessageBox("没有检测到Basler摄像机", _T("错误"), MB_OK | MB_ICONEXCLAMATION);
return;
}
CString DeviceName = *(CBcam::DeviceNames().begin());
TRACE(_T("Devicename = %s\n"), DeviceName);
m_Bcam.Open( DeviceName );
m_bConnectBcam = true;
// 设定摄像机采集的图像格式,Format7,mode0,单色。
//Format7,Mode0是摄像机开发商自定义的工作模式,对A101f即是1300*1030*12FPS
const DCSVideoFormat VideoFormat = DCS_Format7;
const DCSVideoMode VideoMode = DCS_Mode0;
m_ColorCode = DCSColor_Raw8;
m_Bcam.SetVideoMode(VideoFormat, VideoMode);
m_Bcam.FormatSeven[VideoMode].ColorCoding = m_ColorCode;
m_ImageSize.cx = m_ImageSize.cx & ~3;
CPoint AoiPosition(0);
CSize AoiSize(m_ImageSize);
m_Bcam.FormatSeven[VideoMode].Position = AoiPosition;
m_Bcam.FormatSeven[VideoMode].Size = AoiSize;
unsigned long BytePerPacketMax = m_Bcam.FormatSeven[VideoMode].BytePerPacket.Max();
m_Bcam.FormatSeven[VideoMode].BytePerPacket = BytePerPacketMax;
m_Bcam.Brightness.Raw = m_nBrightness ;
m_Bcam.Gain.Raw = m_nGain ;
m_Bcam.Shutter.Raw = m_nShutter;
// m_pDispSingle = new BYTE[m_ImageSize.cx*m_ImageSize.cy*3];
// m_pSingleBitmap = new char[m_ImageSize.cx * m_ImageSize.cy];
m_Bcam.AllocateResources(1, AoiSize.cx * AoiSize.cy );
m_Bcam.GrabImage(m_pSingleBitmap, AoiSize.cx * AoiSize.cy, INFINITE, true);
m_pBCameraSet->ConvertBitmap(m_pDispSingle, (PBYTE)m_pSingleBitmap, m_ImageSize) ;
if(m_colortest)
{
SetDIBitsToDevice(m_display.GetDC()->m_hDC,0, 0,
m_ImageSize.cx, m_ImageSize.cy,
0, 0,
0, m_ImageSize.cy, m_pDispSingle,
m_ptrBmpInfo, DIB_RGB_COLORS);
}
m_Bcam.Cancel();// 停止I/O请求
m_Bcam.FreeResources();//释放在BCAM中建立的资源
m_Bcam.Close();// 关闭BCAM对象
}
CATCH_MSGBOX( "LiveViewDlg::OnGrabsingle" )
}
void CLiveViewDlg::OnLButtonDown(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
CRect rect,rect1;
CPoint pt = point;
ClientToScreen(&pt);
m_display.GetWindowRect(&rect);
m_local.GetWindowRect(&rect1);
if (rect.PtInRect(pt) && (nFlags&MK_LBUTTON))
{
if(SetSelect==COLORSELECT)
{
m_display.ScreenToClient(&pt);
m_Rect.left = pt.x;
m_Rect.top = pt.y;
m_Rect.right = pt.x+1;
m_Rect.bottom = pt.y+1;
RGBTRIPLE*p1=(RGBTRIPLE*)m_pDispSingle;
// m_robotnum=(p1+pt.x+(479-pt.y)*640)->rgbtRed;
// m_leftvalue=(p1+pt.x+(479-pt.y)*640)->rgbtGreen;
// m_rightvalue=(p1+pt.x+(479-pt.y)*640)->rgbtBlue;
// UpdateData(false);
//------测试时给出的定点坐标-----------------//
Gotopoint.x=ground.groundInfo[pt.x][pt.y].x;
Gotopoint.y=180-ground.groundInfo[pt.x][pt.y].y;
//-----------------------------------------------//
CDC* pDC=m_display.GetDC();
pDC->SetROP2(R2_NOTXORPEN);
CPen newPen(PS_SOLID,1,RGB(255,0,0));
CPen* oldPen=pDC->SelectObject(&newPen);
pDC->MoveTo(m_Rect.left,m_Rect.top);
pDC->LineTo(m_Rect.right,m_Rect.top);
pDC->LineTo(m_Rect.right,m_Rect.bottom);
pDC->LineTo(m_Rect.left,m_Rect.bottom);
pDC->LineTo(m_Rect.left,m_Rect.top);
ReleaseDC(pDC);
}
else if(SetSelect==BOUNDSET)
{
m_display.ScreenToClient(&pt);
CDC* pDC=m_display.GetDC();
///记录四个先验点///
TempSelect[SelectCount].x=pt.x;
TempSelect[SelectCount].y=pt.y;
pDC->FillSolidRect(pt.x,pt.y-1,3,3,RGB(255,0,0));
SelectCount++;
if(SelectCount==6)
SelectCount=0;
ReleaseDC(pDC);
}
}
else if(rect1.PtInRect(pt) && (nFlags&MK_LBUTTON)) //在放大框1内选点
{
if(SetSelect==COLORSELECT)
{
UpdateData();
if(m_SelectRect)
{
m_local.ScreenToClient(&pt);
m_Rect1.left = pt.x;
m_Rect1.top = pt.y;
m_Rect1.right = pt.x+1;
m_Rect1.bottom = pt.y+1;
CDC* pDC=m_local.GetDC();
pDC->SetROP2(R2_NOTXORPEN);
CPen newPen(PS_SOLID,1,RGB(255,0,0));
CPen* oldPen=pDC->SelectObject(&newPen);
pDC->MoveTo(m_Rect1.left,m_Rect1.top);
pDC->LineTo(m_Rect1.right,m_Rect1.top);
pDC->LineTo(m_Rect1.right,m_Rect1.bottom);
pDC->LineTo(m_Rect1.left,m_Rect1.bottom);
pDC->LineTo(m_Rect1.left,m_Rect1.top);
ReleaseDC(pDC);
}
else
{
m_local.ScreenToClient(&pt);
CDC* pDC=m_local.GetDC();
LocalPoint[PointCount].x=pt.x;
LocalPoint[PointCount].y=pt.y;
pDC->FillSolidRect(pt.x,pt.y-1,3,3,RGB(255,0,0));
PointCount++;
if(PointCount>10) MessageBox("不能超过十个点","警告");
ReleaseDC(pDC);
}
}
}
CDialog::OnLButtonDown(nFlags, point);
}
void CLiveViewDlg::OnRadioColorselect()
{
// TODO: Add your control notification handler code here
SetSelect=COLORSELECT;
}
void CLiveViewDlg::OnRadioBoundset()
{
// TODO: Add your control notification handler code here
SetSelect=BOUNDSET;
SelectCount=0;
}
void CLiveViewDlg::OnMouseMove(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
CRect rect,rect1;
CPoint pt = point;
ClientToScreen(&pt);
m_display.GetWindowRect(&rect);
m_local.GetWindowRect(&rect1);
if (rect.PtInRect(pt) && (nFlags&MK_LBUTTON)) {
if(SetSelect==COLORSELECT){
CDC* pDC=m_display.GetDC();
pDC->SetROP2(R2_NOTXORPEN);
CPen newPen(PS_SOLID,1,RGB(255,0,0));
CPen* oldPen=pDC->SelectObject(&newPen);
pDC->MoveTo(m_Rect.left,m_Rect.top);
pDC->LineTo(m_Rect.right,m_Rect.top);
pDC->LineTo(m_Rect.right,m_Rect.bottom);
pDC->LineTo(m_Rect.left,m_Rect.bottom);
pDC->LineTo(m_Rect.left,m_Rect.top);
m_display.ScreenToClient(&pt);
m_Rect.right = pt.x;
m_Rect.bottom = pt.y;
pDC->MoveTo(m_Rect.left,m_Rect.top);
pDC->LineTo(m_Rect.right,m_Rect.top);
pDC->LineTo(m_Rect.right,m_Rect.bottom);
pDC->LineTo(m_Rect.left,m_Rect.bottom);
pDC->LineTo(m_Rect.left,m_Rect.top);
pDC->SelectObject(oldPen);
ReleaseDC(pDC);
}
}
else if(rect1.PtInRect(pt) && (nFlags&MK_LBUTTON)&&m_SelectRect) {
if(SetSelect==COLORSELECT){
CDC* pDC=m_local.GetDC();
pDC->SetROP2(R2_NOTXORPEN);
CPen newPen(PS_SOLID,1,RGB(255,0,0));
CPen* oldPen=pDC->SelectObject(&newPen);
pDC->MoveTo(m_Rect1.left,m_Rect1.top);
pDC->LineTo(m_Rect1.right,m_Rect1.top);
pDC->LineTo(m_Rect1.right,m_Rect1.bottom);
pDC->LineTo(m_Rect1.left,m_Rect1.bottom);
pDC->LineTo(m_Rect1.left,m_Rect1.top);
m_local.ScreenToClient(&pt);
m_Rect1.right = pt.x;
m_Rect1.bottom = pt.y;
pDC->MoveTo(m_Rect1.left,m_Rect1.top);
pDC->LineTo(m_Rect1.right,m_Rect1.top);
pDC->LineTo(m_Rect1.right,m_Rect1.bottom);
pDC->LineTo(m_Rect1.left,m_Rect1.bottom);
pDC->LineTo(m_Rect1.left,m_Rect1.top);
pDC->SelectObject(oldPen);
ReleaseDC(pDC);
}
}
CDialog::OnMouseMove(nFlags, point);
}
void CLiveViewDlg::OnBoundset()
{
// TODO: Add your control notification handler code here
ground.LeftTop=TempSelect[0];
ground.GateLeftTop=TempSelect[1];
ground.RightBottom=TempSelect[2];
ground.GateRightBottom=TempSelect[3];
ground.Center.x = (ground.LeftTop.x+ground.GateLeftTop.x+ground.GateRightBottom.x+ground.RightBottom.x)/4;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -