This commit is contained in:
xyy
2026-01-06 13:34:31 +08:00
parent c11aac8a67
commit ffa627e2bf
23 changed files with 135 additions and 19845 deletions

View File

@@ -60,10 +60,6 @@ namespace BasicDemo
// 视频录制相关(新增)
private VideoFileWriter[] videoWriters = new VideoFileWriter[MAX_CAMERAS];
private string[] videoFilePaths = new string[MAX_CAMERAS];
private bool[] isRecording = new bool[MAX_CAMERAS];
// 构造函数
@@ -76,14 +72,14 @@ namespace BasicDemo
OnReturnRequested += returnCallback;
}
// 设置视频保存路径
if (!string.IsNullOrEmpty(videoSavePath))
{
_videoSavePath = videoSavePath;
}
//// 设置视频保存路径
//if (!string.IsNullOrEmpty(videoSavePath))
//{
// _videoSavePath = videoSavePath;
//}
// 确保保存目录存在
Directory.CreateDirectory(_videoSavePath);
//// 确保保存目录存在
//Directory.CreateDirectory(_videoSavePath);
InitializeComponent();
Control.CheckForIllegalCrossThreadCalls = false;
@@ -482,8 +478,7 @@ namespace BasicDemo
return;
}
// 2. 初始化视频录制(新增)
InitializeVideoRecording(cameraIndex);
// 2. 设置采集标志
@@ -510,8 +505,6 @@ namespace BasicDemo
return;
}
// 6. 开始录制视频(新增)
StartVideoRecording(cameraIndex);
UpdateCameraStatus(cameraIndex, "正在采集...", Color.Green);
}
@@ -524,81 +517,6 @@ namespace BasicDemo
/// <summary>
/// 初始化视频录制(新增)
/// </summary>
private void InitializeVideoRecording(int cameraIndex)
{
try
{
// 生成唯一的视频文件名
string timestamp = DateTime.Now.ToString("yyyyMMdd_HHmmss");
string fileName = $"Camera{cameraIndex + 1}_{timestamp}.mp4";
videoFilePaths[cameraIndex] = Path.Combine(_videoSavePath, fileName);
// 创建 VideoFileWriter 实例
videoWriters[cameraIndex] = new VideoFileWriter();
// 从相机获取帧率(如果支持)
try
{
MyCamera.MVCC_FLOATVALUE frameRate = new MyCamera.MVCC_FLOATVALUE();
int ret = cameras[cameraIndex].MV_CC_GetFloatValue_NET("AcquisitionFrameRate", ref frameRate);
if (ret == MyCamera.MV_OK && frameRate.fCurValue > 0)
{
_frameRate = frameRate.fCurValue;
}
}
catch
{
// 如果获取失败,使用默认帧率
_frameRate = 30.0;
}
Console.WriteLine($"相机 {cameraIndex + 1} 准备录制到: {videoFilePaths[cameraIndex]}, 帧率: {_frameRate}FPS");
}
catch (Exception ex)
{
Console.WriteLine($"初始化视频录制失败: {ex.Message}");
videoWriters[cameraIndex] = null;
}
}
/// <summary>
/// 开始录制视频(新增)- 简化版本
/// </summary>
private void StartVideoRecording(int cameraIndex)
{
if (videoWriters[cameraIndex] == null || displayBitmaps[cameraIndex] == null)
return;
try
{
int width = displayBitmaps[cameraIndex].Width;
int height = displayBitmaps[cameraIndex].Height;
// 将帧率转换为整数(四舍五入)
int fps = (int)Math.Round(_frameRate);
// 确保帧率至少为1
if (fps < 1) fps = 30;
// 创建 Rational 帧率
Accord.Math.Rational frameRateRational = new Accord.Math.Rational(fps, 1);
// 打开视频文件
videoWriters[cameraIndex].Open(videoFilePaths[cameraIndex], width, height, frameRateRational, VideoCodec.H264);
isRecording[cameraIndex] = true;
UpdateCameraStatus(cameraIndex, $"录制中: {Path.GetFileName(videoFilePaths[cameraIndex])}", Color.Green);
}
catch (Exception ex)
{
Console.WriteLine($"开始录制视频失败: {ex.Message}");
isRecording[cameraIndex] = false;
}
}
/// <summary>
/// 检查相机是否有效
@@ -636,8 +554,6 @@ namespace BasicDemo
// 3. 停止相机采集
cameras[cameraIndex].MV_CC_StopGrabbing_NET();
// 4. 停止视频录制(新增)
StopVideoRecording(cameraIndex);
// 4. 清理资源
CleanupCameraResources(cameraIndex);
@@ -651,37 +567,7 @@ namespace BasicDemo
}
/// <summary>
/// 停止视频录制(新增)
/// </summary>
private void StopVideoRecording(int cameraIndex)
{
try
{
if (videoWriters[cameraIndex] != null && isRecording[cameraIndex])
{
videoWriters[cameraIndex].Close();
isRecording[cameraIndex] = false;
Console.WriteLine($"相机 {cameraIndex + 1} 视频已保存到: {videoFilePaths[cameraIndex]}");
// 可选:显示保存路径
UpdateCameraStatus(cameraIndex, $"视频已保存", Color.Blue);
}
}
catch (Exception ex)
{
Console.WriteLine($"停止视频录制异常: {ex.Message}");
}
finally
{
if (videoWriters[cameraIndex] != null)
{
videoWriters[cameraIndex].Dispose();
videoWriters[cameraIndex] = null;
}
}
}
private bool PrepareForGrabbing(int cameraIndex)
{
@@ -920,36 +806,7 @@ namespace BasicDemo
displayBitmaps[cameraIndex].UnlockBits(bitmapData);
}
// 录制视频(新增)
if (isRecording[cameraIndex] && videoWriters[cameraIndex] != null && videoWriters[cameraIndex].IsOpen)
{
// 简单的帧率控制
DateTime now = DateTime.Now;
if ((now - lastWriteTime).TotalMilliseconds >= (1000.0 / _frameRate) || framesWritten == 0)
{
try
{
// 锁定以避免线程冲突
Bitmap frameToWrite;
lock (locks[cameraIndex])
{
// 克隆Bitmap用于写入避免资源冲突
frameToWrite = (Bitmap)displayBitmaps[cameraIndex].Clone();
}
videoWriters[cameraIndex].WriteVideoFrame(frameToWrite);
frameToWrite.Dispose();
framesWritten++;
lastWriteTime = now;
}
catch (Exception ex)
{
Console.WriteLine($"写入视频帧失败: {ex.Message}");
}
}
}
// 使用SDK显示
displayInfo.hWnd = pictureBoxes[cameraIndex].Handle;
displayInfo.pData = frameOut.pBufAddr;
@@ -1004,27 +861,7 @@ namespace BasicDemo
displayBufSizes[cameraIndex] = 0;
// 清理视频录制资源(新增)
if (videoWriters[cameraIndex] != null)
{
try
{
if (isRecording[cameraIndex])
{
videoWriters[cameraIndex].Close();
isRecording[cameraIndex] = false;
}
videoWriters[cameraIndex].Dispose();
}
catch (Exception ex)
{
Console.WriteLine($"清理视频录制资源异常: {ex.Message}");
}
finally
{
videoWriters[cameraIndex] = null;
}
}
}
/// <summary>

View File

@@ -0,0 +1,120 @@
<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
Microsoft ResX Schema
Version 2.0
The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes
associated with the data types.
Example:
... ado.net/XML headers & schema ...
<resheader name="resmimetype">text/microsoft-resx</resheader>
<resheader name="version">2.0</resheader>
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
<value>[base64 mime encoded serialized .NET Framework object]</value>
</data>
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
<comment>This is a comment</comment>
</data>
There are any number of "resheader" rows that contain simple
name/value pairs.
Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support
text/value conversion through the TypeConverter architecture.
Classes that don't support this are serialized and stored with the
mimetype set.
The mimetype is used for serialized objects, and tells the
ResXResourceReader how to depersist the object. This is currently not
extensible. For a given mimetype the value must be set accordingly:
Note - application/x-microsoft.net.object.binary.base64 is the format
that the ResXResourceWriter will generate, however the reader can
read any of the formats listed below.
mimetype: application/x-microsoft.net.object.binary.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.soap.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.bytearray.base64
value : The object must be serialized into a byte array
: using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding.
-->
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="metadata">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="name" use="required" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
<xsd:complexType>
<xsd:attribute name="alias" type="xsd:string" />
<xsd:attribute name="name" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
</root>

View File

@@ -140,6 +140,9 @@
</Compile>
<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<EmbeddedResource Include="AutoCameraForm.resx">
<DependentUpon>AutoCameraForm.cs</DependentUpon>
</EmbeddedResource>
<EmbeddedResource Include="BasicDemo.en-US.resx">
<DependentUpon>BasicDemo.cs</DependentUpon>
</EmbeddedResource>

