来源:OpenCV学堂
OpenVINO2025 C#支持
开源的支持项目来自颜国进老师贡献,已经被OpenVINO官方收录,项目网址:
https://gitee.com/linbei_cht/OpenVINO-CSharp-API

安装非常容易,只要在VS2022里面点击一下即可安装。最新版本已经是OpenVINO2025支持。
YOLO11实例分割
YOLO11是YOLOv5跟YOLOv8作者推出最新升级版本模型,支持分类、检测、分割、姿态评估、OBB。这里以YOLO11实例分割模型为例,演示OpenVINO C#如何运行,YOLO11-seg模型的输入与输出。

代码是我在OpenVINO-CSharp-API作者开源的YOLOv8对象检测的代码基础上修改而成。调用检测代码如下:
publicvoidDetect()
{
// Set the video path and model path
stringvideo_path="D:/images/video/play_scoers.mp4";
stringmodel_path="D:/python/yolov5-7.0/yolo11n-seg.onnx";
// Create a new Core object and read the model
Corecore=newCore();
Modelmodel=core.read_model(model_path);
CompiledModelcompiled_model=core.compile_model(model,"GPU");
// Create a list of InferRequest objects
Listrequests =newList{ compiled_model.create_infer_request(), compiled_model.create_infer_request() };
// Create a new VideoCapture object and read the video
VideoCapturecapture=newVideoCapture(video_path);
if(!capture.IsOpened())
{
Console.WriteLine("Error: Video not found!");
return;
}
Matframe=newMat();
Matnext_frame=newMat();
capture.Read(frame);
floatscale=0.0f;
float[] input_data = preprocess(frame, out scale);
requests[0].get_input_tensor().set_data(input_data);
requests[0].start_async();
Stopwatchsw=newStopwatch();
float[] total_infs =newfloat[3];
ListclassList = File.ReadAllLines("D:/python/yolov5-7.0/classes.txt").Select(line => line.Trim()).ToList();
while(true)
{
if(!capture.Read(next_frame))
{
break;
}
sw.Restart();
input_data = preprocess(frame, out scale);
requests[1].get_input_tensor().set_data(input_data);
requests[1].start_async();
requests[0].wait();
float[] det_data = requests[0].get_tensor("output0").get_data(8400*116);
float[] seg_data = requests[0].get_tensor("output1").get_data(32*160*160);
Matrgb_mask=newMat(frame.Size(), frame.Type());
DetResultresult=postprocess(det_data, seg_data, scale, rgb_mask);
sw.Stop();
total_infs[0] = sw.ElapsedMilliseconds;
Cv2.PutText(frame,"Inference: "+ (1000.0/ total_infs[0]).ToString("0.00") +"FPS "+ (total_infs[0]).ToString("0.00") +"ms",newOpenCvSharp.Point(20,40), HersheyFonts.HersheyPlain,2,newScalar(255,0,255),2);
result.update_lable(classList);
Visualize.draw_det_result(result, frame);
Cv2.AddWeighted(frame,0.5, rgb_mask,0.5,0, frame);
Cv2.ImShow("C# YOLO11-OpenVINO-Seg演示 - OpenCV学堂", frame);
// Press 'ESC' to exit the program
if(Cv2.WaitKey(1) ==27)
{
break;
}
swap(requests);
frame = next_frame;
rgb_mask.Release();
}
}
后处理实现细节
这个实现最大的坑在后处理部分,要基于全局编码信息乘以每个检测BOX区域的编码信息,才可以解码得到每个BOX对象的掩膜。实现的代码如下:
Matroi_mask=roi_masks[index];
Matm=roi_mask * mask_info;
for(intcol=0; col < m.Cols; col++)
{
m.At(0, col) = sigmoid_function(m.At(0, col));
}
最后根据得到掩膜直接设置BOX区域的颜色即可,代码如下:
rgb_mask[box].SetTo(new Scalar(0,0,255), box_m); re.add(classIds[index], confidences[index], positionBoxes[index]);
然后把得到RGB彩色掩膜图像跟BOX框绘制图像相加记得到最终输出结果图像。
-
开源
+关注
关注
3文章
4038浏览量
45578 -
模型
+关注
关注
1文章
3649浏览量
51719 -
代码
+关注
关注
30文章
4942浏览量
73159 -
OpenCV
+关注
关注
33文章
651浏览量
44427
原文标题:C# YOLO11-OpenVINO实例分割
文章出处:【微信号:英特尔物联网,微信公众号:英特尔物联网】欢迎添加关注!文章转载请注明出处。
发布评论请先 登录
【飞凌OK-MX9596-C开发板试用】①开箱图赏、跑分测试、yolo大模型三箭齐发
如何进行YOLO模型转换?
RK3576 Yolov11训练部署教程
k230执行yolov11分割任务显示“MPY: soft reboot”,是怎么回事?
【HZ-RK3568开发板免费体验】04 YOLOv11 模型转换为RKNN并在板端部署
基于RK3576开发板的yolov11-track多目标跟踪部署教程
RK3576 Yolov11训练部署教程
使用Yolo-v3-TF运行OpenVINO™对象检测Python演示时的结果不准确的原因?
运行时OpenVINO™找不到模型优化器,为什么?
为什么无法在运行时C++推理中读取OpenVINO™模型?
C#集成OpenVINO™:简化AI模型部署
C#中使用OpenVINO™:轻松集成AI模型!

OpenVINO C#如何运行YOLO11实例分割模型
评论