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