VisioForge

最后更新:2026年11月

AForge.NET 替代方案:迁移到 VisioForge .Net SDK 指南

用现代跨平台 .NET SDK 替换已停止维护的 AForge.NET

AForge.NET 是一个用于视频采集、计算机视觉和图像处理的开源 C# 框架,自 2013 年 7 月起已停止维护,面向 .NET Framework 2.0。本指南将 AForge.NET 的每个命名空间对应到面向 .NET 6-10 的 VisioForge .Net SDK。AForge.Video 的类迁移到 Video Capture SDK .NET 中的 VideoCaptureCoreX:VideoCaptureDevice 对应 VideoCaptureDeviceSourceSettings,MJPEGStream 对应 HTTPMJPEGSourceSettings,ScreenCaptureStream 对应适用于 Windows、macOS 或 Linux 的屏幕源。AForge.Vision 的运动检测迁移到 VideoCaptureCoreX 中的 MotionDetectionExSettings,或 Media Blocks SDK 中的 CVMotionCellsBlock。此外,AForge.NET 从未提供人脸检测或行人检测,而 VisioForge 提供带隐私模糊功能的 Haar cascade 和 DNN 人脸检测器,以及基于 HOG 的行人检测器。AForge.Imaging 的滤镜部分对应 VisioForge CV 块,例如 Canny 边缘检测和直方图均衡化,其余部分对应 OpenCvSharp。例如,一个带运动告警的摄像头录像程序只需一个 VideoCaptureCoreX 引擎,而不必分别使用采集设备、运动检测器和文件写入器。

每年 €250 起 · Lifetime 许可证 €900 起

为什么要替换 AForge.NET?

之所以应替换 AForge.NET,是因为该框架自 2013 年 7 月起已停止维护,此后没有任何更新、安全补丁或错误修复。AForge.NET 面向 .NET Framework 2.0,因此如果不借助质量参差不齐的社区分支,其代码无法在 .NET 6-10 上运行。它的视频采集基于 DirectShow,这是一个已被微软用 Media Foundation 取代的旧版 Windows API,因此采集只能在 Windows 上运行。此外,AForge.NET 不支持 H.265、AV1 或 VP9。例如,将 .NET Framework 摄像头应用迁移到 .NET 8 时有两个选择:使用仍然只能在 Windows 上运行的 AForge.Video 社区分支,或者改用 VideoCaptureCoreX,用一套 API 即可覆盖 Windows、macOS、Linux、iOS 和 Android。

风险影响
无安全补丁视频/图像处理中的漏洞仍未修补
不支持 .NET 6+无法使用现代 .NET 功能、AOT 或跨平台部署
不支持新编解码器不支持 H.265、AV1、VP9 或现代容器格式
无社区论坛于2012年4月关闭,无活跃维护者
依赖 DirectShow旧版 API,已被 Media Foundation 取代
仅限 Windows无法针对 macOS、Linux、iOS、Android

AForge.Video → VisioForge Video Capture SDK .Net

类映射

AForge.Video 组件VisioForge 替代
VideoCaptureDeviceVideoCaptureCoreX + VideoCaptureDeviceSourceSettings
MJPEGStreamVideoCaptureCoreX + HTTPMJPEGSourceSettings
JPEGStreamMJPEG 流使用 VideoCaptureCoreX + HTTPMJPEGSourceSettings;快照 URL 没有直接对应项
ScreenCaptureStreamVideoCaptureCoreX + ScreenCaptureD3D11SourceSettings (Windows), ScreenCaptureMacOSSourceSettings, ScreenCaptureXDisplaySourceSettings (Linux)
FileVideoSourceMediaPlayerCoreX(播放)或 VideoEditCoreX(处理)
AsyncVideoSource内置 — 所有 VisioForge 源默认为异步
NewFrameEventArgsOnVideoFrameBuffer 事件

C# 摄像头捕获

AForge.NET — 摄像头捕获(迁移前)

C#
// AForge: Manual device enumeration, callback-based, no recording
var videoDevices = new FilterInfoCollection(FilterCategory.VideoInputDevice);
var videoSource = new VideoCaptureDevice(videoDevices[0].MonikerString);
videoSource.NewFrame += (sender, eventArgs) =>
{
    Bitmap frame = (Bitmap)eventArgs.Frame.Clone();
    pictureBox.Image = frame;
    // Manual recording requires separate code
};
videoSource.Start();

