diff --git a/labs/CameraCard/AutoUpdate/.gitignore b/labs/CameraCard/AutoUpdate/.gitignore
new file mode 100644
index 00000000..cd5894bd
--- /dev/null
+++ b/labs/CameraCard/AutoUpdate/.gitignore
@@ -0,0 +1,18 @@
+*.bak
+*.suo
+*.db
+*.db-shm
+*.db-wal
+*.user
+.vs
+obj
+Obj
+bin
+Bin
+debug
+Debug
+release
+Release
+Logs
+logs
+node_modules
\ No newline at end of file
diff --git a/labs/CameraCard/AutoUpdate/Properties/AssemblyInfo.cs b/labs/CameraCard/AutoUpdate/Properties/AssemblyInfo.cs
index 9a5106b9..fbe7aa73 100644
--- a/labs/CameraCard/AutoUpdate/Properties/AssemblyInfo.cs
+++ b/labs/CameraCard/AutoUpdate/Properties/AssemblyInfo.cs
@@ -22,7 +22,7 @@ using System.Runtime.InteropServices;
// 如果此项目向 COM 公开,则下列 GUID 用于类型库的 ID
[assembly: Guid("0f767d6d-72de-47fd-be40-432dadfa1fae")]
-// 程序集的版本信息由下列四个值组成:
+// 程序集的版本信息由下列四个值组成:
//
// 主版本
// 次版本
@@ -32,5 +32,5 @@ using System.Runtime.InteropServices;
//可以指定所有这些值,也可以使用“生成号”和“修订号”的默认值
//通过使用 "*",如下所示:
// [assembly: AssemblyVersion("1.0.*")]
-[assembly: AssemblyVersion("1.0.0.0")]
-[assembly: AssemblyFileVersion("1.0.0.0")]
+[assembly: AssemblyVersion("1.0.0.1")]
+[assembly: AssemblyFileVersion("1.0.0.0")]
\ No newline at end of file
diff --git a/labs/CameraCard/AutoUpdate/UpdateForm.Designer.cs b/labs/CameraCard/AutoUpdate/UpdateForm.Designer.cs
index ecc98ee9..09040da3 100644
--- a/labs/CameraCard/AutoUpdate/UpdateForm.Designer.cs
+++ b/labs/CameraCard/AutoUpdate/UpdateForm.Designer.cs
@@ -39,15 +39,16 @@
| System.Windows.Forms.AnchorStyles.Right)));
this.log.Location = new System.Drawing.Point(12, 12);
this.log.Name = "log";
- this.log.Size = new System.Drawing.Size(504, 184);
+ this.log.Size = new System.Drawing.Size(597, 370);
this.log.TabIndex = 0;
this.log.Text = "";
//
// button2
//
- this.button2.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
+ this.button2.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)
+ | System.Windows.Forms.AnchorStyles.Right)));
this.button2.Enabled = false;
- this.button2.Location = new System.Drawing.Point(199, 213);
+ this.button2.Location = new System.Drawing.Point(267, 399);
this.button2.Name = "button2";
this.button2.Size = new System.Drawing.Size(88, 30);
this.button2.TabIndex = 2;
@@ -58,7 +59,7 @@
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
- this.ClientSize = new System.Drawing.Size(531, 255);
+ this.ClientSize = new System.Drawing.Size(624, 441);
this.Controls.Add(this.button2);
this.Controls.Add(this.log);
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedToolWindow;
diff --git a/labs/CameraCard/AutoUpdate/UpdateForm.cs b/labs/CameraCard/AutoUpdate/UpdateForm.cs
index e8ffb886..123b5f9c 100644
--- a/labs/CameraCard/AutoUpdate/UpdateForm.cs
+++ b/labs/CameraCard/AutoUpdate/UpdateForm.cs
@@ -2,6 +2,7 @@
using System;
using System.Diagnostics;
using System.IO;
+using System.Reflection;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Forms;
@@ -19,7 +20,7 @@ namespace AutoUpdate
{
InitializeComponent();
this.StartPosition = FormStartPosition.CenterParent;
- this.Text = "升级程序2";
+ this.Text += $" v{Assembly.GetExecutingAssembly().GetName().Version.ToString()}";
this._file = file;
this._fileName = Path.GetFileNameWithoutExtension(file);
this._path = Path.GetDirectoryName(file);
diff --git a/labs/CameraCard/AutoUpdate/bin/Debug/AutoUpdate.exe b/labs/CameraCard/AutoUpdate/bin/Debug/AutoUpdate.exe
index 7759f3af..6b163b70 100644
Binary files a/labs/CameraCard/AutoUpdate/bin/Debug/AutoUpdate.exe and b/labs/CameraCard/AutoUpdate/bin/Debug/AutoUpdate.exe differ
diff --git a/labs/CameraCard/AutoUpdate/bin/Debug/AutoUpdate.pdb b/labs/CameraCard/AutoUpdate/bin/Debug/AutoUpdate.pdb
index 818e7792..25268179 100644
Binary files a/labs/CameraCard/AutoUpdate/bin/Debug/AutoUpdate.pdb and b/labs/CameraCard/AutoUpdate/bin/Debug/AutoUpdate.pdb differ
diff --git a/labs/CameraCard/AutoUpdate/bin/Release/AutoUpdate.exe b/labs/CameraCard/AutoUpdate/bin/Release/AutoUpdate.exe
index 7cbb9996..c92545d0 100644
Binary files a/labs/CameraCard/AutoUpdate/bin/Release/AutoUpdate.exe and b/labs/CameraCard/AutoUpdate/bin/Release/AutoUpdate.exe differ
diff --git a/labs/CameraCard/AutoUpdate/bin/Release/AutoUpdate.pdb b/labs/CameraCard/AutoUpdate/bin/Release/AutoUpdate.pdb
index 53dff5d2..1e61f9ba 100644
Binary files a/labs/CameraCard/AutoUpdate/bin/Release/AutoUpdate.pdb and b/labs/CameraCard/AutoUpdate/bin/Release/AutoUpdate.pdb differ
diff --git a/labs/CameraCard/AutoUpdate/obj/Debug/AutoUpdate.csproj.GenerateResource.cache b/labs/CameraCard/AutoUpdate/obj/Debug/AutoUpdate.csproj.GenerateResource.cache
index 70554484..2417cdf3 100644
Binary files a/labs/CameraCard/AutoUpdate/obj/Debug/AutoUpdate.csproj.GenerateResource.cache and b/labs/CameraCard/AutoUpdate/obj/Debug/AutoUpdate.csproj.GenerateResource.cache differ
diff --git a/labs/CameraCard/AutoUpdate/obj/Debug/AutoUpdate.exe b/labs/CameraCard/AutoUpdate/obj/Debug/AutoUpdate.exe
index 7759f3af..6b163b70 100644
Binary files a/labs/CameraCard/AutoUpdate/obj/Debug/AutoUpdate.exe and b/labs/CameraCard/AutoUpdate/obj/Debug/AutoUpdate.exe differ
diff --git a/labs/CameraCard/AutoUpdate/obj/Debug/AutoUpdate.pdb b/labs/CameraCard/AutoUpdate/obj/Debug/AutoUpdate.pdb
index 818e7792..25268179 100644
Binary files a/labs/CameraCard/AutoUpdate/obj/Debug/AutoUpdate.pdb and b/labs/CameraCard/AutoUpdate/obj/Debug/AutoUpdate.pdb differ
diff --git a/labs/CameraCard/AutoUpdate/obj/Debug/DesignTimeResolveAssemblyReferences.cache b/labs/CameraCard/AutoUpdate/obj/Debug/DesignTimeResolveAssemblyReferences.cache
index b1d2171f..628d49c9 100644
Binary files a/labs/CameraCard/AutoUpdate/obj/Debug/DesignTimeResolveAssemblyReferences.cache and b/labs/CameraCard/AutoUpdate/obj/Debug/DesignTimeResolveAssemblyReferences.cache differ
diff --git a/labs/CameraCard/AutoUpdate/obj/Release/AutoUpdate.csproj.FileListAbsolute.txt b/labs/CameraCard/AutoUpdate/obj/Release/AutoUpdate.csproj.FileListAbsolute.txt
index e99fd644..5c13947e 100644
--- a/labs/CameraCard/AutoUpdate/obj/Release/AutoUpdate.csproj.FileListAbsolute.txt
+++ b/labs/CameraCard/AutoUpdate/obj/Release/AutoUpdate.csproj.FileListAbsolute.txt
@@ -10,3 +10,4 @@ D:\1.0\ZHXY\labs\CameraCard\AutoUpdate\obj\Release\AutoUpdate.csproj.GenerateRes
D:\1.0\ZHXY\labs\CameraCard\AutoUpdate\obj\Release\AutoUpdate.csproj.CopyComplete
D:\1.0\ZHXY\labs\CameraCard\AutoUpdate\obj\Release\AutoUpdate.exe
D:\1.0\ZHXY\labs\CameraCard\AutoUpdate\obj\Release\AutoUpdate.pdb
+D:\1.0\ZHXY\labs\CameraCard\AutoUpdate\obj\Release\AutoUpdate.csprojAssemblyReference.cache
diff --git a/labs/CameraCard/AutoUpdate/obj/Release/AutoUpdate.csproj.GenerateResource.cache b/labs/CameraCard/AutoUpdate/obj/Release/AutoUpdate.csproj.GenerateResource.cache
index 63458561..95b1dae9 100644
Binary files a/labs/CameraCard/AutoUpdate/obj/Release/AutoUpdate.csproj.GenerateResource.cache and b/labs/CameraCard/AutoUpdate/obj/Release/AutoUpdate.csproj.GenerateResource.cache differ
diff --git a/labs/CameraCard/AutoUpdate/obj/Release/AutoUpdate.exe b/labs/CameraCard/AutoUpdate/obj/Release/AutoUpdate.exe
index 7cbb9996..c92545d0 100644
Binary files a/labs/CameraCard/AutoUpdate/obj/Release/AutoUpdate.exe and b/labs/CameraCard/AutoUpdate/obj/Release/AutoUpdate.exe differ
diff --git a/labs/CameraCard/AutoUpdate/obj/Release/AutoUpdate.pdb b/labs/CameraCard/AutoUpdate/obj/Release/AutoUpdate.pdb
index 53dff5d2..1e61f9ba 100644
Binary files a/labs/CameraCard/AutoUpdate/obj/Release/AutoUpdate.pdb and b/labs/CameraCard/AutoUpdate/obj/Release/AutoUpdate.pdb differ
diff --git a/labs/CameraCard/CameraCard/CameraCard.csproj b/labs/CameraCard/CameraCard/CameraCard.csproj
index de8bf062..0c0f2cab 100644
--- a/labs/CameraCard/CameraCard/CameraCard.csproj
+++ b/labs/CameraCard/CameraCard/CameraCard.csproj
@@ -57,6 +57,7 @@
prompt
MinimumRecommendedRules.ruleset
true
+ true
@@ -77,12 +78,12 @@
-
+
Form
@@ -119,8 +120,8 @@
-
- 2.2.5
+
+ 4.2.0.20200208
diff --git a/labs/CameraCard/CameraCard/Infrastructure/AForgeCameraHelper.cs b/labs/CameraCard/CameraCard/Infrastructure/AForgeCameraHelper.cs
deleted file mode 100644
index 0620161a..00000000
--- a/labs/CameraCard/CameraCard/Infrastructure/AForgeCameraHelper.cs
+++ /dev/null
@@ -1,71 +0,0 @@
-using AForge.Video;
-using AForge.Video.DirectShow;
-using System;
-using System.Collections.Generic;
-using System.Drawing;
-using System.Linq;
-using System.Threading;
-using System.Threading.Tasks;
-
-public class AForgeCameraHelper : IDisposable, ICameraHelper
-{
- private CancellationTokenSource _cts = new CancellationTokenSource();
- private List _cameras = new List();
- private VideoCaptureDevice _videoSource;
- private List _infos;
- public Action> OnCameraChange { get; set; }
- public Action OnFrame { get; set; }
-
- public void Start()
- {
- Task.Run(async () =>
- {
- while (!this._cts.IsCancellationRequested)
- {
- this.ScanCameras();
- await Task.Delay(2000);
- }
- });
- }
-
- private void ScanCameras()
- {
- this._infos = new FilterInfoCollection(FilterCategory.VideoInputDevice).Cast().ToList();
- var cameras = this._infos.Select(o => o.Name).ToList();
- if (!this._cameras.SequenceEqual(cameras))
- {
- this._cameras = cameras;
- this.OnCameraChange?.Invoke(this._cameras);
- }
- }
-
- public void SwitchCamera(int index)
- {
- this.Stop();
- if (this._infos.Count > 0 && index < this._infos.Count)
- {
- var device = this._infos[index].MonikerString;
- this._videoSource = new VideoCaptureDevice(device);
- this._videoSource.VideoResolution = this._videoSource.VideoCapabilities.LastOrDefault();
- this._videoSource.NewFrame += new NewFrameEventHandler((s, e) =>
- {
- this.OnFrame?.Invoke(e.Frame.Clone() as Bitmap);
- });
- this._videoSource.Start();
- }
- }
-
- private void Stop()
- {
- if (this._videoSource != null && this._videoSource.IsRunning)
- {
- this._videoSource.Stop();
- }
- }
-
- public void Dispose()
- {
- this._cts.Cancel();
- this.Stop();
- }
-}
\ No newline at end of file
diff --git a/labs/CameraCard/CameraCard/Infrastructure/OpenCvSharpCameraHelper.cs b/labs/CameraCard/CameraCard/Infrastructure/OpenCvSharpCameraHelper.cs
new file mode 100644
index 00000000..3e06d0c7
--- /dev/null
+++ b/labs/CameraCard/CameraCard/Infrastructure/OpenCvSharpCameraHelper.cs
@@ -0,0 +1,87 @@
+using DirectShowLib;
+using System;
+using System.Collections.Generic;
+using System.Drawing;
+using System.Linq;
+using System.Threading;
+using System.Threading.Tasks;
+using OpenCvSharp;
+using OpenCvSharp.Extensions;
+public class OpenCvSharpCameraHelper : IDisposable, ICameraHelper
+{
+ private CancellationTokenSource _cts = new CancellationTokenSource();
+ private List _cameras = new List();
+ private VideoCapture _videoCapture;
+
+ public Action> OnCameraChange { get; set; }
+ public Action OnFrame { get; set; }
+
+ public void Start()
+ {
+ Task.Run(async () =>
+ {
+ while (!this._cts.IsCancellationRequested)
+ {
+ this.ScanCameras();
+ await Task.Delay(2000);
+ }
+ });
+ }
+
+ private void ScanCameras()
+ {
+ var devices = DsDevice.GetDevicesOfCat(FilterCategory.VideoInputDevice);
+ var cameras = devices.Select(o => o.Name).ToList();
+ foreach (var item in devices)
+ {
+ item.Dispose();
+ }
+ if (!this._cameras.SequenceEqual(cameras))
+ {
+ this._cameras = cameras;
+ this.OnCameraChange?.Invoke(this._cameras);
+ }
+ }
+
+ public void SwitchCamera(int index)
+ {
+ this.Stop();
+ this._videoCapture = new VideoCapture(index);
+ if (this._videoCapture.IsOpened())
+ {
+ Task.Run(() =>
+ {
+ while (this._videoCapture.IsOpened())
+ {
+ try
+ {
+ using (var mat = new Mat())
+ {
+ this._videoCapture.Read(mat);
+ this.OnFrame?.Invoke(mat.ToBitmap());
+ }
+ }
+ catch
+ {
+ break;
+ }
+ }
+ Stop();
+ });
+ }
+ }
+
+ private void Stop()
+ {
+ if (this._videoCapture != null && _videoCapture.IsOpened())
+ {
+ this._videoCapture.Release();
+ }
+ }
+
+ public void Dispose()
+ {
+ this._cts.Cancel();
+ this.Stop();
+ }
+}
\ No newline at end of file
diff --git a/labs/CameraCard/CameraCard/MainForm.cs b/labs/CameraCard/CameraCard/MainForm.cs
index 93a20dff..d7e36a25 100644
--- a/labs/CameraCard/CameraCard/MainForm.cs
+++ b/labs/CameraCard/CameraCard/MainForm.cs
@@ -11,7 +11,7 @@ namespace CameraCard
{
public partial class MainForm : Form
{
- private ICameraHelper _cameraHelper = new AForgeCameraHelper();
+ private ICameraHelper _cameraHelper = new OpenCvSharpCameraHelper();
private CVRHelper _cvrHelper = new CVRHelper();
@@ -108,13 +108,16 @@ namespace CameraCard
private void shotBtn_Click(object sender, EventArgs e)
{
- using (var bitmap = (this.cameraRender.Image.Clone() as Image))
+ lock (this.cameraRender.Image)
{
- using (var bitmap2 = bitmap.ClipImage(this.cameraRender.Width, this.cameraRender.Height, this._rectWidth, this._rectHeight))
+ using (var bitmap = (this.cameraRender.Image.Clone() as Image))
{
- this.photo.Image?.Dispose();
- this.photo.Image = bitmap2.ResizeImage(this._photoWidth, this._photoHeight);
- var base64Value = $"data:image/jpeg;base64,{this.photo.Image.ToBase64()}";
+ using (var bitmap2 = bitmap.ClipImage(this.cameraRender.Width, this.cameraRender.Height, this._rectWidth, this._rectHeight))
+ {
+ this.photo.Image?.Dispose();
+ this.photo.Image = bitmap2.ResizeImage(this._photoWidth, this._photoHeight);
+ var base64Value = $"data:image/jpeg;base64,{this.photo.Image.ToBase64()}";
+ }
}
}
}