markus / Markus.ImageComparer / OpenCVExtensions.cs @ master
이력 | 보기 | 이력해설 | 다운로드 (2.54 KB)
1 |
using System; |
---|---|
2 |
using System.Collections; |
3 |
using System.Collections.Generic; |
4 |
using System.Linq; |
5 |
using System.Text; |
6 |
using System.Threading.Tasks; |
7 |
|
8 |
namespace Markus.Image |
9 |
{ |
10 |
/// <summary> |
11 |
/// OpenCV Extensions |
12 |
/// </summary> |
13 |
public static class OpenCVExtensions |
14 |
{ |
15 |
public static T GetValue<T>(this OpenCvSharp.Mat mat,int Row,int Col) where T : struct |
16 |
{ |
17 |
return mat.Get<T>(Row, Col); |
18 |
} |
19 |
|
20 |
public static IEnumerable<ImageData<float>> ToDataFloat(this OpenCvSharp.Mat mat) |
21 |
{ |
22 |
for (int i = 0; i < mat.Rows; i++) |
23 |
{ |
24 |
for (int j = 0; j < mat.Cols; j++) |
25 |
{ |
26 |
yield return new ImageData<float> { Row = i, Col = j, Value = mat.At<float>(i, j) }; |
27 |
} |
28 |
} |
29 |
} |
30 |
|
31 |
//public static IEnumerable<Point> ToSystemPoint(this OpenCvSharp.CPlusPlus.Point[] mat) |
32 |
//{ |
33 |
// for (int i = 0; i < mat.Rows; i++) |
34 |
// { |
35 |
// for (int j = 0; j < mat.Cols; j++) |
36 |
// { |
37 |
// yield return new ImageData<float> { Row = i, Col = j, Value = mat.At<float>(i, j) }; |
38 |
// } |
39 |
// } |
40 |
//} |
41 |
|
42 |
//public static IEnumerable<ImageData<T>> ToData<T>(this OpenCvSharp.Mat mat) where T : struct |
43 |
//{ |
44 |
// for (int i = 0; i < mat.Rows; i++) |
45 |
// { |
46 |
// for (int j = 0; j < mat.Cols; j++) |
47 |
// { |
48 |
// yield return new ImageData<T> { Row = i, Col = j, Value = mat.At<T>(i, j) }; |
49 |
// } |
50 |
// } |
51 |
//} |
52 |
} |
53 |
|
54 |
|
55 |
|
56 |
public class ImageData<T> : ImageDataColleciton<T> |
57 |
{ |
58 |
public int Row { get; set; } |
59 |
public int Col { get; set; } |
60 |
public T Value { get; set; } |
61 |
} |
62 |
|
63 |
public class ImageDataColleciton<T> |
64 |
{ |
65 |
public ImageDataColleciton() |
66 |
{ |
67 |
data = new List<ImageData<T>>(); |
68 |
} |
69 |
|
70 |
public ImageDataColleciton(IEnumerable<ImageData<T>> items) |
71 |
{ |
72 |
data = items.ToList(); |
73 |
} |
74 |
|
75 |
private ICollection<ImageData<T>> data; |
76 |
|
77 |
public int Count |
78 |
{ |
79 |
get { return data.Count; } |
80 |
} |
81 |
|
82 |
// Indexer declaration. |
83 |
// If index is out of range, the temps array will throw the exception. |
84 |
public ImageData<T> this[int Row,int Col] |
85 |
{ |
86 |
get |
87 |
{ |
88 |
return data.FirstOrDefault(x=>x.Row == Row && x.Col == Col); |
89 |
} |
90 |
|
91 |
set |
92 |
{ |
93 |
data.Add(value); |
94 |
} |
95 |
} |
96 |
} |
97 |
} |