// Cleanup
videoSource.SignalToStop();
videoSource.WaitForStop();

VisioForge — C# 摄像头捕获(迁移后)

C#
// VisioForge: Typed API, async, preview + recording built-in
var capture = new VideoCaptureCoreX(videoView);  // Preview automatic
var devices = await DeviceEnumerator.Shared.VideoSourcesAsync();
capture.Video_Source = new VideoCaptureDeviceSourceSettings(devices[0]);
capture.Outputs_Add(new MP4Output("recording.mp4"), true);
await capture.StartAsync();

// Stop
await capture.StopAsync();

C# IP摄像头 RTSP / MJPEG 流媒体

AForge.NET — MJPEG 流(迁移前)

C#
// AForge: MJPEG only, no RTSP, no reconnection
var stream = new MJPEGStream("http://camera-ip/mjpg/video.mjpg");
stream.NewFrame += (sender, eventArgs) =>
{
    pictureBox.Image = (Bitmap)eventArgs.Frame.Clone();
};
stream.Start();

VisioForge — C# RTSP IP摄像头捕获(迁移后)

C#
// VisioForge: RTSP, RTMP, HLS, MJPEG
// Reconnection is opt-in: configure FallbackSwitch on the source settings
var capture = new VideoCaptureCoreX(videoView);
// RTSPSourceSettings uses a static factory (private constructor)
capture.Video_Source = await RTSPSourceSettings.CreateAsync(
    new Uri("rtsp://camera-ip/stream"), "admin", "pass", audioEnabled: true);
capture.Outputs_Add(new MP4Output("recording.mp4"), true);
await capture.StartAsync();

C# 屏幕捕获和录制

AForge.NET — 屏幕捕获(迁移前)

C#
// AForge: Basic, CPU-intensive, no recording
var screenStream = new ScreenCaptureStream(Screen.PrimaryScreen.Bounds);
screenStream.NewFrame += (sender, eventArgs) =>
{
    pictureBox.Image = (Bitmap)eventArgs.Frame.Clone();
    // Must manually encode and write frames to create a recording
};
screenStream.Start();

VisioForge — C# 屏幕录制器(迁移后)

C#
// VisioForge: monitor selection, cursor capture, automatic H.264 encoder
var capture = new VideoCaptureCoreX(videoView);
// Windows source; macOS and Linux have their own settings classes
capture.Video_Source = new ScreenCaptureD3D11SourceSettings
{
    MonitorIndex = 0,
    CaptureCursor = true,
    FrameRate = new VideoFrameRate(25)
};
capture.Outputs_Add(new MP4Output("screen.mp4"), true);
await capture.StartAsync();

AForge.Vision → VisioForge 计算机视觉模块

类映射

AForge.Vision 组件VisioForge 替代
MotionDetectorVideoCaptureCoreX 上的 MotionDetectionExSettings + OnMotionDetection,或 Media Blocks 中的 CVMotionCellsBlock
TwoFramesDifferenceDetectorCVMotionCellsBlock — 基于网格的运动单元
SimpleBackgroundModelingDetectorObjectDetector (VisioForge.Core.CV) — MOG2 背景差分 (history: 500 frames, variance threshold: 40)
CustomFrameDifferenceDetector可配置的 CVMotionCellsSettings
MotionAreaHighlightingCVMotionCellsBlock(Display = true)— 绘制检测到运动的单元格
GridMotionAreaProcessingCVMotionCellsBlock — 通过 GridSize 设置运动网格,每轴 8 到 32 个单元格
BlobCounterCarCounter (VisioForge.Core.CV) — blob 跟踪、轮廓检测、通过跟踪线的车辆计数

C# 运动和对象检测

AForge.NET — 运动检测(迁移前)

C#
// AForge: Manual frame processing, no recording integration
var detector = new MotionDetector(
    new TwoFramesDifferenceDetector(),
    new MotionAreaHighlighting());

videoSource.NewFrame += (sender, eventArgs) =>
{
    float motionLevel = detector.ProcessFrame((Bitmap)eventArgs.Frame.Clone());
    if (motionLevel > 0.02f)
        Console.WriteLine($"Motion: {motionLevel * 100:F1}%");
};

VisioForge — 基于事件的运动检测(Video Capture SDK)

C#
// Integrated detection during capture + recording
var capture = new VideoCaptureCoreX(videoView);
capture.Video_Source = new VideoCaptureDeviceSourceSettings(devices[0]);
capture.Outputs_Add(new MP4Output("recording.mp4"), true);

capture.Motion_Detection = new MotionDetectionExSettings();
capture.OnMotionDetection += (s, e) =>
{
    if (e.LevelPercent > 30)
        Console.WriteLine($"Motion: {e.LevelPercent}%");
};

await capture.StartAsync();

VisioForge — CVMotionCellsBlock(MediaBlocks 管道)

C#
// Motion cells grid: raises MotionDetected as cells change
var settings = new CVMotionCellsSettings
{
    Display = true,
    GridSize = new Size(16, 16)
};
var detector = new CVMotionCellsBlock(settings);
detector.MotionDetected += (s, e) => Console.WriteLine("Motion");

C# 人脸检测和行人检测(AForge 中不可用)

类映射

功能VisioForge 模块
Haar 级联人脸检测CascadeFaceDetectorBlock — 正面/侧面人脸、眼睛、鼻子、嘴巴检测
DNN 人脸检测DNNFaceDetectorBlock — Caffe SSD 模型、置信度过滤
DLib 人脸检测FaceDetectorBlock (VisioForge.Core.CVD) — DLib HOG+SVM 正面人脸检测器
行人检测PedestrianDetector — 内置 HOG+SVM 行人检测器,通过 Video_Processors 添加
镜头遮挡检测CameraCoveredDetector — Canny 边缘检测

C# 人脸检测

AForge.NET(迁移前)

C#
// AForge had no built-in face detection — required manual Haar cascade code
// or using Accord.NET's HaarObjectDetector on top of AForge frames

VisioForge — Haar 级联人脸检测

C#
var settings = new CascadeFaceDetectorSettings
{
    DetectFrontalFace = true,
    DetectProfileFace = true,
    DetectEyes = true,
    DetectNose = true,
    DetectMouth = true,
    MinFaceSize = new Size(30, 30),
    ScaleFactor = 1.1f,
    DrawEnabled = true,
    Blur = false,    // set true for privacy blur
    Pixelate = false // set true for privacy pixelation
};
var detector = new CascadeFaceDetectorBlock(settings);

VisioForge — DNN 人脸检测器

C#
var settings = new DNNFaceDetectorSettings
{
    Confidence = 0.25f,
    DrawEnabled = true,
    Blur = true  // built-in privacy blur
};
var detector = new DNNFaceDetectorBlock(settings);

VisioForge — DLib 人脸检测器

C#
var settings = new FaceDetectorSettings
{
    DrawEnabled = true,
    MinFaceSize = new Size(30, 30)
};
var detector = new FaceDetectorBlock(settings);

C# 行人检测

AForge.NET(迁移前)

C#
// AForge had no pedestrian detection — required manual HOG+SVM implementation

VisioForge — 行人检测(迁移后)

C#
var detector = new PedestrianDetector
{
    DrawEnabled = true,
    VideoScale = 1.0,
    FramesToSkip = 2
};
detector.Init();
detector.OnPedestrianDetected += OnPedestrianDetected;
capture.Video_Processors.Add(detector);
// HOG descriptors + SVM classifier

AForge.Imaging → VisioForge CV + OpenCvSharp

类映射

AForge.Imaging 功能VisioForge 内置独立 OpenCvSharp
GaussianBlurCVSmoothBlock,或对区域使用 CVProcess.BlurRegion() (kernel 23x23)Cv2.GaussianBlur()
PixellateCVProcess.PixelateRegion()自定义缩小/放大
CannyEdgeDetectorCVEdgeDetectBlockCv2.Canny()
Erosion / DilationCVErodeBlock / CVDilateBlockCv2.Erode() / Cv2.Dilate()
BlobCounterCarCounter — 轮廓检测、面积/宽高比过滤、凸包Cv2.FindContours()
Grayscale所有检测器中内置的 BGR→Gray 转换Cv2.CvtColor()
ThresholdObjectDetector 和 CarCounter 中内置的二值阈值处理Cv2.Threshold()
ResizeBilinear所有检测器设置中内置的视频缩放Cv2.Resize()
HistogramEqualizationCVEqualizeHistogramBlockCv2.EqualizeHist()
HSLFiltering / 颜色滤镜—Cv2.InRange() / Cv2.CvtColor()
HoughLineTransformation—Cv2.HoughLinesP()
SobelEdgeDetectorCVSobelBlockCv2.Sobel()
模板匹配CVTemplateMatchBlockCv2.MatchTemplate()

迁移检查清单

  • 清点 AForge 引用 — 查找项目中所有的 `using AForge.*`
  • 安装 VisioForge NuGet 包
  • 替换视频源类
  • 替换运动检测
  • 替换人脸检测
  • 替换 blob/对象检测
  • 移除手动帧循环
  • 添加录制/流媒体
  • 面向现代 .NET — .NET 6-10
  • 进行跨平台测试
  • 对于图像处理 — VisioForge CV 涵盖模糊、像素化、Canny、Sobel、形态学、模板匹配;使用 OpenCvSharp 获取额外滤镜

迁移后获得的优势

能力AForge.NET迁移后
框架.NET Framework 2.0.NET 6-10
平台仅 WindowsWindows、macOS、Linux、iOS、Android
视频捕获基本 DirectShow具有异步 API 的专业 SDK
录制手动实现内置(MP4、MKV、AVI、WebM)
硬件编码无NVENC、QSV、AMF、VideoToolbox
流媒体无RTMP、HLS、SRT、NDI
音频效果无两个引擎合计 40+(EQ、混响、合唱、3D)
视频效果无GPU + CPU 管道
人脸检测无Haar + DNN (Caffe SSD) 含模糊/像素化;DLib HOG 仅检测
运动检测基本帧差分MOG2 背景差分 + 带 ID 的对象跟踪
行人检测无内置 HOG+SVM 行人检测器
IP摄像头仅 MJPEGRTSP、RTMP、HLS、ONVIF
虚拟摄像头无输出到 Zoom/Teams/OBS
维护已停止(2013)活跃开发
安全性未修补定期更新

常见问题

AForge.NET 还在维护吗?
不。AForge.NET 自2013年7月以来已被放弃,没有更新、安全补丁或 .NET 6+ 支持。社区分支存在但质量和维护各不相同。请使用 VisioForge .Net SDK 作为现代 AForge.NET 替代方案。
C# 视频捕获最好的 AForge.NET 替代方案是什么?
VisioForge Video Capture SDK .Net 以现代异步 API 替换 AForge.Video,支持网络摄像头、IP摄像头(RTSP/ONVIF)、屏幕捕获以及输出到 MP4、WebM 和其他格式(.NET 6-10)。
VisioForge 能替换 AForge.Imaging 滤镜吗?
部分可以。VisioForge CV 包含模糊、像素化、Canny 和 Sobel 边缘检测、形态学运算、灰度转换、直方图均衡化和模板匹配。对于其余图像滤镜(Hough、颜色过滤),请将 OpenCvSharp 与 VisioForge 一起使用。
我可以在没有 AForge 的情况下使用 VisioForge 进行 C# 人脸检测吗?
可以。VisioForge .Net SDK 包含三个内置人脸检测引擎 — Haar 级联、基于 DNN 和基于 DLib;其中 Haar 和 DNN 引擎还可对检测到的人脸进行模糊或像素化处理以保护隐私。不需要 AForge 或 Accord.NET 依赖。
VisioForge 支持 .NET 6、.NET 8、.NET 9 和 .NET 10 吗?
支持。所有 VisioForge .Net SDK 包支持 .NET 6 到 .NET 10,包括在 Windows、macOS、Linux、iOS 和 Android 上的跨平台部署。
我可以从 AForge.NET 逐步迁移吗?
可以。VisioForge SDK 可以在迁移期间与 AForge.NET 包共存。一次替换一个组件 — 从视频捕获开始,然后是检测,然后是图像处理 — 并在每个步骤完成后删除 AForge NuGet 包。

每年 €250 起 · Lifetime 许可证 €900 起

开始您的迁移

相关迁移指南