-
Notifications
You must be signed in to change notification settings - Fork 2
/
TagDetection.cs
62 lines (60 loc) · 2.14 KB
/
TagDetection.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
58
59
60
61
62
using System;
using System.Collections;
using System.Text.RegularExpressions;
using OpenCvSharp;
namespace csharp {
public class TagDetection {
public bool good; //汉明距离是否在误差范围内 Whether the hamming distance is within the margin of error.
public long obsCode; //解析出的code Observed Code
public long matchCode; //匹配上的code match Code
public int id; //匹配上的id tag`id
public int hammingDistance; // hamming distance between Observed code and matched code
public int rotation;
public Point[] points;//four corner
public Mat homography;
public TagDetection () {
this.obsCode = -1;
this.id = -1;
this.hammingDistance = -1;
this.rotation = 1;
this.good = false;
this.matchCode = -1;
}
/// <summary>
/// 将Point转化成Point2d
/// Translate normal point to 2d point
/// </summary>
/// <returns>转化后的Point2d 2d point which has been translated
/// </returns>
Point2d[] _convertPoint2Point2D () {
Point2d[] points2d = new Point2d[4];
for (int i = 0; i < 4; i++) {
points2d[i] = new Point2d (this.points[i].X, this.points[i].Y);
}
return points2d;
}
/// <summary>
/// 得到旋转矩阵,需要使用opencv
/// </summary>
void _computeHomographyOpencv () {
Point2d[] src = {
new Point2d (-1, -1),
new Point2d (1, -1),
new Point2d (1, 1),
new Point2d (-1, 1)
};
Point2d[] dst = _convertPoint2Point2D ();
Mat retval = Cv2.FindHomography (src, dst);
this.homography = retval;
}
/// <summary>
/// 得到旋转矩阵,不使用opencv
/// get homography but not using opencv
/// </summary>
void _computeHomography () { }
public void addPoint (Point[] points) {
this.points = points;
_computeHomographyOpencv ();
}
}
}