來源: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文章
4056瀏覽量
45649 -
模型
+關注
關注
1文章
3658瀏覽量
51804 -
代碼
+關注
關注
30文章
4947瀏覽量
73291 -
OpenCV
+關注
關注
33文章
651瀏覽量
44486
原文標題: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實例分割模型
評論