View File

@@ -14,7 +14,7 @@ using System.Reflection;
[assembly: System.Reflection.AssemblyCompanyAttribute("外科辅料和患者防护罩激光抗性测试仪")]
[assembly: System.Reflection.AssemblyConfigurationAttribute("Debug")]
[assembly: System.Reflection.AssemblyFileVersionAttribute("1.0.0.0")]
[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+6bb75650af99fa47d7897eafb2313a2fa238d5f8")]
[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+c11aac8a677e520f36b77c52aba9a1cab9bafcaa")]
[assembly: System.Reflection.AssemblyProductAttribute("外科辅料和患者防护罩激光抗性测试仪")]
[assembly: System.Reflection.AssemblyTitleAttribute("外科辅料和患者防护罩激光抗性测试仪")]
[assembly: System.Reflection.AssemblyVersionAttribute("1.0.0.0")]

View File

@@ -1 +1 @@
b4c497e6e79f0a362f8b6e1f5947c60bf1dc61cfc830643b182748637ce91182
b489adfdbed1114a62fd5a549649aa56c8419bf06d0972649e23dbf42cdb8395

View File

@@ -12,7 +12,6 @@ D:\软件\Z714System\外科辅料和患者防护罩激光抗性测试仪\外科
D:\软件\Z714System\外科辅料和患者防护罩激光抗性测试仪\外科辅料和患者防护罩激光抗性测试仪\外科辅料和患者防护罩激光抗性测试仪\bin\Debug\net8.0-windows7.0\外科辅料和患者防护罩激光抗性测试仪.runtimeconfig.json
D:\软件\Z714System\外科辅料和患者防护罩激光抗性测试仪\外科辅料和患者防护罩激光抗性测试仪\外科辅料和患者防护罩激光抗性测试仪\bin\Debug\net8.0-windows7.0\外科辅料和患者防护罩激光抗性测试仪.dll
D:\软件\Z714System\外科辅料和患者防护罩激光抗性测试仪\外科辅料和患者防护罩激光抗性测试仪\外科辅料和患者防护罩激光抗性测试仪\bin\Debug\net8.0-windows7.0\外科辅料和患者防护罩激光抗性测试仪.pdb
D:\软件\Z714System\外科辅料和患者防护罩激光抗性测试仪\外科辅料和患者防护罩激光抗性测试仪\外科辅料和患者防护罩激光抗性测试仪\bin\Debug\net8.0-windows7.0\Accord.dll
D:\软件\Z714System\外科辅料和患者防护罩激光抗性测试仪\外科辅料和患者防护罩激光抗性测试仪\外科辅料和患者防护罩激光抗性测试仪\bin\Debug\net8.0-windows7.0\NModbus.dll
D:\软件\Z714System\外科辅料和患者防护罩激光抗性测试仪\外科辅料和患者防护罩激光抗性测试仪\外科辅料和患者防护罩激光抗性测试仪\bin\Debug\net8.0-windows7.0\SunnyUI.dll
D:\软件\Z714System\外科辅料和患者防护罩激光抗性测试仪\外科辅料和患者防护罩激光抗性测试仪\外科辅料和患者防护罩激光抗性测试仪\bin\Debug\net8.0-windows7.0\SunnyUI.Common.dll
@@ -36,10 +35,8 @@ D:\软件\Z714System\外科辅料和患者防护罩激光抗性测试仪\外科
D:\软件\Z714System\外科辅料和患者防护罩激光抗性测试仪\外科辅料和患者防护罩激光抗性测试仪\外科辅料和患者防护罩激光抗性测试仪\bin\Debug\net8.0-windows7.0\runtimes\unix\lib\net8.0\System.IO.Ports.dll
D:\软件\Z714System\外科辅料和患者防护罩激光抗性测试仪\外科辅料和患者防护罩激光抗性测试仪\外科辅料和患者防护罩激光抗性测试仪\bin\Debug\net8.0-windows7.0\runtimes\win\lib\net8.0\System.IO.Ports.dll
D:\软件\Z714System\外科辅料和患者防护罩激光抗性测试仪\外科辅料和患者防护罩激光抗性测试仪\外科辅料和患者防护罩激光抗性测试仪\bin\Debug\net8.0-windows7.0\NModbus4.dll
D:\软件\Z714System\外科辅料和患者防护罩激光抗性测试仪\外科辅料和患者防护罩激光抗性测试仪\外科辅料和患者防护罩激光抗性测试仪\bin\Debug\net8.0-windows7.0\Accord.Video.FFMPEG.dll
D:\软件\Z714System\外科辅料和患者防护罩激光抗性测试仪\外科辅料和患者防护罩激光抗性测试仪\外科辅料和患者防护罩激光抗性测试仪\bin\Debug\net8.0-windows7.0\BasicDemo_CS.pdb
D:\软件\Z714System\外科辅料和患者防护罩激光抗性测试仪\外科辅料和患者防护罩激光抗性测试仪\外科辅料和患者防护罩激光抗性测试仪\bin\Debug\net8.0-windows7.0\NModbus4.xml
D:\软件\Z714System\外科辅料和患者防护罩激光抗性测试仪\外科辅料和患者防护罩激光抗性测试仪\外科辅料和患者防护罩激光抗性测试仪\bin\Debug\net8.0-windows7.0\Accord.Video.FFMPEG.xml
D:\软件\Z714System\外科辅料和患者防护罩激光抗性测试仪\外科辅料和患者防护罩激光抗性测试仪\外科辅料和患者防护罩激光抗性测试仪\bin\Debug\net8.0-windows7.0\en-US\BasicDemo_CS.resources.dll
D:\软件\Z714System\外科辅料和患者防护罩激光抗性测试仪\外科辅料和患者防护罩激光抗性测试仪\外科辅料和患者防护罩激光抗性测试仪\bin\Debug\net8.0-windows7.0\zh-CHS\BasicDemo_CS.resources.dll
D:\软件\Z714System\外科辅料和患者防护罩激光抗性测试仪\外科辅料和患者防护罩激光抗性测试仪\外科辅料和患者防护罩激光抗性测试仪\obj\Debug\net8.0-windows7.0\外科辅料和患者防护罩激光抗性测试仪.csproj.AssemblyReference.cache
@@ -60,6 +57,5 @@ D:\软件\Z714System\外科辅料和患者防护罩激光抗性测试仪\外科
D:\软件\Z714System\外科辅料和患者防护罩激光抗性测试仪\外科辅料和患者防护罩激光抗性测试仪\外科辅料和患者防护罩激光抗性测试仪\obj\Debug\net8.0-windows7.0\外科辅料和患者防护罩激光抗性测试仪.pdb
D:\软件\Z714System\外科辅料和患者防护罩激光抗性测试仪\外科辅料和患者防护罩激光抗性测试仪\外科辅料和患者防护罩激光抗性测试仪\obj\Debug\net8.0-windows7.0\外科辅料和患者防护罩激光抗性测试仪.genruntimeconfig.cache
D:\软件\Z714System\外科辅料和患者防护罩激光抗性测试仪\外科辅料和患者防护罩激光抗性测试仪\外科辅料和患者防护罩激光抗性测试仪\obj\Debug\net8.0-windows7.0\ref\外科辅料和患者防护罩激光抗性测试仪.dll
D:\软件\Z714System\外科辅料和患者防护罩激光抗性测试仪\外科辅料和患者防护罩激光抗性测试仪\外科辅料和患者防护罩激光抗性测试仪\bin\Debug\net8.0-windows7.0\Accord.xml
D:\软件\Z714System\外科辅料和患者防护罩激光抗性测试仪\外科辅料和患者防护罩激光抗性测试仪\外科辅料和患者防护罩激光抗性测试仪\bin\Debug\net8.0-windows7.0\BasicDemo_CS.exe
D:\软件\Z714System\外科辅料和患者防护罩激光抗性测试仪\外科辅料和患者防护罩激光抗性测试仪\外科辅料和患者防护罩激光抗性测试仪\bin\Debug\net8.0-windows7.0\BasicDemo_CS.exe.config