The part of calling the camera has been implemented
but the recognition is not yet complete
This commit is contained in:
parent
eafdf671d5
commit
b1b87ad724
38
OTP/Form3.Designer.cs
generated
38
OTP/Form3.Designer.cs
generated
@ -42,7 +42,10 @@
|
|||||||
this.label4 = new System.Windows.Forms.Label();
|
this.label4 = new System.Windows.Forms.Label();
|
||||||
this.label5 = new System.Windows.Forms.Label();
|
this.label5 = new System.Windows.Forms.Label();
|
||||||
this.groupBox1 = new System.Windows.Forms.GroupBox();
|
this.groupBox1 = new System.Windows.Forms.GroupBox();
|
||||||
|
this.pictureBox1 = new System.Windows.Forms.PictureBox();
|
||||||
|
this.button7 = new System.Windows.Forms.Button();
|
||||||
this.groupBox1.SuspendLayout();
|
this.groupBox1.SuspendLayout();
|
||||||
|
((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).BeginInit();
|
||||||
this.SuspendLayout();
|
this.SuspendLayout();
|
||||||
//
|
//
|
||||||
// label1
|
// label1
|
||||||
@ -125,6 +128,7 @@
|
|||||||
this.button5.TabIndex = 8;
|
this.button5.TabIndex = 8;
|
||||||
this.button5.Text = "Scan QR Code with Camera";
|
this.button5.Text = "Scan QR Code with Camera";
|
||||||
this.button5.UseVisualStyleBackColor = true;
|
this.button5.UseVisualStyleBackColor = true;
|
||||||
|
this.button5.Click += new System.EventHandler(this.button5_Click);
|
||||||
//
|
//
|
||||||
// button6
|
// button6
|
||||||
//
|
//
|
||||||
@ -164,22 +168,49 @@
|
|||||||
//
|
//
|
||||||
// groupBox1
|
// groupBox1
|
||||||
//
|
//
|
||||||
|
this.groupBox1.Controls.Add(this.button7);
|
||||||
|
this.groupBox1.Controls.Add(this.pictureBox1);
|
||||||
this.groupBox1.Controls.Add(this.label4);
|
this.groupBox1.Controls.Add(this.label4);
|
||||||
this.groupBox1.Controls.Add(this.label5);
|
this.groupBox1.Controls.Add(this.label5);
|
||||||
this.groupBox1.Controls.Add(this.label3);
|
this.groupBox1.Controls.Add(this.label3);
|
||||||
this.groupBox1.Location = new System.Drawing.Point(15, 148);
|
this.groupBox1.Location = new System.Drawing.Point(15, 148);
|
||||||
this.groupBox1.Name = "groupBox1";
|
this.groupBox1.Name = "groupBox1";
|
||||||
this.groupBox1.Size = new System.Drawing.Size(453, 243);
|
this.groupBox1.Size = new System.Drawing.Size(453, 288);
|
||||||
this.groupBox1.TabIndex = 14;
|
this.groupBox1.TabIndex = 14;
|
||||||
this.groupBox1.TabStop = false;
|
this.groupBox1.TabStop = false;
|
||||||
this.groupBox1.Text = "Debug Info";
|
this.groupBox1.Text = "Debug Info";
|
||||||
//
|
//
|
||||||
|
// pictureBox1
|
||||||
|
//
|
||||||
|
this.pictureBox1.Location = new System.Drawing.Point(105, 113);
|
||||||
|
this.pictureBox1.Name = "pictureBox1";
|
||||||
|
this.pictureBox1.Size = new System.Drawing.Size(255, 169);
|
||||||
|
this.pictureBox1.SizeMode = System.Windows.Forms.PictureBoxSizeMode.Zoom;
|
||||||
|
this.pictureBox1.TabIndex = 14;
|
||||||
|
this.pictureBox1.TabStop = false;
|
||||||
|
//
|
||||||
|
// button7
|
||||||
|
//
|
||||||
|
this.button7.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
|
||||||
|
| System.Windows.Forms.AnchorStyles.Left)
|
||||||
|
| System.Windows.Forms.AnchorStyles.Right)));
|
||||||
|
this.button7.Font = new System.Drawing.Font("Microsoft Sans Serif", 48F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
|
||||||
|
this.button7.Location = new System.Drawing.Point(366, 162);
|
||||||
|
this.button7.MinimumSize = new System.Drawing.Size(75, 75);
|
||||||
|
this.button7.Name = "button7";
|
||||||
|
this.button7.Size = new System.Drawing.Size(75, 75);
|
||||||
|
this.button7.TabIndex = 15;
|
||||||
|
this.button7.Text = "●";
|
||||||
|
this.button7.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
|
||||||
|
this.button7.UseVisualStyleBackColor = true;
|
||||||
|
this.button7.Click += new System.EventHandler(this.button7_Click);
|
||||||
|
//
|
||||||
// Form3
|
// Form3
|
||||||
//
|
//
|
||||||
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
|
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
|
||||||
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
||||||
this.CancelButton = this.button2;
|
this.CancelButton = this.button2;
|
||||||
this.ClientSize = new System.Drawing.Size(488, 403);
|
this.ClientSize = new System.Drawing.Size(488, 448);
|
||||||
this.Controls.Add(this.groupBox1);
|
this.Controls.Add(this.groupBox1);
|
||||||
this.Controls.Add(this.button6);
|
this.Controls.Add(this.button6);
|
||||||
this.Controls.Add(this.button5);
|
this.Controls.Add(this.button5);
|
||||||
@ -201,6 +232,7 @@
|
|||||||
this.FormClosing += new System.Windows.Forms.FormClosingEventHandler(this.Form3_FormClosing);
|
this.FormClosing += new System.Windows.Forms.FormClosingEventHandler(this.Form3_FormClosing);
|
||||||
this.groupBox1.ResumeLayout(false);
|
this.groupBox1.ResumeLayout(false);
|
||||||
this.groupBox1.PerformLayout();
|
this.groupBox1.PerformLayout();
|
||||||
|
((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).EndInit();
|
||||||
this.ResumeLayout(false);
|
this.ResumeLayout(false);
|
||||||
this.PerformLayout();
|
this.PerformLayout();
|
||||||
|
|
||||||
@ -222,5 +254,7 @@
|
|||||||
private System.Windows.Forms.Label label4;
|
private System.Windows.Forms.Label label4;
|
||||||
private System.Windows.Forms.Label label5;
|
private System.Windows.Forms.Label label5;
|
||||||
private System.Windows.Forms.GroupBox groupBox1;
|
private System.Windows.Forms.GroupBox groupBox1;
|
||||||
|
private System.Windows.Forms.PictureBox pictureBox1;
|
||||||
|
private System.Windows.Forms.Button button7;
|
||||||
}
|
}
|
||||||
}
|
}
|
68
OTP/Form3.cs
68
OTP/Form3.cs
@ -10,6 +10,8 @@ using System.Text;
|
|||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using System.Windows.Forms;
|
using System.Windows.Forms;
|
||||||
using ZXing;
|
using ZXing;
|
||||||
|
using AForge.Video;
|
||||||
|
using AForge.Video.DirectShow;
|
||||||
|
|
||||||
namespace OTP
|
namespace OTP
|
||||||
{
|
{
|
||||||
@ -18,15 +20,22 @@ namespace OTP
|
|||||||
private string connectionString = "Data Source=key.db;Version=3;";
|
private string connectionString = "Data Source=key.db;Version=3;";
|
||||||
private bool isCapturing = false; // 添加标识截图状态的成员变量
|
private bool isCapturing = false; // 添加标识截图状态的成员变量
|
||||||
private bool isLocalfile = false;
|
private bool isLocalfile = false;
|
||||||
|
private FilterInfoCollection videoDevices; // 声明用于存储摄像头设备信息的变量
|
||||||
|
private VideoCaptureDevice camera; // 声明用于摄像头捕获的变量
|
||||||
|
private bool isCameraRunning = false; // 用于标识摄像头的运行状态
|
||||||
|
private bool isScanningPaused = false;
|
||||||
|
|
||||||
public Form3()
|
public Form3()
|
||||||
{
|
{
|
||||||
InitializeComponent();
|
InitializeComponent();
|
||||||
|
videoDevices = new FilterInfoCollection(FilterCategory.VideoInputDevice);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void Form3_FormClosing(object sender, FormClosingEventArgs e)
|
private void Form3_FormClosing(object sender, FormClosingEventArgs e)
|
||||||
{
|
{
|
||||||
StopCapturing(); // 关闭窗口时停止截图
|
StopCapturing(); // 关闭窗口时停止截图
|
||||||
|
StopCamera(); // 关闭窗口时停止摄像头
|
||||||
}
|
}
|
||||||
|
|
||||||
private void button1_Click(object sender, EventArgs e)
|
private void button1_Click(object sender, EventArgs e)
|
||||||
@ -198,5 +207,64 @@ namespace OTP
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void button5_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
if (!isCameraRunning)
|
||||||
|
{
|
||||||
|
StartCamera(); // 启动摄像头
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
StopCamera(); // 停止摄像头
|
||||||
|
}
|
||||||
|
}
|
||||||
|
private void StartCamera()
|
||||||
|
{
|
||||||
|
if (videoDevices != null && videoDevices.Count > 0)
|
||||||
|
{
|
||||||
|
camera = new VideoCaptureDevice(videoDevices[0].MonikerString);
|
||||||
|
camera.NewFrame += Camera_NewFrame; // 注册摄像头捕获图像的事件
|
||||||
|
camera.Start(); // 启动摄像头
|
||||||
|
isCameraRunning = true; // 设置摄像头运行状态为 true
|
||||||
|
//button5.Text = "Stop Camera"; // 更新按钮文本
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
MessageBox.Show("No camera device found.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void StopCamera()
|
||||||
|
{
|
||||||
|
if (camera != null && camera.IsRunning)
|
||||||
|
{
|
||||||
|
camera.SignalToStop();
|
||||||
|
camera.WaitForStop();
|
||||||
|
camera.NewFrame -= Camera_NewFrame; // 取消注册摄像头捕获图像的事件
|
||||||
|
isCameraRunning = false; // 设置摄像头运行状态为 false
|
||||||
|
//button5.Text = "Start Camera"; // 更新按钮文本
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void Camera_NewFrame(object sender, NewFrameEventArgs eventArgs)
|
||||||
|
{
|
||||||
|
// 进行二维码扫描
|
||||||
|
Bitmap bitmap = (Bitmap)eventArgs.Frame.Clone();
|
||||||
|
if (!isScanningPaused)
|
||||||
|
{
|
||||||
|
pictureBox1.Image = bitmap;
|
||||||
|
}else
|
||||||
|
{
|
||||||
|
// 进行二维码扫描
|
||||||
|
ScanQRCode(bitmap);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void button7_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
isScanningPaused = !isScanningPaused;
|
||||||
|
button7.Text = isScanningPaused ? "Resume" : "Pause";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -36,6 +36,15 @@
|
|||||||
<WarningLevel>4</WarningLevel>
|
<WarningLevel>4</WarningLevel>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
<Reference Include="AForge, Version=2.2.5.0, Culture=neutral, PublicKeyToken=c1db6ff4eaa06aeb, processorArchitecture=MSIL">
|
||||||
|
<HintPath>..\packages\AForge.2.2.5\lib\AForge.dll</HintPath>
|
||||||
|
</Reference>
|
||||||
|
<Reference Include="AForge.Video, Version=2.2.5.0, Culture=neutral, PublicKeyToken=cbfb6e07d173c401, processorArchitecture=MSIL">
|
||||||
|
<HintPath>..\packages\AForge.Video.2.2.5\lib\AForge.Video.dll</HintPath>
|
||||||
|
</Reference>
|
||||||
|
<Reference Include="AForge.Video.DirectShow, Version=2.2.5.0, Culture=neutral, PublicKeyToken=61ea4348d43881b7, processorArchitecture=MSIL">
|
||||||
|
<HintPath>..\packages\AForge.Video.DirectShow.2.2.5\lib\AForge.Video.DirectShow.dll</HintPath>
|
||||||
|
</Reference>
|
||||||
<Reference Include="CircularProgressBar, Version=2.8.0.16, Culture=neutral, PublicKeyToken=310fd07b25df79b3, processorArchitecture=MSIL">
|
<Reference Include="CircularProgressBar, Version=2.8.0.16, Culture=neutral, PublicKeyToken=310fd07b25df79b3, processorArchitecture=MSIL">
|
||||||
<HintPath>..\packages\CircularProgressBar.2.8.0.16\lib\net40\CircularProgressBar.dll</HintPath>
|
<HintPath>..\packages\CircularProgressBar.2.8.0.16\lib\net40\CircularProgressBar.dll</HintPath>
|
||||||
</Reference>
|
</Reference>
|
||||||
|
@ -1,5 +1,8 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<packages>
|
<packages>
|
||||||
|
<package id="AForge" version="2.2.5" targetFramework="net481" />
|
||||||
|
<package id="AForge.Video" version="2.2.5" targetFramework="net481" />
|
||||||
|
<package id="AForge.Video.DirectShow" version="2.2.5" targetFramework="net481" />
|
||||||
<package id="CircularProgressBar" version="2.8.0.16" targetFramework="net481" />
|
<package id="CircularProgressBar" version="2.8.0.16" targetFramework="net481" />
|
||||||
<package id="EntityFramework" version="6.4.4" targetFramework="net481" />
|
<package id="EntityFramework" version="6.4.4" targetFramework="net481" />
|
||||||
<package id="Otp.NET" version="1.3.0" targetFramework="net481" />
|
<package id="Otp.NET" version="1.3.0" targetFramework="net481" />
|
||||||
|
Loading…
x
Reference in New Issue
Block a user