C#:<SubType>Component</SubType>

在C#项目中,<SubType>Component</SubType>用于指定文件类型,影响Visual Studio的打开方式和编译行为。
1、作用与使用场景

    ‌可视化编辑器关联‌:当SubType设为Component时,Visual Studio会使用可视化设计器打开文件(如WinForm窗体文件) 。若设为Code,则使用代码编辑器 。 ‌
    ‌编译流程控制‌:在工作流或组件化项目中,Component类型可能触发特定编译逻辑(如SequentialWorkflowActivity的初始化) 。 ‌

2、配置方法

    ‌项目文件修改‌:在.csproj文件中,为<Compile>节点添加<SubType>Component</SubType> 。例如:
    <Compile Include="Form1.cs">
      <SubType>Component</SubType>
    </Compile>

    ‌代码文件关联‌:确保文件扩展名(如.cs)与SubType匹配,否则可能无法正确识别 。 ‌

3、注意事项

    ‌兼容性验证‌:修改后需重新加载项目或重启Visual Studio以生效 。 ‌
    ‌类型冲突‌:避免与<SubType>Code</SubType>混淆,后者适用于纯代码文件 。

这是我整个csproj文件。里面显示的内容就是缺失{0}{{{<?xml version="1.0" encoding="utf-8"?> <Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> <Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" /> <PropertyGroup> <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration> <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform> <ProjectGuid>{1A8E2AB2-6591-498F-9439-CF15A0C3C8E3}</ProjectGuid> <OutputType>Exe</OutputType> <RootNamespace>Vertical</RootNamespace> <AssemblyName>Vertical</AssemblyName> <TargetFrameworkVersion>v4.7.2</TargetFrameworkVersion> <FileAlignment>512</FileAlignment> <AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects> <Deterministic>true</Deterministic> <NuGetPackageImportStamp> </NuGetPackageImportStamp> </PropertyGroup> <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' "> <PlatformTarget>x64</PlatformTarget> <DebugSymbols>true</DebugSymbols> <DebugType>full</DebugType> <Optimize>false</Optimize> <OutputPath>bin\Debug\</OutputPath> <DefineConstants>DEBUG;TRACE</DefineConstants> <ErrorReport>prompt</ErrorReport> <WarningLevel>4</WarningLevel> </PropertyGroup> <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' "> <PlatformTarget>AnyCPU</PlatformTarget> <DebugType>pdbonly</DebugType> <Optimize>true</Optimize> <OutputPath>bin\Release\</OutputPath> <DefineConstants>TRACE</DefineConstants> <ErrorReport>prompt</ErrorReport> <WarningLevel>4</WarningLevel> </PropertyGroup> <PropertyGroup> <StartupObject /> </PropertyGroup> <ItemGroup> <Reference Include="Newtonsoft.Json, Version=13.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL"> <HintPath>packages\Newtonsoft.Json.13.0.3\lib\net45\Newtonsoft.Json.dll</HintPath> </Reference> <Reference Include="System" /> <Reference Include="System.ComponentModel.DataAnnotations" /> <Reference Include="System.Core" /> <Reference Include="System.Data.SQLite, Version=1.0.119.0, Culture=neutral, PublicKeyToken=db937bc2d44ff139, processorArchitecture=MSIL"> <HintPath>packages\System.Data.SQLite.2.0.1\lib\net471\System.Data.SQLite.dll</HintPath> </Reference> <Reference Include="System.Transactions" /> <Reference Include="System.Xml.Linq" /> <Reference Include="System.Data.DataSetExtensions" /> <Reference Include="Microsoft.CSharp" /> <Reference Include="System.Data" /> <Reference Include="System.Deployment" /> <Reference Include="System.Drawing" /> <Reference Include="System.Net.Http" /> <Reference Include="System.Windows.Forms" /> <Reference Include="System.Xml" /> </ItemGroup> <ItemGroup> <Compile Include="Dal\Configurations\ConfigInitializer.cs" /> <Compile Include="Dal\DataContext.cs" /> <Compile Include="Dal\Configurations\FilePathConfig.cs" /> <Compile Include="Dal\Configurations\DatabaseConfig.cs" /> <Compile Include="Dal\Repositories\UserRepository.cs" /> <Compile Include="Dal\Repositories\JsonConfigRepository.cs" /> <Compile Include="Dal\Repositories\SqliteDataRepository.cs" /> <Compile Include="Models\FunctionValueProcessor.cs" /> <Compile Include="Models\ListValueProcessor.cs" /> <Compile Include="Models\MappingValueProcessor.cs" /> <Compile Include="question.cs" /> <Compile Include="Commands\ICommands.cs" /> <Compile Include="Commands\RelayCommand.cs" /> <Compile Include="Dal\Entities\LogEntity.cs" /> <Compile Include="Dal\Entities\UserEntity.cs" /> <Compile Include="Dal\Entities\RowDataEntity.cs" /> <Compile Include="Dal\Interfaces\IUserRepository.cs" /> <Compile Include="Dal\Interfaces\IConfigRepository.cs" /> <Compile Include="Dal\Interfaces\IDataRepository.cs" /> <Compile Include="Dal\Interfaces\IRepository.cs" /> <Compile Include="Dal\Mappers\DataMapper.cs" /> <Compile Include="Infrastructure\DataBinding.cs" /> <Compile Include="Infrastructure\INotifyPropertyChangedBase.cs" /> <Compile Include="Models\CheckBoxControlModel.cs" /> <Compile Include="Models\ApplicationDataModel.cs" /> <Compile Include="Models\AttributeValueConfig.cs" /> <Compile Include="Models\DataGridViewModel.cs" /> <Compile Include="Models\NavigationState.cs" /> <Compile Include="Models\TransformFunction.cs" /> <Compile Include="Models\UserModel.cs" /> <Compile Include="Models\PageModel.cs" /> <Compile Include="Models\NavigationModel.cs" /> <Compile Include="Models\RowItemModel.cs" /> <Compile Include="Models\ComboBoxControlModel.cs" /> <Compile Include="Models\ComboBoxItem.cs" /> <Compile Include="Models\TextBoxControlModel.cs" /> <Compile Include="Models\InputControlBase.cs" /> <Compile Include="Models\IControlData.cs" /> <Compile Include="Models\ValidationRule.cs" /> <Compile Include="Models\FontInfoModel.cs" /> <Compile Include="Models\ControlTypeEnum.cs" /> <Compile Include="Test\ExtendedTest.cs" /> <Compile Include="Test\TestHelpers.cs" /> <Compile Include="Test\TestProgram.cs" /> <Compile Include="Views\BindingManagers\IBindingManager.cs" /> <Compile Include="Views\Form1.cs"> <SubType>Form</SubType> </Compile> <Compile Include="Views\Form1.Designer.cs"> <DependentUpon>Form1.cs</DependentUpon> </Compile> <Compile Include="Models\ModelBase.cs" /> <Compile Include="Program.cs" /> <Compile Include="Properties\AssemblyInfo.cs" /> <Compile Include="ViewModels\MainViewModel.cs" /> <Compile Include="ViewModels\ViewModelBase.cs" /> <EmbeddedResource Include="Views\Form1.resx"> <DependentUpon>Form1.cs</DependentUpon> </EmbeddedResource> <EmbeddedResource Include="Properties\Resources.resx"> <Generator>ResXFileCodeGenerator</Generator> <LastGenOutput>Resources.Designer.cs</LastGenOutput> <SubType>Designer</SubType> </EmbeddedResource> <Compile Include="Properties\Resources.Designer.cs"> <AutoGen>True</AutoGen> <DependentUpon>Resources.resx</DependentUpon> </Compile> <None Include="packages.config" /> <None Include="Properties\Settings.settings"> <Generator>SettingsSingleFileGenerator</Generator> <LastGenOutput>Settings.Designer.cs</LastGenOutput> </None> <Compile Include="Properties\Settings.Designer.cs"> <AutoGen>True</AutoGen> <DependentUpon>Settings.settings</DependentUpon> <DesignTimeSharedInput>True</DesignTimeSharedInput> </Compile> </ItemGroup> <ItemGroup> <None Include="App.config" /> </ItemGroup> <ItemGroup /> <ItemGroup> <EmbeddedResource Include="Resources\InitDatabase.sql" /> <None Update="Resources\InitDatabase.sql"> <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> </None> </ItemGroup> <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" /> <Import Project="packages\Stub.System.Data.SQLite.Core.NetFramework.1.0.119.0\build\net46\Stub.System.Data.SQLite.Core.NetFramework.targets" Condition="Exists('packages\Stub.System.Data.SQLite.Core.NetFramework.1.0.119.0\build\net46\Stub.System.Data.SQLite.Core.NetFramework.targets')" /> <Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild"> <PropertyGroup> <ErrorText>这台计算机上缺少此项目引用的 NuGet 程序包。使用“NuGet 程序包还原”可下载这些程序包。有关更多信息,请参见 http://go.microsoft.com/fwlink/?LinkID=322105。缺少的文件是 {0}。</ErrorText> </PropertyGroup> <Error Condition="!Exists('packages\Stub.System.Data.SQLite.Core.NetFramework.1.0.119.0\build\net46\Stub.System.Data.SQLite.Core.NetFramework.targets')" Text="$([System.String]::Format('$(ErrorText)', 'packages\Stub.System.Data.SQLite.Core.NetFramework.1.0.119.0\build\net46\Stub.System.Data.SQLite.Core.NetFramework.targets'))" /> </Target> </Project>}}}帮我看看问题出在哪里?
09-10
Form2.Designer.cs namespace CAD加入打包exe插件 { partial class Form2 { /// <summary> /// Required designer variable. /// </summary> private System.ComponentModel.IContainer components = null; /// <summary> /// Clean up any resources being used. /// </summary> /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param> protected override void Dispose(bool disposing) { if (disposing && (components != null)) { components.Dispose(); } base.Dispose(disposing); } #region Windows Form Designer generated code /// <summary> /// Required method for Designer support - do not modify /// the contents of this method with the code editor. /// </summary> private void InitializeComponent() { this.SuspendLayout(); // // Form2 // this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.ClientSize = new System.Drawing.Size(800, 450); this.Name = "Form2"; this.Text = "Form2"; this.Load += new System.EventHandler(this.Form2_Load); this.ResumeLayout(false); } #endregion } } 严重性 代码 说明 行 详细信息 错误(活动) CS1061 “Form2”未包含“ResumeLayout”的定义,并且找不到可接受第一个“Form2”类型参数的可访问扩展方法“ResumeLayout”(是否缺少 using 指令或程序集引用?) 41 错误(活动) CS0117 “object”未包含“Dispose”的定义 20 错误(活动) CS1061 “Form2”未包含“Text”的定义,并且找不到可接受第一个“Form2”类型参数的可访问扩展方法“Text”(是否缺少 using 指令或程序集引用?) 39 错误(活动) CS1061 “Form2”未包含“SuspendLayout”的定义,并且找不到可接受第一个“Form2”类型参数的可访问扩展方法“SuspendLayout”(是否缺少 using 指令或程序集引用?) 31 错误(活动) CS1061 “Form2”未包含“Name”的定义,并且找不到可接受第一个“Form2”类型参数的可访问扩展方法“Name”(是否缺少 using 指令或程序集引用?) 38 错误(活动) CS1061 “Form2”未包含“Load”的定义,并且找不到可接受第一个“Form2”类型参数的可访问扩展方法“Load”(是否缺少 using 指令或程序集引用?) 40 错误(活动) CS1061 “Form2”未包含“Form2_Load”的定义,并且找不到可接受第一个“Form2”类型参数的可访问扩展方法“Form2_Load”(是否缺少 using 指令或程序集引用?) 40 错误(活动) CS1061 “Form2”未包含“ClientSize”的定义,并且找不到可接受第一个“Form2”类型参数的可访问扩展方法“ClientSize”(是否缺少 using 指令或程序集引用?) 37 错误(活动) CS1061 “Form2”未包含“AutoScaleMode”的定义,并且找不到可接受第一个“Form2”类型参数的可访问扩展方法“AutoScaleMode”(是否缺少 using 指令或程序集引用?) 36 错误(活动) CS1061 “Form2”未包含“AutoScaleDimensions”的定义,并且找不到可接受第一个“Form2”类型参数的可访问扩展方法“AutoScaleDimensions”(是否缺少 using 指令或程序集引用?) 35 错误(活动) CS0115 “Form2.Dispose(bool)”: 没有找到适合的方法来重写 14
09-25
namespace AIPlateformSystem { public partial class FrmCameraOnnxTest : Form { public FrmCameraOnnxTest() { InitializeComponent(); InitializeOpenGLControl(); } // OpenCV 视频捕获 private VideoCapture _capture; private bool _isRunning; // OpenGL 组件 private GLControl _glControl; private int _textureId; private Size _videoSize = new Size(1920, 1080); // 默认视频尺寸 private void InitializeOpenGLControl() { // 创建 OpenGL 控件 _glControl = new GLControl(new GraphicsMode(32, 24, 0, 4)) { Dock = DockStyle.Fill, BackColor = System.Drawing.Color.Black }; _glControl.Load += GlControl_Load; _glControl.Paint += GlControl_Paint; _glControl.Resize += GlControl_Resize; this.Controls.Add(_glControl); } private void GlControl_Load(object sender, EventArgs e) { // 初始化 OpenGL GL.Enable(EnableCap.Texture2D); GL.GenTextures(1, out _textureId); GL.BindTexture(TextureTarget.Texture2D, _textureId); // 设置纹理参数 GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMinFilter, (int)TextureMinFilter.Linear); GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMagFilter, (int)TextureMagFilter.Linear); // 创建空纹理 GL.TexImage2D(TextureTarget.Texture2D, 0, PixelInternalFormat.Rgb, _videoSize.Width, _videoSize.Height, 0, PixelFormat.Bgr, PixelType.UnsignedByte, IntPtr.Zero); } private void GlControl_Paint(object sender, PaintEventArgs e) { GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit); // 绑定纹理并渲染到全屏四边形 GL.BindTexture(TextureTarget.Texture2D, _textureId); GL.Begin(PrimitiveType.Quads); GL.TexCoord2(0, 1); GL.Vertex2(-1, -1); // 左下 GL.TexCoord2(1, 1); GL.Vertex2(1, -1); // 右下 GL.TexCoord2(1, 0); GL.Vertex2(1, 1); // 右上 GL.TexCoord2(0, 0); GL.Vertex2(-1, 1); // 左上 GL.End(); _glControl.SwapBuffers(); // 显示渲染结果 } private void GlControl_Resize(object sender, EventArgs e) { // 调整视口大小 GL.Viewport(0, 0, _glControl.Width, _glControl.Height); GL.MatrixMode(MatrixMode.Projection); GL.LoadIdentity(); GL.Ortho(-1, 1, -1, 1, -1, 1); _glControl.Invalidate(); } private void ProcessVideo() { using (Mat frame = new Mat()) { while (_isRunning && _capture != null && _capture.IsOpened()) { if (_capture.Read(frame) && !frame.Empty()) { // 使用委托安全更新OpenGL纹理 _glControl.Invoke((MethodInvoker)delegate { UpdateTexture(frame); _glControl.Invalidate(); // 触发重绘 }); RenderFrame(frame); } Thread.Sleep(1); // 最小延迟 } } } // 关键方法:将Mat数据更新到OpenGL纹理 private void UpdateTexture(Mat frame) { GL.BindTexture(TextureTarget.Texture2D, _textureId); // 直接传输Mat数据到GPU (避免CPU复制) GL.TexSubImage2D(TextureTarget.Texture2D, 0, 0, 0, frame.Width, frame.Height, PixelFormat.Bgr, PixelType.UnsignedByte, frame.Data); } private void StartVideo() { try { // 初始化视频捕获 (替换为你的RTSP地址) string rtsp_url = "rtsp://admin:P2%40ink668803@10.21.0.188:554/cam/realmonitor?channel=1&subtype=0"; string optimizedUrl = "rtsp://admin:P2%40ink668803@10.21.0.188:554/cam/realmonitor?channel=1&subtype=0&transport=tcp"; _capture = new VideoCapture(rtsp_url); if (!_capture.IsOpened()) throw new Exception("无法打开视频流"); // 获取实际视频尺寸 _videoSize = new Size( (int)_capture.Get(VideoCaptureProperties.FrameWidth), (int)_capture.Get(VideoCaptureProperties.FrameHeight) ); _isRunning = true; new Thread(ProcessVideo).Start(); } catch (Exception ex) { MessageBox.Show($"初始化错误: {ex.Message}"); } } private Mat currentFrame = new Mat(); private int frameCount=0; public string[] class_names; public int class_num; DateTime dt1 = DateTime.Now; DateTime dt2 = DateTime.Now; int input_height; int input_width; float ratio_height; float ratio_width; // 在渲染循环中添加推理 private List<DetectionResult> currentResults = new List<DetectionResult>(); public void RenderFrame(Mat currentFrame) { // 调整图像尺寸到640×640 int targetWidth = 640; int targetHeight = 640; // 计算保持宽高比的缩放比例 double scaleWidth = (double)targetWidth / currentFrame.Width; double scaleHeight = (double)targetHeight / currentFrame.Height; double scale = Math.Min(scaleWidth, scaleHeight); // 计算缩放后的尺寸 int width = (int)(currentFrame.Width * scale); int height = (int)(currentFrame.Height * scale); // 调整图像尺寸 // Mat resizedImg = currentFrame.Resize(width, height); // 如果需要强制设置为640x640(可能会变形),可以使用以下代码: Mat resizedImg = new Mat(new Size(targetWidth, targetHeight), currentFrame.Type()); Cv2.Resize(currentFrame, resizedImg, new Size(targetWidth, targetHeight)); GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit); // 1. 上传视频帧到GPU纹理 UploadFrameToTexture(resizedImg); // 2. 执行模型推理(每5帧一次) if (frameCount % 5 == 0) { currentResults = RunInference(resizedImg.Clone()); } // 3. 绘制视频纹理 // GL.BindTexture(TextureTarget.Texture2D, videoTextureID); // DrawFullscreenQuad(); // 4. 绘制推理结果 DrawDetectionResults(currentResults); // glControl.SwapBuffers(); frameCount++; } InferenceSession onnx_session; int box_num; float conf_threshold; float nms_threshold; List<DetectionResult> RunInference(Mat frame) { Mat input_img = new Mat(); input_img = frame; Tensor<float> input_tensor = new DenseTensor<float>(new[] { 1, 3, 640, 640 }); for (int y = 0; y < input_img.Height; y++) { for (int x = 0; x < input_img.Width; x++) { input_tensor[0, 0, y, x] = input_img.At<Vec3b>(y, x)[0] / 255f; input_tensor[0, 1, y, x] = input_img.At<Vec3b>(y, x)[1] / 255f; input_tensor[0, 2, y, x] = input_img.At<Vec3b>(y, x)[2] / 255f; } } List<NamedOnnxValue> input_container = new List<NamedOnnxValue> { NamedOnnxValue.CreateFromTensor("images", input_tensor) }; // 执行推理 var inputs = new List<NamedOnnxValue> { NamedOnnxValue.CreateFromTensor("images", input_tensor) }; //推理 dt1 = DateTime.Now; var ort_outputs = onnx_session.Run(input_container).ToArray(); dt2 = DateTime.Now; float[] data = Transpose(ort_outputs[0].AsTensor<float>().ToArray(), 4 + class_num, box_num); float[] confidenceInfo = new float[class_num]; float[] rectData = new float[4]; List<DetectionResult> detResults = new List<DetectionResult>(); for (int i = 0; i < box_num; i++) { Array.Copy(data, i * (class_num + 4), rectData, 0, 4); Array.Copy(data, i * (class_num + 4) + 4, confidenceInfo, 0, class_num); float score = confidenceInfo.Max(); // 获取最大值 int maxIndex = Array.IndexOf(confidenceInfo, score); // 获取最大值的位置 int _centerX = (int)(rectData[0] * ratio_width); int _centerY = (int)(rectData[1] * ratio_height); int _width = (int)(rectData[2] * ratio_width); int _height = (int)(rectData[3] * ratio_height); detResults.Add(new DetectionResult( maxIndex, class_names[maxIndex], new Rect(_centerX - _width / 2, _centerY - _height / 2, _width, _height), score)); } //NMS CvDnn.NMSBoxes(detResults.Select(x => x.Rect), detResults.Select(x => x.Confidence), conf_threshold, nms_threshold, out int[] indices); detResults = detResults.Where((x, index) => indices.Contains(index)).ToList(); int personCount = detResults.Where(w => w.ClassId == 0).Count(); //绘制结果 Mat result_image = input_img.Clone(); foreach (DetectionResult r in detResults) { Cv2.PutText(result_image, $"{r.Class}:{r.Confidence:P0}", new OpenCvSharp.Point(r.Rect.TopLeft.X, r.Rect.TopLeft.Y - 10), HersheyFonts.HersheySimplex, 1, Scalar.Red, 2); Cv2.Rectangle(result_image, r.Rect, Scalar.Red, thickness: 2); } pictureBox2.Invoke((MethodInvoker)delegate { if (result_image != null) { pictureBox2.Image = new Bitmap(result_image.ToMemoryStream()); } textBox1.Text = "推理耗时:" + (dt2 - dt1).TotalMilliseconds + "ms"; }); // 解析结果 return detResults; } void DrawDetectionResults(List<DetectionResult> results) { GL.Disable(EnableCap.Texture2D); GL.LineWidth(2.0f); foreach (var r in results) { // 将矩形坐标转换到屏幕空间 [-1,1] float x0 = (r.Rect.X / (float)currentFrame.Width) * 2 - 1; float y0 = (r.Rect.Y / (float)currentFrame.Height) * 2 - 1; float x1 = ((r.Rect.X + r.Rect.Width) / (float)currentFrame.Width) * 2 - 1; float y1 = ((r.Rect.Y + r.Rect.Height) / (float)currentFrame.Height) * 2 - 1; // 绘制边界框 GL.Color3(1.0f, 0.0f, 0.0f); // 红色 GL.Begin(PrimitiveType.LineLoop); GL.Vertex2(x0, y0); GL.Vertex2(x1, y0); GL.Vertex2(x1, y1); GL.Vertex2(x0, y1); GL.End(); // 绘制标签 //DrawText($"{r.Class}:{r.Confidence:F2}", // x0, y0 - 0.05f, 0.03f); } GL.Enable(EnableCap.Texture2D); } // 使用生产者-消费者模式 private BlockingCollection<Mat> inferenceQueue = new BlockingCollection<Mat>(5); private ConcurrentQueue<List<DetectionResult>> resultsQueue = new ConcurrentQueue<List<DetectionResult>>(); // 专用推理线程 private void StartInferenceThread() { new Thread(() => { while (true) { if (inferenceQueue.TryTake(out Mat frame, 50)) { var results = RunInference(frame); resultsQueue.Enqueue(results); frame.Dispose(); } } }).Start(); } //// 渲染循环中 //if (frameCount % 5 == 0 && inferenceQueue.Count< 3) //{ // inferenceQueue.Add(currentFrame.Clone()); //} //if (resultsQueue.TryDequeue(out var newResults)) //{ // currentResults = newResults; //} /// <summary> /// 上传视频帧到GPU纹理 /// </summary> /// <param name="frame"></param> private void UploadFrameToTexture(Mat frame) { // GL.BindTexture(TextureTarget.Texture2D, videoTextureID); GL.TexImage2D(TextureTarget.Texture2D, 0, PixelInternalFormat.Rgba, frame.Width, frame.Height, 0, PixelFormat.Bgra, PixelType.UnsignedByte, frame.Data); } public static Mat PreprocessFrame(Mat inputFrame, Size targetSize , NormTypes normType = NormTypes.MinMax, double minVal = 0, double maxVal = 1 ) { // 1. 颜色空间转换:BGR→RGB Mat rgbFrame = new Mat(); Cv2.CvtColor(inputFrame, rgbFrame, ColorConversionCodes.BGR2RGB); // 2. 尺寸缩放 Mat resizedFrame = new Mat(); Cv2.Resize(rgbFrame, resizedFrame, targetSize, 0, 0, InterpolationFlags.Linear); // 3. 数据类型转换 Mat convertedFrame = new Mat(); // resizedFrame.ConvertTo(convertedFrame, outputType); // 4. 归一化处理 Mat normalizedFrame = new Mat(); Cv2.Normalize(convertedFrame, normalizedFrame, minVal, maxVal, normType); // 释放中间资源 rgbFrame.Dispose(); resizedFrame.Dispose(); convertedFrame.Dispose(); return normalizedFrame; } public unsafe float[] Transpose(float[] tensorData, int rows, int cols) { float[] transposedTensorData = new float[tensorData.Length]; fixed (float* pTensorData = tensorData) { fixed (float* pTransposedData = transposedTensorData) { for (int i = 0; i < rows; i++) { for (int j = 0; j < cols; j++) { int index = i * cols + j; int transposedIndex = j * rows + i; pTransposedData[transposedIndex] = pTensorData[index]; } } } } return transposedTensorData; } string fileFilter = "*.*|*.bmp;*.jpg;*.jpeg;*.tiff;*.tiff;*.png"; string image_path = ""; string model_path; string classer_path; private void FrmCameraOnnxTest_Load(object sender, EventArgs e) { model_path = @"D:\资料\图片视屏大模型\WinformTestYolov11\AIPlateformSystem\AIPlatformSystem\model\\yolo11n.onnx"; //创建输出会话,用于输出模型读取信息 SessionOptions options = new SessionOptions(); options.LogSeverityLevel = OrtLoggingLevel.ORT_LOGGING_LEVEL_INFO; options.AppendExecutionProvider_CPU(0);// 设置为CPU上运行 // 创建推理模型类,读取模型文件 onnx_session = new InferenceSession(model_path, options);//model_path 为onnx模型文件的路径 input_height = 640; input_width = 640; box_num = 8400; conf_threshold = 0.5f; nms_threshold = 0.7f; // classer_path = @"D:\\workplace\\repos\\WindowsFormsApp12\\WindowsFormsApp12\\model\\label.txt"; classer_path = @"D:\资料\图片视屏大模型\C# ONNXRuntime部署yoloV11\WindowsFormsApp12\WindowsFormsApp12\model\label.txt"; class_names = File.ReadAllLines(classer_path, Encoding.UTF8); class_num = class_names.Length; StartVideo(); } } }以上代码如何在前端页面中实时标注推理的结果数据,代码如何修改
08-21
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值