📄 videocaptureview.cpp
字号:
if (ZDJC) {
if (m_hDib[0][0][0]) {
DrawDIB(dc.m_hDC,m_hDib[thisBlockNum][0][0],rectImage.left,rectImage.top,rectImage.Width(),rectImage.Height());
}
}
if (!ZDJC) {
if (m_hDib[thisBlockNum][0][1]) {
DrawDIB(dc.m_hDC,m_hDib[thisBlockNum][0][1],rectImage.left,rectImage.top,rectImage.Width()/2-2,rectImage.Height()/2-2);
}
if (m_hDib[thisBlockNum][0][0]) {
DrawDIB(dc.m_hDC,m_hDib[thisBlockNum][0][0],rectImage.left+2+rectImage.Width()/2,rectImage.top,rectImage.Width()/2-2,rectImage.Height()/2-2);
}
if (m_hDib[thisBlockNum][1][0]) {
DrawDIB(dc.m_hDC,m_hDib[thisBlockNum][1][0],rectImage.left,rectImage.top+2+rectImage.Height()/2,rectImage.Width()/2-2,rectImage.Height()/2-2);
}
if (m_hDib[thisBlockNum][2][0]) {
DrawDIB(dc.m_hDC,m_hDib[thisBlockNum][2][0],rectImage.left+2+rectImage.Width()/2,rectImage.top+2+rectImage.Height()/2,rectImage.Width()/2-2,rectImage.Height()/2-2);
}
}
// Do not call CFormView::OnPaint() for painting messages
}
BEGIN_EVENTSINK_MAP(CVideoCaptureView, CFormView)
//{{AFX_EVENTSINK_MAP(CVideoCaptureView)
ON_EVENT(CVideoCaptureView, IDC_MSCOMM_SPEED, 1 /* OnComm */, OnOnCommMscommSpeed, VTS_NONE)
//}}AFX_EVENTSINK_MAP
END_EVENTSINK_MAP()
void CVideoCaptureView::OnOnCommMscommSpeed()
{
m_fCanGetSpeed=FALSE;
if(!m_Comm.GetPortOpen())
return;
if(m_Comm.GetCommEvent()==2) //事件值为2表示接收缓冲区内有字符
{
GetComData();
//}
//::SafeArrayDestroyData( &safearray_inp);
}
m_fCanGetSpeed=TRUE;
}
/***-------------------------------------------------------------------------
抓拍图像,
同时保存到数据库热record表中。
-------------------------------------------------------------------------***/
CString CVideoCaptureView::Capture(int targetSpeed,int fastSpeed,int lockSpeed, int MaxSpeed,BOOL SaveToDB,int MemoryBlock)
{
if (MemoryBlock>3 || MemoryBlock<0) return "BlockNumError";
if(!MemoryStatus[MemoryBlock])//1 可用
{
for(int i=0;i<4;i++)
{
if (MemoryStatus[i])
{
break;
}
}
if(i>=4)
return "MemoryIsFull";
else{
MemoryBlock=i;
}
}
if( m_nThisBmpNum<2)
{
for(int i=0;i<6;i++)
{
GlobalFree(m_hDib[MemoryBlock][i][0]);
m_hDib[MemoryBlock][i][0]=NULL;
GlobalFree(m_hDib[MemoryBlock][i][1]);
m_hDib[MemoryBlock][i][1]=NULL;
}
}
//保存名字清零
thisBlockNum=MemoryBlock;
if(m_nThisBmpNum==1){
m_szSeveralBMP[MemoryBlock][0]="";
m_szSeveralBMP[MemoryBlock][1]="";
for(int i=0;i<6;i++){
FileName[MemoryBlock][i][0]="";
FileName[MemoryBlock][i][1]="";
}
}
CRect rect;
GetDlgItem(IDC_STATIC_CK)->GetWindowRect(&rect);
ScreenToClient(&rect);
//抓拍特写(3张)
PBYTE p=new BYTE[768*576*3+54];
PBYTE pl;
int* pa=m_VC.Capture(p, 2, TRUE,10);
try{
if (pa) {
m_hDib[MemoryBlock][m_nThisBmpNum-1][0] = (HDIB)GlobalAlloc(GMEM_FIXED,768*576*3+40);
pl= (PBYTE)GlobalLock(m_hDib[MemoryBlock][m_nThisBmpNum-1][0]);
memcpy(pl,p+14,768*576*3+40);
GlobalUnlock(m_hDib[MemoryBlock][m_nThisBmpNum-1][0]);
CDC* pDC=GetDC();
if (!ZDJC) {
switch(m_nThisBmpNum) {
case 1:
m_VC.DrawImage(p,pDC->m_hDC,rectImage.left+2+rectImage.Width()/2,rectImage.top,rectImage.Width()/2-2,rectImage.Height()/2-2);
break;
case 2:
m_VC.DrawImage(p,pDC->m_hDC,rectImage.left,rectImage.top+2+rectImage.Height()/2,rectImage.Width()/2-2,rectImage.Height()/2-2);
break;
default:
m_VC.DrawImage(p,pDC->m_hDC,rectImage.left+2+rectImage.Width()/2,rectImage.top+2+rectImage.Height()/2,rectImage.Width()/2-2,rectImage.Height()/2-2);
}
}else
{
m_VC.DrawImage(p,pDC->m_hDC,rect.left+1+rect.Width()/2,rect.top+10,rect.Width()/2-4,rect.Height()-16);
}
ReleaseDC(pDC);
}else{
delete[] p;
p=NULL;
WriteLog("特写抓拍失败");
if (m_nThisBmpNum<m_nNumBmp)
return "TXError";
}
}catch (...) {
try{
if (p) {
delete[] p;
}
}catch(...){
WriteLog("特写抓拍失败 delete p");
}
WriteLog("try特写抓拍失败");
if (m_nThisBmpNum<m_nNumBmp)
return "TXError";
}
delete[] p;
//抓拍全景(1张)
try{
if(m_nThisBmpNum==1){
p=new BYTE[768*576*3+54];
if (pa) {
pa=m_VC.Capture(p, 1, TRUE,10);
m_hDib[MemoryBlock][m_nThisBmpNum-1][1] = (HDIB)GlobalAlloc(GMEM_FIXED,768*576*3+40);
pl= (PBYTE)GlobalLock(m_hDib[MemoryBlock][m_nThisBmpNum-1][1]);
memcpy(pl,p+14,768*576*3+40);
GlobalUnlock(m_hDib[MemoryBlock][m_nThisBmpNum-1][1]);
CDC* pDC=GetDC();
if (!ZDJC) {
m_VC.DrawImage(p,pDC->m_hDC,rectImage.left,rectImage.top,rectImage.Width()/2-2,rectImage.Height()/2-2);
}else
{
m_VC.DrawImage(p,pDC->m_hDC,rect.left+2,rect.top+10,rect.Width()/2-4,rect.Height()-16);
}
ReleaseDC(pDC);
}else{
delete[] p;
WriteLog("全景抓拍失败");
if (m_nThisBmpNum<m_nNumBmp)
return "QJError";
}
delete[] p;
}
}catch (...) {
try{
if (p) {
delete[] p;
}
}catch(...){
WriteLog("全景抓拍失败 delete p");
}
WriteLog("全景抓拍失败");
if (m_nThisBmpNum<m_nNumBmp)
return "TXError";
}
if(m_hDib[MemoryBlock][m_nThisBmpNum-1][0] && m_hDib[MemoryBlock][0][1])
{
COleDateTime tm=COleDateTime::GetCurrentTime();
CString str,tmpStr;
str.Format("%d-%d-%d %d:%d:%d",tm.GetYear(),tm.GetMonth(),tm.GetDay(),tm.GetHour(),tm.GetMinute(),tm.GetSecond());
tmpStr=str;
CString FileName1,FileName2;
DWORD a=GetTickCount();
if(m_JPG)
{
FileName1.Format("%d%d%d%d%d%dB%ld#%d.jpg",tm.GetYear(),tm.GetMonth(),tm.GetDay(),tm.GetHour(),tm.GetMinute(),tm.GetSecond(),a,m_nThisBmpNum);
FileName2.Format("%d%d%d%d%d%dP%ld#%d.jpg",tm.GetYear(),tm.GetMonth(),tm.GetDay(),tm.GetHour(),tm.GetMinute(),tm.GetSecond(),a,m_nThisBmpNum);
}
else{
FileName1.Format("%d%d%d%d%d%dB%ld#%d.bmp",tm.GetYear(),tm.GetMonth(),tm.GetDay(),tm.GetHour(),tm.GetMinute(),tm.GetSecond(),a,m_nThisBmpNum);
FileName2.Format("%d%d%d%d%d%dP%ld#%d.bmp",tm.GetYear(),tm.GetMonth(),tm.GetDay(),tm.GetHour(),tm.GetMinute(),tm.GetSecond(),a,m_nThisBmpNum);
}
FileName[MemoryBlock][m_nThisBmpNum-1][0]=FileName1;
//为山东特别处理,只抓一张全景
if (FileName[MemoryBlock][0][1]=="") {
FileName[MemoryBlock][0][1]=FileName2;
}
// targetSpeed=90;
/************************************************************************/
/* //图片文字添加 */
/************************************************************************/
CString sBMPText;
CString sWZBH='0000';
// targetSpeed=50;
sBMPText.Format("时间:%s,车速:%dkm/h,限速:%dkm/h",tmpStr,targetSpeed,m_iSpeed);
//车速/超速百分比/违章时间/违章地点
if(targetSpeed>MaxSpeed&&targetSpeed&&MaxSpeed){
int m_bfb;
m_bfb=(targetSpeed-MaxSpeed)*100/MaxSpeed;
tmpStr.Format("超速:%d%%",m_bfb);
if (m_bfb<=50) {
sWZBH="1303";
}
else{
sWZBH="1603";
}
sBMPText=sBMPText+","+tmpStr;
if (m_bSaveWeizhang) {
tmpStr="违法类型:超速行驶";
sBMPText=sBMPText+","+tmpStr;
}
}
BmpText[MemoryBlock][m_nThisBmpNum-1]=sBMPText;
/************************************************************************/
m_iTiggerTargetSpeed=targetSpeed;
m_iTiggerLockSpeed=lockSpeed;
m_iTiggerFastSpeed=fastSpeed;
if(m_szSeveralBMP[MemoryBlock][0]=="")
m_szSeveralBMP[MemoryBlock][0]=DataPath+"\\"+ FileName1;
else
m_szSeveralBMP[MemoryBlock][0]=m_szSeveralBMP[MemoryBlock][0]+","+DataPath+"\\"+ FileName1;
//全景只有一张,所以只保留一个名字
if(m_szSeveralBMP[MemoryBlock][1]=="")
m_szSeveralBMP[MemoryBlock][1]=DataPath+"\\"+ FileName2;
if(m_nThisBmpNum+1>m_nNumBmp)//m_nThisBmpNum)
{
CString sql,date;
//如果特写抓拍成功,则保存
if(m_szSeveralBMP[MemoryBlock][0] !="" )
{
COleDateTime tm=COleDateTime::GetCurrentTime();
date.Format("%d-%d-%d %d:%d:%d",tm.GetYear(),tm.GetMonth(),tm.GetDay(),tm.GetHour(),tm.GetMinute(),tm.GetSecond());
CString status="";
if (date!="")
{
if (SaveToDB)
{
CString stationName;
// if(m_bSaveStation)//如果选择默认地点路段则 写到数据库中
stationName=m_stationName;
// else stationname="";
CString license=GetLicense(m_hDib[MemoryBlock][m_nThisBmpNum-1][0]);
int XCXS=m_iSpeed;//小车限速
int DSXZ=0;//低速违章
if(m_bCapMinSpeed)
DSXZ=m_iSpeedDown;
if(m_bCapSmallCarSpeed)
XCXS=m_iSpeedUp;
if (m_iTiggerTargetSpeed>m_iSpeed)// || m_iTiggerLockSpeed>m_iSpeed || m_iTiggerFastSpeed>m_iSpeed)//超速自动抓拍
{
sql.Format("insert into record(XZQYDM,JQBH,WZSJ,WZDD,XLSD,MBSD,ZKSD,SDSD,XZSD,WZBH,bmp,HPHM,XSFX,XCXS,DSXZ,SPBJ,ZDJC) values('%s','%s','%s','%s',%d,%d,%d,%d,%d,'%s','%s','%s',%d,%d,%d,'0','0')",
m_szAddress,m_szMachineID,date,stationName,m_PoliceSpeed,m_iTiggerTargetSpeed,m_iTiggerFastSpeed,m_iTiggerLockSpeed,m_iSpeed,sWZBH,m_szSeveralBMP[MemoryBlock][1]+","+ m_szSeveralBMP[MemoryBlock][0],license,RadarStatus.driveway,XCXS,DSXZ);//,HPImage[MemoryBlock]);
}
else if ((m_iTiggerTargetSpeed<m_iSpeedDown) && (m_iTiggerTargetSpeed>20))//低速抓拍
{
sql.Format("insert into record(XZQYDM,JQBH,WZSJ,WZDD,XLSD,MBSD,ZKSD,SDSD,XZSD,WZBH,bmp,HPHM,XSFX,XCXS,DSXZ,SPBJ,ZDJC) values('%s','%s','%s','%s',%d,%d,%d,%d,%d,'%s','%s','%s',%d,%d,%d,'0','0')",
m_szAddress,m_szMachineID,date,stationName,m_PoliceSpeed,m_iTiggerTargetSpeed,m_iTiggerFastSpeed,m_iTiggerLockSpeed,m_iSpeed,sWZBH,m_szSeveralBMP[MemoryBlock][1]+","+m_szSeveralBMP[MemoryBlock][0],license,RadarStatus.driveway,XCXS,DSXZ);//,HPImage[MemoryBlock]);
}
else//手动抓拍等其他原因造成的捕捉
{
sql.Format("insert into record(XZQYDM,JQBH,WZSJ,WZDD,XLSD,MBSD,ZKSD,SDSD,XZSD,bmp,HPHM,XCXS,DSXZ,SPBJ,ZDJC) values('%s','%s','%s','%s',%d,%d,%d,%d,%d,'%s','%s',%d,%d,'0','0')",
m_szAddress,m_szMachineID,date,stationName,m_PoliceSpeed,m_iTiggerTargetSpeed,m_iTiggerFastSpeed,m_iTiggerLockSpeed,m_iSpeed,m_szSeveralBMP[MemoryBlock][1]+","+m_szSeveralBMP[MemoryBlock][0],license,XCXS,DSXZ);//,HPImage[MemoryBlock]);
}
try{
pConn->Execute(sql);
}catch (...) {
WriteLog("写数据库出错!");
}
InsertToList();//在主界面 列表控件上添加纪录
{
GetDlgItem(IDC_BTNIMAGECAP)->EnableWindow(TRUE);
m_nThisBmpNum=1;//pView->m_nThisBmpNum=0;
GetDlgItem(IDC_BTNIMAGECAP)->SetFocus();
}
if ( m_bSmallCar )
HPZL[MemoryBlock]=2;
else HPZL[MemoryBlock]=1;
///单独保存文件 线程;图片添加文字
THREADPARMS* ptp = new THREADPARMS;
ptp->DataPath = DataPath;
ptp->hWnd = m_hWnd;
ptp->XH = m_uSelectRecord;
for(int i=0;i<6;i++)
{
ptp->hDib[i][0] = NULL;
ptp->hDib[i][0] = m_hDib[MemoryBlock][i][0];
ptp->hDib[i][1] = NULL;
ptp->hDib[i][1] = m_hDib[MemoryBlock][i][1];
ptp->text[i] = BmpText[MemoryBlock][i];
ptp->FileName[i][0] = FileName[MemoryBlock][i][0];
ptp->FileName[i][1] = FileName[MemoryBlock][i][1];
ptp->station[i]="";
if (m_bSaveStation) {
ptp->station[i]=m_stationName;
}
}
ptp->m_JPG = m_JPG;
ptp->BlockNum = MemoryBlock;
ptp->m_JpgQuality = m_JpgQuality;
//添加大小车限速设置
ptp->ThisSpeed=targetSpeed;
if (m_bCapSmallCarSpeed)
ptp->SpeedUp=m_iSpeedUp;
else
ptp->SpeedUp=0;
ptp->bSPJC=false;
MemoryStatus[MemoryBlock]=FALSE;
AfxBeginThread(ThreadSave, ptp);
return m_szSeveralBMP[MemoryBlock][1] + "," + m_szSeveralBMP[MemoryBlock][0] ;
}
else
{
///单独保存文件 线程;图片添加文字
THREADPARMS* ptp = new THREADPARMS;
ptp->DataPath = DataPath;
ptp->hWnd = m_hWnd;
for(int ii=0;ii<6;ii++){
for (int j=0;j<2;j++)
{
ptp->hDib[ii][j] = NULL;
ptp->hDib[ii][j] = m_hDib[MemoryBlock][ii][j];
ptp->text[ii] = BmpText[MemoryBlock][ii];
ptp->FileName[ii][j] = FileName[MemoryBlock][ii][j];
if(m_bSaveWeizhang){
if ((m_iTiggerTargetSpeed>m_iSpeed))
ptp->station[ii] = "超速行驶";//m_stationName;
else
if ((m_iTiggerTargetSpeed<m_iSpeedDown) && (m_iTiggerTargetSpeed>20))
ptp->station[ii] = "低速行驶";//m_stationName;
else ptp->station[ii] = "---";
}
else ptp->station[ii] =m_stationName;
}
}
ptp->m_JPG = m_JPG;
ptp->BlockNum = MemoryBlock;
ptp->m_JpgQuality = m_JpgQuality;
//添加大小车限速设置
ptp->ThisSpeed=targetSpeed;
if (m_bCapSmallCarSpeed)
ptp->SpeedUp=m_iSpeedUp;
else
ptp->SpeedUp=0;
ptp->bSPJC=false;
MemoryStatus[MemoryBlock]=FALSE;
AfxBeginThread(ThreadSave, ptp);
return m_szSeveralBMP[MemoryBlock][1] + "," +m_szSeveralBMP[MemoryBlock][0];
}
}
}
}
else// if(m_nNumBmp<m_nThisBmpNum+1)//m_nThisBmpNum)
{
m_nThisBmpNum++;
Capture(targetSpeed,fastSpeed,lockSpeed,MaxSpeed,SaveToDB,MemoryBlock);
}
}
return "";
}
void CVideoCaptureView::OnUpdateCaptureJpg(CCmdUI* pCmdUI)
{
// pCmdUI->SetCheck(m_JPG==TRUE);
}
void CVideoCaptureView::OnCaptureVideo()
{
// Capture(m_OldTargetSpeed,m_OldLockSpeed,m_OldFastSpeed,m_iSpeed);
OnBtnimagecap();
}
void CVideoCaptureView::OnCaptureJpg()
{
// m_JPG=!m_JPG;
}
void CVideoCaptureView::OnImageCopy()
{
}
void CVideoCaptureView::OnCommOpen()
{
if(m_Comm.GetPortOpen())
{
// ComStopRec=TRUE;
m_Comm.GetInput();//先预读缓冲区以清除残留数据
m_Comm.SetPortOpen(FALSE);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -