來(lái)源:OpenCV學(xué)堂
OpenVINO2025 C#支持
開(kāi)源的支持項(xiàng)目來(lái)自顏國(guó)進(jìn)老師貢獻(xiàn),已經(jīng)被OpenVINO官方收錄,項(xiàng)目網(wǎng)址:
https://gitee.com/linbei_cht/OpenVINO-CSharp-API
安裝非常容易,只要在VS2022里面點(diǎn)擊一下即可安裝。最新版本已經(jīng)是OpenVINO2025支持。
YOLO11實(shí)例分割
YOLO11是YOLOv5跟YOLOv8作者推出最新升級(jí)版本模型,支持分類(lèi)、檢測(cè)、分割、姿態(tài)評(píng)估、OBB。這里以YOLO11實(shí)例分割模型為例,演示OpenVINO C#如何運(yùn)行,YOLO11-seg模型的輸入與輸出。
代碼是我在OpenVINO-CSharp-API作者開(kāi)源的YOLOv8對(duì)象檢測(cè)的代碼基礎(chǔ)上修改而成。調(diào)用檢測(cè)代碼如下:
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學(xué)堂", frame); // Press 'ESC' to exit the program if(Cv2.WaitKey(1) ==27) { break; } swap(requests); frame = next_frame; rgb_mask.Release(); } }
后處理實(shí)現(xiàn)細(xì)節(jié)
這個(gè)實(shí)現(xiàn)最大的坑在后處理部分,要基于全局編碼信息乘以每個(gè)檢測(cè)BOX區(qū)域的編碼信息,才可以解碼得到每個(gè)BOX對(duì)象的掩膜。實(shí)現(xiàn)的代碼如下:
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)); }
最后根據(jù)得到掩膜直接設(shè)置BOX區(qū)域的顏色即可,代碼如下:
rgb_mask[box].SetTo(new Scalar(0,0,255), box_m); re.add(classIds[index], confidences[index], positionBoxes[index]);
然后把得到RGB彩色掩膜圖像跟BOX框繪制圖像相加記得到最終輸出結(jié)果圖像。
-
開(kāi)源
+關(guān)注
關(guān)注
3文章
3695瀏覽量
43852 -
模型
+關(guān)注
關(guān)注
1文章
3522瀏覽量
50450 -
代碼
+關(guān)注
關(guān)注
30文章
4900瀏覽量
70797 -
OpenCV
+關(guān)注
關(guān)注
32文章
642瀏覽量
42935
原文標(biāo)題:C# YOLO11-OpenVINO實(shí)例分割
文章出處:【微信號(hào):英特爾物聯(lián)網(wǎng),微信公眾號(hào):英特爾物聯(lián)網(wǎng)】歡迎添加關(guān)注!文章轉(zhuǎn)載請(qǐng)注明出處。
發(fā)布評(píng)論請(qǐng)先 登錄
k230執(zhí)行yolov11分割任務(wù)顯示“MPY: soft reboot”,是怎么回事?
【HZ-RK3568開(kāi)發(fā)板免費(fèi)體驗(yàn)】04 YOLOv11 模型轉(zhuǎn)換為RKNN并在板端部署
使用Openvino? GenAI運(yùn)行Sdxl Turbo模型時(shí)遇到錯(cuò)誤怎么解決?
基于RK3576開(kāi)發(fā)板的yolov11-track多目標(biāo)跟蹤部署教程

RK3576 Yolov11訓(xùn)練部署教程

OpenVINO中的量化模型與OpenVINO ESR模型結(jié)果不一致是怎么回事?
如何使用OpenVINO?運(yùn)行對(duì)象檢測(cè)模型?
使用Yolo-v3-TF運(yùn)行OpenVINO?對(duì)象檢測(cè)Python演示時(shí)的結(jié)果不準(zhǔn)確的原因?
運(yùn)行時(shí)OpenVINO?找不到模型優(yōu)化器,為什么?
為什么無(wú)法在運(yùn)行時(shí)C++推理中讀取OpenVINO?模型?
從OpenVINO? 2019_R3下載的face-detection-retail-0004模型,運(yùn)行時(shí)報(bào)錯(cuò)怎么解決?
C#集成OpenVINO?:簡(jiǎn)化AI模型部署

C#中使用OpenVINO?:輕松集成AI模型!

【米爾RK3576開(kāi)發(fā)板評(píng)測(cè)】+項(xiàng)目名稱3、使用rknn 進(jìn)行圖像檢測(cè)
使用OpenVINO C# API部署YOLO-World實(shí)現(xiàn)實(shí)時(shí)開(kāi)放詞匯對(duì)象檢測(cè)

評(píng)論