📄 liveviewdlg.cpp
字号:
ground.Center.y = (ground.LeftTop.y+ground.GateLeftTop.y+ground.GateRightBottom.y+ground.RightBottom.y)/4;
destDC.FillSolidRect(0,0,640,480,RGB(255,255,255));
CPen redPen;
redPen.CreatePen(PS_SOLID,1,RGB(255,0,0));
destDC.SelectObject(&redPen);
CPoint point[13];
point[0].x=320-75;point[0].y=240-65;
point[1].x=320+75;point[1].y=240-65;
point[2].x=320+75;point[2].y=240-20;
point[3].x=320+85;point[3].y=240-20;
point[4].x=320+85;point[4].y=240+20;
point[5].x=320+75;point[5].y=240+20;
point[6].x=320+75;point[6].y=240+65;
point[7].x=320-75;point[7].y=240+65;
point[8].x=320-75;point[8].y=240+20;
point[9].x=320-85;point[9].y=240+20;
point[10].x=320-85;point[10].y=240-20;
point[11].x=320-75;point[11].y=240-20;
point[12].x=320-75;point[12].y=240-65;
CRgn rgn;
CDC* pDC = m_display.GetDC();
rgn.CreatePolygonRgn(point,13,WINDING);
double MX,MX1,MX2, MY,MY1,MY2;
MX1 = (double(ground.RightBottom.x-ground.LeftTop.x))/150;
MX2 = (double(ground.GateRightBottom.x-ground.GateLeftTop.x))/150;
MX = (double(MX1+MX2))/2;
MY1 = (double(ground.RightBottom.y-ground.LeftTop.y))/130;
MY2 = (double(TempSelect[5].y-TempSelect[4].y))/130;
MY = (double(MY1+MY2))/2;
int x1,y1;
for(int j=0;j<480;j++)
for(int i=0;i<640;i++)
{
x1 = i - ground.Center.x;
y1 = j - ground.Center.y;
ground.groundInfo[i][j].x=(int)(x1/MX)+75;
ground.groundInfo[i][j].y=(int)(y1/MY)+65;
COLORREF color=pDC->GetPixel(i,j);
destDC.SetPixel((int)(x1/MX)+320,(int)(y1/MY)+240,color);
if(rgn.PtInRegion((int)(x1/MX)+320,(int)(y1/MY)+240))
ground.groundInfo[i][j].flag=1;
else
ground.groundInfo[i][j].flag=0;
}
destDC.Polyline( point, 13 );
//ground.M=M;
//ground.E=E;
pDC->StretchBlt(0,0,640,480,&destDC,0,0,640,480,SRCCOPY);
ReleaseDC(pDC);
MessageBox("边界校正结束!","边界校正");
}
void CLiveViewDlg::OnLoad()
{
// TODO: Add your control notification handler code here
CFileDialog dlg(TRUE,"dat","Ground.dat");
if(dlg.DoModal()==IDOK){
int i;
CString str1;
CString str(dlg.GetPathName());
i=str.GetLength();
while(str.GetAt(i-1)!='\\') i--;
PathName=str.Left(i);
FILE* stream;
str1=PathName+"Ground.dat";
stream=fopen(str1,"a+");
stream=fopen(str1,"rb+");
fseek( stream, 0L, SEEK_SET);
fread(&ground,sizeof(Ground),1,stream);
fclose(stream);
str1=PathName+"Object.dat";
stream=fopen(str1,"a+");
stream=fopen(str1,"rb+");
fseek( stream, 0L, SEEK_SET);
fread(&m_LUT[0][0],sizeof(int),7*0x8000,stream);
fread(&ObjectColor,sizeof(COLORREF),7,stream);
fclose(stream);
for( i=0;i<7;i++)
{
CDC* pDC=GetStaticDC(i);
pDC->FillSolidRect(0,0,25,23,ObjectColor[i]);
ReleaseDC(pDC);
}
m_save.EnableWindow(true);
}
}
CDC* CLiveViewDlg::GetStaticDC(int Object)
{
CDC* pDC;
switch(Object)
{
case 0:
pDC=m_steam.GetDC();
break;
case 1:
pDC=m_smem1.GetDC();
break;
case 2:
pDC=m_smem2.GetDC();
break;
case 3:
pDC=m_smem3.GetDC();
break;
case 4:
pDC=m_smem4.GetDC();
break;
case 5:
pDC=m_smem5.GetDC();
break;
case 6:
pDC=m_sball.GetDC();
break;
}
return pDC;
}
void CLiveViewDlg::OnSave()
{
// TODO: Add your control notification handler code here
FILE* stream;
CString str;
str=PathName+"Ground.dat";
stream=fopen(str,"a+");
stream=fopen(str,"rb+");
fseek( stream, 0L, SEEK_SET);
fwrite(&ground,sizeof(Ground),1,stream);
fclose(stream);
str=PathName+"Object.dat";
stream=fopen(str,"a+");
stream=fopen(str,"rb+");
fseek( stream, 0L, SEEK_SET);
fwrite(&m_LUT[0][0],sizeof(int),7*0x8000,stream);
fwrite(&ObjectColor,sizeof(COLORREF),7,stream);
fclose(stream);
AfxMessageBox("颜色保存结束");
}
void CLiveViewDlg::OnSaveas()
{
// TODO: Add your control notification handler code here
CFileDialog dlg(FALSE,"dat","Ground.dat.dat");
if(dlg.DoModal()==IDOK){
int i;
CString str1;
CString str(dlg.GetPathName());
i=str.GetLength();
while(str.GetAt(i-1)!='\\') i--;
PathName=str.Left(i);
FILE* stream;
str1=PathName+"Ground.dat";
stream=fopen(str1,"a+");
stream=fopen(str1,"rb+");
fseek( stream, 0L, SEEK_SET);
fwrite(&ground,sizeof(Ground),1,stream);
fclose(stream);
str1=PathName+"Object.dat";
stream=fopen(str1,"a+");
stream=fopen(str1,"rb+");
fseek( stream, 0L, SEEK_SET);
fwrite(&m_LUT[0][0],sizeof(int),7*0x8000,stream);
fwrite(&ObjectColor,sizeof(COLORREF),7,stream);
fclose(stream);
AfxMessageBox("颜色另存结束");
}
}
void CLiveViewDlg::OnColorsampling()
{
// TODO: Add your control notification handler code here
UpdateData();
if(SetSelect==COLORSELECT)
{
if(m_object==-1)
{
MessageBox("请选择一个我方对象!","警告",MB_ICONWARNING);
return;
}
CString str;
switch(m_object)
{
case 0:
str="您选择的是我方队标!";
break;
case 1:
str="您选择的是我方队员1!";
break;
case 2:
str="您选择的是我方队员2!";
break;
case 3:
str="您选择的是我方队员3!";
break;
case 4:
str="您选择的是我方队员4!";
break;
case 5:
str="您选择的是我方队员5!";
break;
case 6:
str="您选择的是球!";
break;
}
if(AfxMessageBox(str,MB_OKCANCEL)==IDCANCEL)
return;
ColorAnalyse();
CDC* pDC=GetStaticDC(m_object);
pDC->FillSolidRect(0,0,25,23,ObjectColor[m_object]);
ReleaseDC(pDC);
}
}
void CLiveViewDlg::ColorAnalyse()
{
int i,j,r1,g1,b1;
int m,n;
int r,g,b,R,G,B,data;
RGBTRIPLE *pStart=(RGBTRIPLE *)m_pDispSingle;
r1=g1=b1=1;
if(m_nesample) r1=g1=b1=0;
for (j=m_Rect.top+1; j<m_Rect.bottom-1;j++) {
for (i=m_Rect.left+1; i<m_Rect.right-1; i++) {
R=((pStart+i+(479-j)*640)->rgbtRed)/8;//(i,j)对应的象素的R,G,B值,均为一个字节表示
G=((pStart+i+(479-j)*640)->rgbtGreen)/8;
B=((pStart+i+(479-j)*640)->rgbtBlue)/8;
for (r=R-r1; r<=R+r1; r++)
for (g=G-g1; g<=G+g1; g++)
for (b=B-b1; b<=B+b1; b++) {
data = (r&0x1f)<<10|(g&0x1f)<<5|(b&0x1f);
m_LUT[m_object][data] = 1;
}
}
}
n=(m_Rect.top+m_Rect.bottom)/2;
m=(m_Rect.left+m_Rect.right)/2;
ObjectColor[m_object]=RGB((pStart+m+(479-n)*640)->rgbtRed,(pStart+m+(479-n)*640)->rgbtGreen,(pStart+m+(479-n)*640)->rgbtBlue);
}
void CLiveViewDlg::OnColortest()
{
// TODO: Add your control notification handler code here
UpdateData();
if(m_object==-1)
{
MessageBox("请选择一个我方对象!","警告",MB_ICONWARNING);
return;
}
m_colortest=false;
CLiveViewDlg::OnGrabsingle();
PBYTE m_pTestBitmap;
m_pTestBitmap = new BYTE[m_ImageSize.cx*m_ImageSize.cy*3];
RGBTRIPLE *pSingle=(RGBTRIPLE *)m_pDispSingle;
RGBTRIPLE *pTest=(RGBTRIPLE *)m_pTestBitmap;
int i,j,r,g,b,data;
for (j=0; j<480; j++)
for (i=0; i<640; i++) {
r=(pSingle+i+(479-j)*640)->rgbtRed/8;
g=(pSingle+i+(479-j)*640)->rgbtGreen/8;
b=(pSingle+i+(479-j)*640)->rgbtBlue/8;
data= (r&0x1f)<<10|(g&0x1f)<<5|(b&0x1f);
if (m_LUT[m_object][data&0x7fff])
{
(pTest+i+(479-j)*640)->rgbtRed=(pSingle+i+(479-j)*640)->rgbtRed;
(pTest+i+(479-j)*640)->rgbtGreen=(pSingle+i+(479-j)*640)->rgbtGreen;
(pTest+i+(479-j)*640)->rgbtBlue=(pSingle+i+(479-j)*640)->rgbtBlue;
}
else
{
(pTest+i+(479-j)*640)->rgbtRed=255;
(pTest+i+(479-j)*640)->rgbtGreen=255;
(pTest+i+(479-j)*640)->rgbtBlue=255;
}
}
SetDIBitsToDevice(m_display.GetDC()->m_hDC,0, 0,
m_ImageSize.cx, m_ImageSize.cy,
0, 0,
0, m_ImageSize.cy, m_pTestBitmap,
m_ptrBmpInfo, DIB_RGB_COLORS);
m_colortest=true;
}
void CLiveViewDlg::OnColorfilter()
{
// TODO: Add your control notification handler code here
UpdateData();
if(SetSelect==COLORSELECT)
{
if(m_object==-1)
{
MessageBox("请选择我方一个对象!","警告",MB_ICONWARNING);
return;
}
Filter();
}
}
void CLiveViewDlg::Filter()
{
int i,j;
int r,g,b,R,G,B,data;
int r1,g1,b1;
r1=g1=b1=1;
if(m_nefilter) r1=g1=b1=0;
RGBTRIPLE *pStart=(RGBTRIPLE *)m_pDispSingle;
for (j=m_Rect.top+1; j<m_Rect.bottom-1; j++)
{
for (i=m_Rect.left+1; i<m_Rect.right-1; i++)
{
R=((pStart+i+(479-j)*640)->rgbtRed)/8;//(i,j)对应的象素的R,G,B值,均为一个字节表示
G=((pStart+i+(479-j)*640)->rgbtGreen)/8;
B=((pStart+i+(479-j)*640)->rgbtBlue)/8;
for (r=R-r1; r<=R+r1; r++)
for (g=G-g1; g<=G+g1; g++)
for (b=B-b1; b<=B+b1; b++)
{
data = (r&0x1f)<<10|(g&0x1f)<<5|(b&0x1f);
m_LUT[m_object][data] = 0;
}
}
}
}
void CLiveViewDlg::OnClear()
{
// TODO: Add your control notification handler code here
UpdateData();
if(m_object==-1)
{
MessageBox("请选择一个我方对象!","警告",MB_ICONWARNING);
return;
}
if(m_object>=0)
{
for(int i=0;i<0x8000;i++)
{
m_LUT[m_object][i]=0;
}
}
ObjectColor[m_object]=RGB(212,208,200);
CDC* pDC=GetStaticDC(m_object);
pDC->FillSolidRect(0,0,25,23,ObjectColor[m_object]);
ReleaseDC(pDC);
}
void CLiveViewDlg::OnIdentifytest()
{
// TODO: Add your control notification handler code here
try
{
if(CBcam::DeviceNames().size() == 0)// 检测摄像机是否存在
{
MessageBox("没有检测到Basler摄像机", _T("错误"), MB_OK | MB_ICONEXCLAMATION);
return;
}
CString DeviceName = *(CBcam::DeviceNames().begin());// 得到本PC连接的第一台摄像机的名字
TRACE(_T("Devicename = %s\n"), DeviceName);
m_Bcam.Open( DeviceName );// 打开第一台摄像机
m_bConnectBcam = true;
const DCSVideoFormat VideoFormat = DCS_Format7;// 设定摄像机采集的图像格式,Format7,mode0,单色。Format7,Mode0是摄像机开发商自定义的工作模式,对A101f即是1300*1030*12FPS
const DCSVideoMode VideoMode = DCS_Mode0;
m_ColorCode = DCSColor_Raw8;
m_Bcam.SetVideoMode(VideoFormat, VideoMode);
m_Bcam.FormatSeven[VideoMode].ColorCoding = m_ColorCode;
// 注意: bitmap要求宽度是4的倍数,即DWORD对齐 :-(
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_Bcam.WhiteBalance.Raw.UBValue.SetAsync(m_nU);
m_Bcam.WhiteBalance.Raw.VRValue.SetAsync(m_nV);
m_pDispBitmap = new BYTE[m_ImageSize.cx*m_ImageSize.cy*3];
m_pBitmap=NULL;
for(int i=0; i<NUM_BUFFERS; ++i) // 为多缓冲区分配资源
m_ptrBitmaps[i] = new char[m_ImageSize.cx * m_ImageSize.cy];
m_Bcam.AllocateResources(NUM_BUFFERS, AoiSize.cx * AoiSize.cy );// 在BCAM中建立内存
m_test=TRUE;
m_stop=true;
UpdateData();
if ( ! m_GrabThread.Create(&GrabThreadProc, this, THREAD_PRIORITY_HIGHEST) )
{
throw BcamException(::GetLastError(), "CLiveViewDlg::OnCamLive : Create Grab Thread");
}
if ( ! m_DispThread.Create(&DispThreadProc, this, THREAD_PRIORITY_HIGHEST) )
{
throw BcamException(::GetLastError(), "CLiveViewDlg::OnCamLive : Create Grab Thread");
}
// 设定标记,表示采集开始了
m_LiveGrabbing = true;
m_bIsDispImage = FALSE;
m_bOCROk = true;
m_nLostFrame = 0;
// 将多缓冲区同步采集指令顺序排入队列
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -