📄 mainform.pas
字号:
unit MainForm;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, VideoWnd,videocard, StdCtrls, ExtCtrls,VirLoop,DateUtils,
TeeProcs, TeEngine, Chart, Series,filename,Math,extinifile,Log,Mmsystem,
OleCtrls, PlateDSPV2_TLB;
const
FRAMERATE=2;
type
TForm1 = class(TForm)
VideoWnd1: TVideoWnd;
VideoWnd2: TVideoWnd;
VideoWnd3: TVideoWnd;
VideoWnd4: TVideoWnd;
VideoWnd5: TVideoWnd;
VideoWnd6: TVideoWnd;
ButtonBg: TButton;
VideoWnd7: TVideoWnd;
MemoFrameNum: TMemo;
MemoBright: TMemo;
Label1: TLabel;
Label2: TLabel;
Memo1: TMemo;
Label3: TLabel;
VideoWnd8: TVideoWnd;
ShapeCap: TShape;
ButtonStart: TButton;
Timer1: TTimer;
GroupBoxVideoCard: TGroupBox;
ComboBoxQjCard: TComboBox;
Label4: TLabel;
CheckBoxSave: TCheckBox;
ComboBoxQjChannel: TComboBox;
Label5: TLabel;
ComboBoxTXCard: TComboBox;
ComboBoxTXChannel: TComboBox;
Label6: TLabel;
GroupBox2: TGroupBox;
LabeledEditlooplt: TLabeledEdit;
LabeledEditlooplb: TLabeledEdit;
LabeledEditlooprt: TLabeledEdit;
LabeledEditlooprb: TLabeledEdit;
LabeledEditlooptp: TLabeledEdit;
LabeledEditloopbtm: TLabeledEdit;
LabeledEditloopcpt: TLabeledEdit;
ButtonEditLoopParam: TButton;
GroupBox1: TGroupBox;
LabeledEdit1: TLabeledEdit;
LabeledEdit2: TLabeledEdit;
LabeledEdit3: TLabeledEdit;
LabeledEdit4: TLabeledEdit;
LabeledEdit5: TLabeledEdit;
LabeledEdit9: TLabeledEdit;
LabeledEdit10: TLabeledEdit;
LabeledEdit6: TLabeledEdit;
LabeledEdit7: TLabeledEdit;
LabeledEdit8: TLabeledEdit;
CheckBoxShadow: TCheckBox;
LabeledEdit11: TLabeledEdit;
LabeledEdit12: TLabeledEdit;
LabeledEdit13: TLabeledEdit;
LabeledEdit14: TLabeledEdit;
LabeledEdit15: TLabeledEdit;
LabeledEdit16: TLabeledEdit;
LabeledEdit17: TLabeledEdit;
LabeledEdit18: TLabeledEdit;
LabeledEdit19: TLabeledEdit;
RadioGroupMode: TRadioGroup;
ButtonEditSetParam: TButton;
Label7: TLabel;
Label8: TLabel;
LabeledEdit20: TLabeledEdit;
LabeledEdit21: TLabeledEdit;
LabeledEdit22: TLabeledEdit;
CheckBoxNoise: TCheckBox;
CheckBoxContrast: TCheckBox;
RadioGroupTime: TRadioGroup;
MemoTime: TMemo;
Label9: TLabel;
LabeledEditBright: TLabeledEdit;
procedure FormCreate(Sender: TObject);
procedure FormCloseQuery(Sender: TObject; var CanClose: Boolean);
procedure VideoWnd1MouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
procedure ButtonEditSetParamClick(Sender: TObject);
procedure ButtonStartClick(Sender: TObject);
procedure ButtonBgClick(Sender: TObject);
procedure Timer1Timer(Sender: TObject);
procedure CheckBoxSaveClick(Sender: TObject);
procedure RadioGroupTimeClick(Sender: TObject);
procedure ButtonEditLoopParamClick(Sender: TObject);
private
{ Private declarations }
m_QJCard:TVideoCard;
m_TXCard:TVideoCard;
m_clicknum:integer;//记录在视窗上点击的次数,用于确定虚拟线圈的位置
m_VLoop:TVLoop;
m_id:integer;
m_image:array [0..IMGWIDTH*IMGHEIGHT*3-1]of Byte;
m_pic:array [0..3,0..IMGWIDTH*IMGHEIGHT*3-1]of Byte;//存贮全景和特写图片
m_bgimage:array [0..IMGWIDTH*IMGHEIGHT*3-1]of Byte;//采集背景
m_grayimg:array [0..IMGHEIGHT-1,0..IMGWIDTH-1] of byte; //存储灰度图像
//虚拟线圈检测的相关参数
m_Loopparam:array[1..7] of integer;//虚拟线圈位置
m_setparam1:array[1..27] of real;//虚拟线圈白天参数
m_setparam2:array[1..27] of real;//虚拟线圈夜晚参数
m_savefile:boolean;
m_daynight:integer;//界定白天晚上,0为白天,1为晚上
//m_mode:integer;//选择是背景提取还是帧差
//m_shadow:boolean;//是否去除阴影
//BMP头
Bih: BITMAPINFOHEADER;
imgconvert: array of byte;
public
{ Public declarations }
procedure ReadLoopParam();
procedure WriteLoopParam();
procedure ReadSetParam();
procedure WriteSetParam();
procedure showparam();//过程参数显示
procedure DrawLoop();//画线圈
procedure VideoDetect(image:PByte);//进行虚拟线圈分析
procedure SaveDatFile(filename:string;time:TDateTime);
procedure SaveConfig();
procedure LoadConfig();
end;
var
Form1: TForm1;
g_RoadName:string = '试验路口';
g_Direct:string='未知方向';
//预存全景图片
g_picbuff:array [0..24,0..IMGWIDTH*IMGHEIGHT*3-1]of Byte;
g_picid:integer=0;
g_picnum:integer=0;
g_ConfigFile:string = '.\config\param.ini';
g_time:integer;//显示程序消耗的时间
implementation
{$R *.dfm}
procedure TForm1.LoadConfig();
var
inifile:TExtIniFile;
section:String;
begin
CreateDir('.\config\');
inifile:=TExtIniFile.Create(g_ConfigFile);
section:=IntToStr(m_id);
g_SavePath:=inifile.ReadString(section,'存盘路径',g_SavePath);
inifile.ReadIntegerArray(section,'虚拟线圈位置',m_Loopparam,m_Loopparam,7);
inifile.ReadRealArray(section,'虚拟线圈白天设置',m_setparam1,m_setparam1,27);
inifile.ReadRealArray(section,'虚拟线圈夜晚设置',m_setparam2,m_setparam2,27);
inifile.Free;
end;
procedure TForm1.SaveConfig();
var
inifile:TExtIniFile;
section:string;
begin
CreateDir('.\config\');
inifile:=TExtIniFile.Create(g_ConfigFile);
section:=IntToStr(m_id);
inifile.WriteString(section,'存盘路径',g_SavePath);
inifile.WriteIntegerArray(section,'虚拟线圈位置',m_Loopparam,7);
inifile.WriteRealArray(section,'虚拟线圈白天设置',m_setparam1,27);
inifile.WriteRealArray(section,'虚拟线圈夜晚设置',m_setparam2,27);
inifile.Free;
end;
procedure TForm1.ReadLoopParam();
begin
m_Loopparam[1]:=strtoint(LabeledEditlooptp.Text);//上
m_Loopparam[2]:=strtoint(LabeledEditlooplt.Text);//左上
m_Loopparam[3]:=strtoint(LabeledEditlooprt.Text);//右上
m_Loopparam[4]:=strtoint(LabeledEditloopbtm.Text);//下
m_Loopparam[5]:=strtoint(LabeledEditlooplb.Text);//左下
m_Loopparam[6]:=strtoint(LabeledEditlooprb.Text);//右下
m_Loopparam[7]:=strtoint(LabeledEditloopcpt.Text);//抓拍线
end;
procedure TForm1.WriteLoopParam();
begin
LabeledEditlooptp.Text:=inttostr(m_Loopparam[1]);
LabeledEditlooplt.Text:=inttostr(m_Loopparam[2]);
LabeledEditlooprt.Text:=inttostr(m_Loopparam[3]);
LabeledEditloopbtm.Text:=inttostr(m_Loopparam[4]);
LabeledEditlooplb.Text:=inttostr(m_Loopparam[5]);
LabeledEditlooprb.Text:=inttostr(m_Loopparam[6]);
LabeledEditloopcpt.Text:=inttostr(m_Loopparam[7]);
end;
procedure TForm1.ReadSetParam();//从界面上读取参数
var
i:integer;
LabeledEditName:TLabeledEdit;
begin
if m_daynight=0 then //白天
begin
for i:=Low(m_setparam1) to High(m_setparam1)-5 do
begin
LabeledEditName:=TLabeledEdit(findcomponent('LabeledEdit'+inttostr(i)));
m_setparam1[i]:=StrToFloat(LabeledEditName.Text);
end;
m_setparam1[23]:=RadioGroupMode.ItemIndex;
m_setparam1[24]:=ord(CheckBoxShadow.checked);
m_setparam1[25]:=ord(CheckBoxNoise.checked);
m_setparam1[26]:=ord(CheckBoxContrast.checked);
end
else if m_daynight=1 then //晚上
begin
for i:=Low(m_setparam2) to High(m_setparam2)-5 do
begin
LabeledEditName:=TLabeledEdit(findcomponent('LabeledEdit'+inttostr(i)));
m_setparam2[i]:=StrToFloat(LabeledEditName.Text);
end;
m_setparam2[23]:=RadioGroupMode.ItemIndex;
m_setparam2[24]:=ord(CheckBoxShadow.checked);
m_setparam2[25]:=ord(CheckBoxNoise.checked);
m_setparam2[26]:=ord(CheckBoxContrast.checked);
end;
m_setparam1[27]:=StrToInt(LabeledEditBright.Text);
m_setparam2[27]:=m_setparam1[27];
end;
procedure TForm1.WriteSetParam();//将参数写到界面上
var
i:integer;
LabeledEditName:TLabeledEdit;
begin
if m_daynight=0 then//白天
begin
for i:=Low(m_setparam1) to High(m_setparam1)-5 do
begin
LabeledEditName:=TLabeledEdit(findcomponent('LabeledEdit'+inttostr(i)));
LabeledEditName.Text:=FloattoStr(m_setparam1[i]);
end;
RadioGroupMode.ItemIndex:=round(m_setparam1[23]);
CheckBoxShadow.checked:=boolean(round(m_setparam1[24]));
CheckBoxNoise.checked:=boolean(round(m_setparam1[25]));
CheckBoxcontrast.checked:=boolean(round(m_setparam1[26]));
end
else if m_daynight=1 then //晚上
begin
for i:=Low(m_setparam2) to High(m_setparam2)-5 do
begin
LabeledEditName:=TLabeledEdit(findcomponent('LabeledEdit'+inttostr(i)));
LabeledEditName.Text:=FloattoStr(m_setparam2[i]);
end;
RadioGroupMode.ItemIndex:=round(m_setparam2[23]);
CheckBoxShadow.checked:=boolean(round(m_setparam2[24]));
CheckBoxNoise.checked:=boolean(round(m_setparam2[25]));
CheckBoxContrast.checked:=boolean(round(m_setparam2[26]));
end;
LabeledEditBright.Text:=FloatToStr(m_setparam1[27]);
end;
procedure TForm1.DrawLoop();
var
i,j:integer;
ACar:PCarObject;
center_i,center_j:integer;
lp_lft,lp_lft_b,lp_rt,lp_rt_b,lp_tp,lp_btm,cpt,cptll,cptrr:integer;
mode:integer;//mode=0背景提取,mode=1帧差
begin
lp_tp:=m_Loopparam[1];
lp_lft:=m_Loopparam[2];
lp_rt:=m_Loopparam[3];
lp_btm:=m_Loopparam[4];
lp_lft_b:=m_Loopparam[5];
lp_rt_b:=m_Loopparam[6];
cpt:=m_Loopparam[7];
mode:=0;
if m_daynight=0 then
mode:=round(m_setparam1[23])
else if m_daynight=1 then
mode:=round(m_setparam2[23]);
//画线圈
VideoWnd1.MoveTo(lp_lft,lp_tp);
VideoWnd1.LineTo(lp_rt,lp_tp,clRed);
VideoWnd1.LineTo(lp_rt_b,lp_btm,clRed);
VideoWnd1.LineTo(lp_lft_b,lp_btm,clRed);
VideoWnd1.LineTo(lp_lft,lp_tp,clRed);
cptll:=lp_lft+round((cpt-lp_tp)*(lp_lft_b-lp_lft)/(lp_btm-lp_tp));
cptrr:=lp_rt+round((cpt-lp_tp)*(lp_rt_b-lp_rt)/(lp_btm-lp_tp));
VideoWnd1.MoveTo(cptll, cpt);
VideoWnd1.LineTo(cptrr,cpt,clRed);
//显示差分图像
VideoWnd5.DrawImage(@g_image[0]);
VideoWnd5.MoveTo(lp_lft, lp_tp);
VideoWnd5.LineTo(lp_rt,lp_tp,clRed);
VideoWnd5.LineTo(lp_rt_b,lp_btm,clRed);
VideoWnd5.LineTo(lp_lft_b,lp_btm,clRed);
VideoWnd5.LineTo(lp_lft,lp_tp,clRed);
VideoWnd5.MoveTo(cptll, cpt);
VideoWnd5.LineTo(cptrr,cpt,clRed);
if mode=0 then
begin
//显示车辆对象及轨迹
for i:=0 to m_VLoop.m_CarList.Count-1 do
begin
ACar:=m_VLoop.m_CarList.Items[i];
VideoWnd5.Rectangle(ACar^.ObjectRecord[ACar^.FrameNum-1].ll*WBLOCKSIZE,ACar^.ObjectRecord[ACar^.FrameNum-1].ii_t*HBLOCKSIZE,ACar^.ObjectRecord[ACar^.FrameNum-1].rr*WBLOCKSIZE,ACar^.ObjectRecord[ACar^.FrameNum-1].ii_b*HBLOCKSIZE,clred);
VideoWnd1.Rectangle(ACar^.ObjectRecord[ACar^.FrameNum-1].ll*WBLOCKSIZE,ACar^.ObjectRecord[ACar^.FrameNum-1].ii_t*HBLOCKSIZE,ACar^.ObjectRecord[ACar^.FrameNum-1].rr*WBLOCKSIZE,ACar^.ObjectRecord[ACar^.FrameNum-1].ii_b*HBLOCKSIZE,clred);
for j:=0 to ACar^.FrameNum-2 do
begin
//center_i:=(ACar^.ObjectRecord[j].ii_t+ACar^.ObjectRecord[j].ii_b) div 2;
center_i:=ACar^.ObjectRecord[j].ii_b;
center_j:=(ACar^.ObjectRecord[j].ll+ACar^.ObjectRecord[j].rr) div 2;
VideoWnd5.MoveTo(center_j*WBLOCKSIZE, center_i*HBLOCKSIZE);
VideoWnd1.MoveTo(center_j*WBLOCKSIZE, center_i*HBLOCKSIZE);
//center_i:=(ACar^.ObjectRecord[j+1].ii_t+ACar^.ObjectRecord[j+1].ii_b) div 2;
center_i:=ACar^.ObjectRecord[j+1].ii_b;
center_j:=(ACar^.ObjectRecord[j+1].ll+ACar^.ObjectRecord[j+1].rr) div 2;
VideoWnd5.LineTo(center_j*WBLOCKSIZE,center_i*HBLOCKSIZE,clred);
VideoWnd1.LineTo(center_j*WBLOCKSIZE,center_i*HBLOCKSIZE,clred);
end;
end;
end
else if mode=1 then
begin
//显示车辆对象及轨迹
for i:=0 to m_VLoop.m_CarList.Count-1 do
begin
ACar:=m_VLoop.m_CarList.Items[i];
VideoWnd5.Rectangle(ACar^.ObjectRecord[ACar^.FrameNum-1].ll,ACar^.ObjectRecord[ACar^.FrameNum-1].ii_t,ACar^.ObjectRecord[ACar^.FrameNum-1].rr,ACar^.ObjectRecord[ACar^.FrameNum-1].ii_b,clred);
VideoWnd1.Rectangle(ACar^.ObjectRecord[ACar^.FrameNum-1].ll,ACar^.ObjectRecord[ACar^.FrameNum-1].ii_t,ACar^.ObjectRecord[ACar^.FrameNum-1].rr,ACar^.ObjectRecord[ACar^.FrameNum-1].ii_b,clred);
for j:=0 to ACar^.FrameNum-2 do
begin
//center_i:=(ACar^.ObjectRecord[j].ii_t+ACar^.ObjectRecord[j].ii_b) div 2;
center_i:=ACar^.ObjectRecord[j].ii_b;
center_j:=(ACar^.ObjectRecord[j].ll+ACar^.ObjectRecord[j].rr) div 2;
VideoWnd5.MoveTo(center_j, center_i);
VideoWnd1.MoveTo(center_j, center_i);
//center_i:=(ACar^.ObjectRecord[j+1].ii_t+ACar^.ObjectRecord[j+1].ii_b) div 2;
center_i:=ACar^.ObjectRecord[j+1].ii_b;
center_j:=(ACar^.ObjectRecord[j+1].ll+ACar^.ObjectRecord[j+1].rr) div 2;
VideoWnd5.LineTo(center_j,center_i,clred);
VideoWnd1.LineTo(center_j,center_i,clred);
end;
end;
end;
//显示背景
VideoWnd6.DrawImage(@g_imagebg[0]);
//画线圈
VideoWnd6.MoveTo(lp_lft, lp_tp);
VideoWnd6.LineTo(lp_rt,lp_tp,clRed);
VideoWnd6.LineTo(lp_rt_b,lp_btm,clRed);
VideoWnd6.LineTo(lp_lft_b,lp_btm,clRed);
VideoWnd6.LineTo(lp_lft,lp_tp,clRed);
VideoWnd6.MoveTo(cptll, cpt);
VideoWnd6.LineTo(cptrr,cpt,clRed);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -