Last updated: 2026年1月
AForge.NET 替代方案:迁移到 VisioForge .Net SDK 指南
用现代跨平台 .NET SDK 替换已停止维护的 AForge.NET
从 AForge.NET(AForge.Video、AForge.Vision、AForge.Imaging)迁移到现代 .NET 6-10 替代方案的 C# 开发者
为什么要替换 AForge.NET?
AForge.NET 自2013年7月以来已被放弃 — 超过12年没有更新、安全补丁或错误修复。它针对 .NET Framework 2.0,如果没有质量参差不齐的社区分支,则无法在现代 .NET 6-10 上运行。
| 风险 | 影响 |
|---|---|
| 无安全补丁 | 视频/图像处理中的漏洞仍未修补 |
| 不支持 .NET 6+ | 无法使用现代 .NET 功能、AOT 或跨平台部署 |
| 不支持新编解码器 | 不支持 H.265、AV1、VP9 或现代容器格式 |
| 无社区 | 论坛于2012年4月关闭,无活跃维护者 |
| 依赖 DirectShow | 已被 Microsoft 弃用,转而使用 Media Foundation |
| 仅限 Windows | 无法针对 macOS、Linux、iOS、Android |
AForge.Video → VisioForge Video Capture SDK .Net
类映射
| AForge.Video 组件 | VisioForge 替代 |
|---|---|
| VideoCaptureDevice | VideoCaptureCoreX + VideoCaptureDeviceSourceSettings |
| MJPEGStream | VideoCaptureCoreX + RTSPSourceSettings or UniversalSourceBlock |
| JPEGStream | VideoCaptureCoreX + IPCameraSourceSettings |
| ScreenCaptureStream | VideoCaptureCoreX + ScreenCaptureSourceSettings |
| FileVideoSource | MediaPlayerCoreX(播放)或 VideoEditCoreX(处理) |
| AsyncVideoSource | 内置 — 所有 VisioForge 源默认为异步 |
| NewFrameEventArgs | OnVideoFrameBuffer 事件 |
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 — with auto-reconnection
var capture = new VideoCaptureCoreX(videoView);
capture.Video_Source = new RTSPSourceSettings(
new Uri("rtsp://admin:pass@camera-ip/stream"));
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: Region selection, cursor capture, hardware encoding
var capture = new VideoCaptureCoreX(videoView);
capture.Video_Source = new ScreenCaptureSourceSettings();
capture.Outputs_Add(new MP4Output("screen.mp4", new H264EncoderSettings()), true);
await capture.StartAsync();AForge.Vision → VisioForge 计算机视觉模块
类映射
| AForge.Vision 组件 | VisioForge 替代 |
|---|---|
| MotionDetector | CVMotionCellsBlock — MOG2 背景差分,支持对象跟踪和 ID 分配 |
| TwoFramesDifferenceDetector | CVMotionCellsBlock — MOG2 (history: 500 frames, variance threshold: 40) |
| SimpleBackgroundModelingDetector | CVMotionCellsBlock — 基于轮廓检测的自动背景模型 |
| CustomFrameDifferenceDetector | 可配置的 CVMotionCellsSettings |
| MotionAreaHighlighting | CVMotionCellsBlock(DrawEnabled = true)— 绘制带有对象 ID 的边界框 |
| GridMotionAreaProcessing | 通过 Video Capture SDK 事件进行基于区域的运动检测 |
| BlobCounter | CVMotionCellsBlock — 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.OnMotionDetection += (s, e) =>
{
if (e.Level > 30)
Console.WriteLine($"Motion: {e.Level}%");
};
await capture.StartAsync();VisioForge — CVMotionCellsBlock(MediaBlocks 管道)
C#// MOG2 background subtraction with automatic object tracking and IDs
var settings = new CVMotionCellsSettings
{
DrawEnabled = true
};
var detector = new CVMotionCellsBlock(settings);
// Tracks objects with unique IDs using Euclidean distance matchingC# 人脸检测和行人检测(AForge 中不可用)
类映射
| 功能 | VisioForge 模块 |
|---|---|
| Haar 级联人脸检测 | CVFaceDetectBlock — 正面/侧面人脸、眼睛、鼻子、嘴巴检测 |
| DNN 人脸检测 | CVFaceDetectBlock — Caffe SSD 模型、置信度过滤、GPU 加速 |
| DLib 人脸检测 | CVFaceDetectBlock (CVD) — DLib HOG+SVM 正面人脸检测器 |
| 行人检测 | CVFaceDetectBlock — 内置 HOG+SVM 行人检测器 |
| 镜头遮挡检测 | CameraCoveredDetectorBlock — 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 framesVisioForge — Haar 级联人脸检测
C#var settings = new CVFaceDetectSettings
{
DetectFrontalFace = true,
DetectProfileFace = true,
DetectEyes = true,
DetectNose = true,
DetectMouth = true,
MinFaceSize = new Size(30, 30),
ScaleFactor = 1.1,
DrawEnabled = true,
BlurFaces = false, // set true for privacy blur
PixelateFaces = false // set true for privacy pixelation
};
var detector = new CVFaceDetectBlock(settings);VisioForge — DNN 人脸检测器(更高精度,GPU 支持)
C#var settings = new CVFaceDetectSettings
{
Confidence = 0.25,
DrawEnabled = true,
BlurFaces = true // built-in privacy blur
};
var detector = new CVFaceDetectBlock(settings);VisioForge — DLib 人脸检测器
C#var settings = new CVFaceDetectSettings
{
DrawEnabled = true,
MinFaceSize = new Size(30, 30)
};
var detector = new CVFaceDetectBlock(settings);C# 行人检测
AForge.NET(迁移前)
C#// AForge had no pedestrian detection — required manual HOG+SVM implementationVisioForge — 行人检测(迁移后)
C#var settings = new CVFaceDetectSettings
{
DrawEnabled = true,
VideoScale = 1.0,
FramesToSkip = 2
};
var detector = new CVFaceDetectBlock(settings);
// Built-in HOG descriptors + SVM classifier, multi-scale detectionAForge.Imaging → VisioForge CV + OpenCvSharp
类映射
| AForge.Imaging 功能 | VisioForge 内置 | 独立 OpenCvSharp |
|---|---|---|
| GaussianBlur | CVProcess.BlurRegion() (kernel 23x23) | Cv2.GaussianBlur() |
| Pixellate | CVProcess.PixelateRegion() | 自定义缩小/放大 |
| CannyEdgeDetector | CameraCoveredDetector (thresholds 100/200) | Cv2.Canny() |
| Erosion / Dilation | 由 CVMotionCellsBlock 内部使用(5x5 结构元素) | Cv2.Erode() / Cv2.Dilate() |
| BlobCounter | CVMotionCellsBlock — 轮廓检测、面积/宽高比过滤、凸包 | Cv2.FindContours() |
| Grayscale | 所有检测器中内置的 BGR→Gray 转换 | Cv2.CvtColor() |
| Threshold | 运动管道中内置的二值阈值处理 | Cv2.Threshold() |
| ResizeBilinear | 所有检测器设置中内置的视频缩放 | Cv2.Resize() |
| HistogramEqualization | 在 CVFaceDetect 中用于改进检测 | Cv2.EqualizeHist() |
| HSLFiltering / 颜色滤镜 | — | Cv2.InRange() / Cv2.CvtColor() |
| HoughLineTransformation | — | Cv2.HoughLinesP() |
| SobelEdgeDetector | — | Cv2.Sobel() |
| 模板匹配 | — | Cv2.MatchTemplate() |
迁移检查清单
- 清点 AForge 引用 — 查找项目中所有的 `using AForge.*`
- 安装 VisioForge NuGet 包
- 替换视频源类
- 替换运动检测
- 替换人脸检测
- 替换 blob/对象检测
- 移除手动帧循环
- 添加录制/流媒体
- 面向现代 .NET — .NET 6-10
- 进行跨平台测试
- 对于图像处理 — VisioForge CV 涵盖模糊、像素化、Canny、形态学;使用 OpenCvSharp 获取额外滤镜
迁移后获得的优势
| 能力 | AForge.NET | 迁移后 |
|---|---|---|
| 框架 | .NET Framework 2.0 | .NET 6-10 |
| 平台 | 仅 Windows | Windows、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摄像头 | 仅 MJPEG | RTSP、RTMP、HLS、ONVIF |
| 虚拟摄像头 | 无 | 输出到 Zoom/Teams/OBS |
| 维护 | 已停止(2013) | 活跃开发 |
| 安全性 | 未修补 | 定期更新 |
Frequently Asked Questions
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 — 具有内置的隐私模糊和像素化功能。不需要 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 包。
