-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathBoundingBox.cs
57 lines (54 loc) · 1.93 KB
/
BoundingBox.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Data;
namespace Target_Recognition_Console
{
public class Box
{
private const string configurationFilename = @"C:\software\TRC\Cfg\yolov4.cfg";
private const string weightsFilename = @"C:\software\TRC\Weights\yolov3.weights";
private const string namesFile = @"C:\software\TRC\Data\coco.names";
private static Dictionary<int, string> _namesDic = new Dictionary<int, string>();
private static YoloWrapper _wrapper;
public void Initilize()
{
//初始化
int gpu = 0;
Console.WriteLine(configurationFilename);
Console.WriteLine(weightsFilename);
_wrapper = new YoloWrapper(configurationFilename, weightsFilename, gpu);
var lines = File.ReadAllLines(namesFile);
for (var i = 0; i < lines.Length; i++)
{
_namesDic.Add(i, lines[i]);
}
}
public DataTable Convert(string imagePath)
{
//从图片得出结果的数据表
var bbox = _wrapper.Detect(imagePath);
var table = new DataTable();
table.Columns.Add("Type");
table.Columns.Add("Confidence");
table.Columns.Add("X");
table.Columns.Add("Y");
table.Columns.Add("Width");
table.Columns.Add("Height");
foreach (var item in bbox.Where(o => o.h > 0 || o.w > 0))
{
var type = _namesDic[(int)item.obj_id];
DataRow dr = table.NewRow();
dr["Type"] = type;
dr["Confidence"] = item.prob;
dr["X"] = item.x;
dr["Y"] = item.y;
dr["Width"] = item.w;
dr["Height"] = item.h;
table.Rows.Add(dr);
}
return table;
}
}
}