C# OpenCV EmguCv mobilenet_v3 对象检测
2022/3/21 17:28:30
本文主要是介绍C# OpenCV EmguCv mobilenet_v3 对象检测,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!
链接:https://pan.baidu.com/s/1I9N3lRe_t9C24IKJRcv89Q?pwd=1212
由于OpenCVSharp缺少相关api,这次使用EmguCv,这个demo网上都是python版本的,抄写为C#
使用ssd_mobilenet_v3_large_coco_2020_01_14.pbtxt和frozen_inference_graph.pb模型
public class EasyObjectDetection { public static void Run() { string modelPathBase = @"D:\SourceCode\Models\"; string classesfile = modelPathBase + "coco.names"; string configPath = modelPathBase + "ssd_mobilenet_v3_large_coco_2020_01_14.pbtxt"; string weightsPath = modelPathBase + "frozen_inference_graph.pb"; var thres = 0.5f; var cap = new VideoCapture(modelPathBase + "Road_traffic_video2.mp4"); string[] classes = File.ReadAllLines(classesfile); var net = new Emgu.CV.Dnn.DetectionModel(weightsPath, configPath); net.SetInputSize(new Size(320, 320)); net.SetInputScale(1.0 / 127.5); net.SetInputMean(new Emgu.CV.Structure.MCvScalar(127.5, 127.5, 127.5)); net.SetInputSwapRB(true); Mat frame = new Mat(); while (true) { var isSuccess = cap.Read(frame); var classIds = new VectorOfInt(); var confs = new VectorOfFloat(); var bbox = new VectorOfRect(); var indices = new VectorOfInt(); net.Detect(frame, classIds, confs, bbox, confThreshold: 0.5f); DnnInvoke.NMSBoxes(bbox, confs, thres, 0.2f, indices); for (int i = 0; i < indices.Size; i++) { var confidence = confs[i].ToString(); for (int j = 0; j < classIds.Size; j++) { var classId = classIds[j]; //var box = bbox[j]; Rectangle box = bbox[indices[i]]; CvInvoke.Rectangle(frame, box, new Emgu.CV.Structure.MCvScalar(255, 0, 255), 2); CvInvoke.PutText(frame, classes[classIds[i] - 1].ToUpper(), new Point(box.X + 2, box.Y + 2), Emgu.CV.CvEnum.FontFace.HersheyPlain, 0.7, new Emgu.CV.Structure.MCvScalar(200, 200, 200), 1); } } CvInvoke.Imshow("output", frame); int c = CvInvoke.WaitKey(5); if (c == 27) { // ESC退出 break; } } } }
这篇关于C# OpenCV EmguCv mobilenet_v3 对象检测的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!
- 2022-03-01沐雪多租宝商城源码从.NetCore3.1升级到.Net6的步骤
- 2024-12-06使用Microsoft.Extensions.AI在.NET中生成嵌入向量
- 2024-11-18微软研究:RAG系统的四个层次提升理解与回答能力
- 2024-11-15C#中怎么从PEM格式的证书中提取公钥?-icode9专业技术文章分享
- 2024-11-14云架构设计——如何用diagrams.net绘制专业的AWS架构图?
- 2024-05-08首个适配Visual Studio平台的国产智能编程助手CodeGeeX正式上线!C#程序员必备效率神器!
- 2024-03-30C#设计模式之十六迭代器模式(Iterator Pattern)【行为型】
- 2024-03-29c# datetime tryparse
- 2024-02-21list find index c#
- 2024-01-24convert toint32 c#