当前位置:网站首页>[opencvsharpdnn] implementation example of yolov3 and Caffe in opencvsharp
[opencvsharpdnn] implementation example of yolov3 and Caffe in opencvsharp
2022-06-09 19:54:00 【Ten year dream Lab】


Recognition effect
Demo video
Usage method
This is a YoloV3 and Caffe Implementation usage in the model
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using OpenCVCSharpDNN.Impl;
using OpenCVCSharpDNN;
using System.IO;
using System.Drawing;
namespace OpenCVCSharp.Example
{
class Program
{
static void Main(string[] args)
{
// Directory containing model and configuration files
string dir = System.IO.Path.Combine(Directory.GetCurrentDirectory(), "data");
// YoloV3 Model
string model = System.IO.Path.Combine(dir, "yolov3.weights");
string cfg = System.IO.Path.Combine(dir, "yolov3.cfg");
string labelsYolo = System.IO.Path.Combine(dir, "coco.names");
// Face detection model
string modelFace = System.IO.Path.Combine(dir, "yolov3-wider_16000.weights");
string cfgFace = System.IO.Path.Combine(dir, "yolov3-face.cfg");
// Gender classification model
string modelGenderCaffe = System.IO.Path.Combine(dir, "gender_net.caffemodel");
string cfgGenderCaffe = System.IO.Path.Combine(dir, "deploy_gender.prototxt");
// Picture path
string testImage = System.IO.Path.Combine(dir, "1.bmp");//friends.jpg
using (NetYoloV3 yoloV3 = new NetYoloV3())
using (NetYoloV3 yoloV3Faces = new NetYoloV3())
using (NetCaffeAgeGender caffeGender = new NetCaffeAgeGender())
using (Bitmap bitmap = new Bitmap(testImage))
using (Bitmap resultImage = new Bitmap(testImage))
{
// Initialize model
yoloV3.Initialize(model, cfg, labelsYolo);
yoloV3Faces.Initialize(modelFace, cfgFace, new string[] { "faces" });
caffeGender.Initialize(modelGenderCaffe, cfgGenderCaffe, new string[] { "Male", "Female" });
// obtain YoloV3 Result
NetResult[] resultPersons = yoloV3.Detect(bitmap, labelsFilters: new string[] { "person" });// Tester
// obtain YoloV3 The result of face detection
NetResult[] resultFaces = yoloV3Faces.Detect(bitmap);// Face detection
using (Graphics canvas = Graphics.FromImage(resultImage))
{
Font font = new Font(FontFamily.GenericSansSerif, 15);
// Inferential gender , Draw labels and face bounding boxes
foreach (NetResult item in resultFaces)
{
// Create regions of interest for each face
using (Bitmap roi = (Bitmap)bitmap.Clone(item.Rectangle, bitmap.PixelFormat))
{
NetResult resultGender = caffeGender.Detect(roi).FirstOrDefault();// Detect face region and infer gender
// Draw labels
canvas.DrawString($"{resultGender.Label} {resultGender.Probability:0.0%}",
font,
new SolidBrush(Color.Green),
item.Rectangle.X - font.GetHeight(), item.Rectangle.Y - font.GetHeight());
}
canvas.DrawRectangle(new Pen(Color.Red, 2), item.Rectangle);
}
canvas.Save();
}
resultImage.Save(Path.Combine(dir, "result.jpg"));// Save the recognition results
}
}
}
} Pre training model
You can download the pre training model at the following link :
|YoloV3|
https://pjreddie.com/darknet/yolo/
|YoloV3 Faces|
http://mmlab.ie.cuhk.edu.hk/projects/WIDERFace/index.html
|Caffe Age and Gender Classification|
https://talhassner.github.io/home/publication/2015_CVPR
Reference resources :
https://github.com/julian9012/OpenCVCSharpDNN
https://drive.google.com/drive/folders/1oj9p04mPjbbCbq1qSK8ChMjOhMLMpk42
边栏推荐
- 5 longest palindrome substring (interval DP)
- ASPX DataTable 行列互换
- 官宣!博通将以610亿美元收购VMware,并承担80亿美元债务
- Have you established an internal wiki?
- shell script安装prometheus和node_exporter
- 版号批下来,可公司已倒闭:现如今,做款游戏还能卖给腾讯吗?
- 高通:将坚持多元化的代工战略,关注英特尔代工商务合作条件
- Logback日志配置文件添加颜色区分
- Alibaba cloud 22q1 status summary, where are you going
- Node版本切换
猜你喜欢
Summary of mongodb database condition query skills

C语言实现电脑自动关机程序--可以用来恶搞舍友电脑

VNCTF 2022 InterestingPHP

The crayfish left out by the young people has only a life of losing money?

不止于观测|阿里云可观测技术峰会正式上线

Hash table distributed hash table (DHT) hash table

Unity upgrade project to URP

个人博客系统(附源码)

【tgowt】cmake转ninja构建

Unity-UI-Scrollbar组件
随机推荐
mtb12_ PearsonR_ correlAtion coefficient_ heatmap_ Distribution Bin_ Clean step type conversion caution_ spatial dist_ Change para value
MySQL data type
2018年全国职业院校技能大赛中职组“网络空间安全”正式赛卷及评分标准
【增量学习】2022 KDD Geometer: Graph Few-Shot Class-Incremental Learning via Prototype Representation
Taiwan once again strictly investigated the poaching of mainland enterprises: more than 100 people were dispatched, 10 enterprises were investigated, and nearly 70 people were interviewed!
Implementation method of redis generating global unique ID
根文件系统
MySQL has no service and the ultimate solution sharing that the service cannot be started
Win7 64 bit ultimate installation office2003 prompt: "error 1919, error occurred when configuring ODBC data source MS Access database ODEC error"
Question bank and answers for the 2022 National latest fire facility operator (senior fire facility operator) examination
oracle 一行转多行
ASP Err.Number 错误描述详解
NoSQL之Redis配置与优化(你不在南京的日子我替你吹了秦淮河的晚风)
STM32内存知识
The version number is approved, but the company has gone bankrupt: can you sell Tencent to make a game now?
5 最長回文子串(區間 dp)
20XX年全國職業院校技能大賽高職組“信息安全管理與評估”賽項任務書
坠落的蚂蚁
Uniapp H5 single page horizontal screen
上海光机所两名员工核酸阳性,园区367人将被转运