红绿灯模拟

本文介绍了一个使用Delphi实现的交通信号灯程序设计案例。该程序通过定时器控制红绿黄三色灯的状态切换,并利用计数器进行倒计时显示。通过不同的颜色变化和时间间隔,模拟了真实的交通信号灯工作流程。
  1 unit TrafficLight3;
  2 
  3 interface
  4 
  5 uses
  6   Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  7   Dialogs, StdCtrls, ExtCtrls;
  8 
  9 type
 10   TForm1 = class(TForm)
 11     Shape1: TShape;
 12     Shape2: TShape;
 13     Shape3: TShape;
 14     Panel1: TPanel;
 15     Label1: TLabel;
 16     Timer4: TTimer;
 17     Label2: TLabel;
 18     procedure Timer4Timer(Sender: TObject);
 19   private
 20     { Private declarations }
 21   public
 22     { Public declarations }
 23   end;
 24 
 25 var
 26   Form1: TForm1;
 27 
 28 implementation
 29 
 30 {$R *.dfm}
 31 {
 32 procedure TForm1.Timer1Timer(Sender: TObject);
 33 begin
 34   if label1.Caption<>'1' then
 35   label1.Caption:=IntToStr(StrToInt(Label1.Caption)-1)
 36   else
 37   begin
 38     Shape1.Brush.Color:=clSilver;
 39     Shape3.Brush.Color:=clSilver;
 40     Shape2.Brush.Color:=clYellow;
 41     Timer2.Enabled:=True;
 42     Timer1.Enabled:=False;
 43     Timer3.Enabled:=False;
 44     Label1.Caption:='4';
 45 
 46   end;
 47 end;
 48 
 49 
 50 procedure TForm1.Timer2Timer(Sender: TObject);
 51 begin
 52      if label1.Caption<>'1' then
 53   label1.Caption:=IntToStr(StrToInt(Label1.Caption)-1)
 54   else
 55   begin
 56     Shape2.Brush.Color:=clSilver;
 57     Shape3.Brush.Color:=clSilver;
 58     Shape1.Brush.Color:=clRed;
 59     Timer1.Enabled:=True;
 60     Timer2.Enabled:=False;
 61     Timer3.Enabled:=False;
 62     Label1.Caption:='5';
 63 
 64   end;
 65 end;
 66 
 67 procedure TForm1.Timer3Timer(Sender: TObject);
 68 begin
 69    if label1.Caption<>'1' then
 70   label1.Caption:=IntToStr(StrToInt(Label1.Caption)-1)
 71   else
 72   begin
 73     Shape1.Brush.Color:=clSilver;
 74     Shape2.Brush.Color:=clSilver;
 75     Shape3.Brush.Color:=clGreen;
 76     Timer3.Enabled:=True;
 77     Timer2.Enabled:=False;
 78     Timer1.Enabled:=False;
 79     Label1.Caption:='6';
 80 
 81   end;
 82 end;
 83 
 84 }
 85 
 86 
 87 var
 88     n:Integer=0;
 89 procedure TForm1.Timer4Timer(Sender: TObject);
 90 begin
 91   n:=n+1;
 92   Label2.Caption:=IntToStr(n);
 93   if n<=10  then
 94 
 95  begin
 96  
 97     Shape2.Brush.Color:=clSilver;
 98     Shape3.Brush.Color:=clSilver;
 99     Shape1.Brush.Color:=clGreen;
100    if label1.Caption<>'1' then
101      label1.Caption:=IntToStr(StrToInt(Label1.Caption)-1)
102    else
103    begin
104   
105     Label1.Caption:='5';
106    end;
107     end;
108 
109  if (n>5) and (n<=10) then
110 
111  begin
112     if n mod 2=0 then
113       begin
114       Shape1.Brush.Color:=clGreen;
115       Shape3.Brush.Color:=clSilver;
116       Shape2.Brush.Color:=clBlack;
117     end
118    else
119    begin
120 
121 
122     Shape1.Brush.Color:=clGreen;
123     Shape3.Brush.Color:=clSilver;
124     Shape2.Brush.Color:=clYellow;
125        end;
126    if label1.Caption<>'1' then
127      label1.Caption:=IntToStr(StrToInt(Label1.Caption)-1)
128     else
129      begin
130        Label1.Caption:='10';
131       end;
132 
133   end;
134 
135   if (n>10) and (n<=20) then
136  begin
137     Shape2.Brush.Color:=clSilver;
138     Shape1.Brush.Color:=clSilver;
139     Shape3.Brush.Color:=clRed;
140    if label1.Caption<>'1' then
141   label1.Caption:=IntToStr(StrToInt(Label1.Caption)-1)
142   else
143   begin
144 
145     Label1.Caption:='10';
146     n:=0;
147   end;
148 
149  end;
150 end;
151 
152 end.

 

 

转载于:https://www.cnblogs.com/thrive/p/4146064.html

一、数据采集层:多源人脸数据获取 该层负责从不同设备 / 渠道采集人脸原始数据,为后续模型训练与识别提供基础样本,核心功能包括: 1. 多设备适配采集 实时摄像头采集: 调用计算机内置摄像头(或外接 USB 摄像头),通过OpenCV的VideoCapture接口实时捕获视频流,支持手动触发 “拍照”(按指定快捷键如Space)或自动定时采集(如每 2 秒采集 1 张),采集时自动框选人脸区域(通过Haar级联分类器初步定位),确保样本聚焦人脸。 支持采集参数配置:可设置采集分辨率(如 640×480、1280×720)、图像格式(JPG/PNG)、单用户采集数量(如默认采集 20 张,确保样本多样性),采集过程中实时显示 “已采集数量 / 目标数量”,避免样本不足。 本地图像 / 视频导入: 支持批量导入本地人脸图像文件(支持 JPG、PNG、BMP 格式),自动过滤非图像文件;导入视频文件(MP4、AVI 格式)时,可按 “固定帧间隔”(如每 10 帧提取 1 张图像)或 “手动选择帧” 提取人脸样本,适用于无实时摄像头场景。 数据集对接: 支持接入公开人脸数据集(如 LFW、ORL),通过预设脚本自动读取数据集目录结构(按 “用户 ID - 样本图像” 分类),快速构建训练样本库,无需手动采集,降低系统开发与测试成本。 2. 采集过程辅助功能 人脸有效性校验:采集时通过OpenCV的Haar级联分类器(或MTCNN轻量级模型)实时检测图像中是否包含人脸,若未检测到人脸(如遮挡、侧脸角度过大),则弹窗提示 “未识别到人脸,请调整姿态”,避免无效样本存入。 样本标签管理:采集时需为每个样本绑定 “用户标签”(如姓名、ID 号),支持手动输入标签或从 Excel 名单批量导入标签(按 “标签 - 采集数量” 对应),采集完成后自动按 “标签 - 序号” 命名文件(如 “张三
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值