forked from shimat/opencvsharp
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathNormalArrayOperations.cs
More file actions
84 lines (70 loc) · 2.48 KB
/
Copy pathNormalArrayOperations.cs
File metadata and controls
84 lines (70 loc) · 2.48 KB
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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
using System;
using System.Collections.Generic;
using System.Linq;
using OpenCvSharp;
namespace SamplesCS
{
/// <summary>
///
/// </summary>
class NormalArrayOperations : ISample
{
public void Run()
{
Threshold1();
Threshold2();
Threshold3();
Console.Read();
}
/// <summary>
/// Run thresholding to byte array
/// </summary>
private void Threshold1()
{
const int T = 3;
const int Max = 5;
byte[] input = {1, 2, 3, 4, 5, };
List<byte> output = new List<byte>();
Cv2.Threshold(InputArray.Create(input), OutputArray.Create(output),
T, Max, ThresholdTypes.Binary);
Console.WriteLine("Threshold: {0}", T);
Console.WriteLine("input: {0}", String.Join(",", input));
Console.WriteLine("output: {0}", String.Join(",", output));
}
/// <summary>
/// Run thresholding to short array
/// </summary>
private void Threshold2()
{
const int T = 150;
const int Max = 250;
short[] input = { 50, 100, 150, 200, 250, };
List<short> output = new List<short>();
Cv2.Threshold(InputArray.Create(input), OutputArray.Create(output),
T, Max, ThresholdTypes.Binary);
Console.WriteLine("Threshold: {0}", T);
Console.WriteLine("input: {0}", String.Join(",", input));
Console.WriteLine("output: {0}", String.Join(",", output));
}
/// <summary>
/// Run thresholding to struct array
/// </summary>
private void Threshold3()
{
const double T = 2000;
const double Max = 5000;
// threshold does not support Point (int)
Point2f[] input = {
new Point2f(1000, 1500),
new Point2f(2000, 2001),
new Point2f(500, 5000),
};
List<Point2f> output = new List<Point2f>();
Cv2.Threshold(InputArray.Create(input), OutputArray.Create(output),
T, Max, ThresholdTypes.Binary);
Console.WriteLine("Threshold: {0}", T);
Console.WriteLine("input: {0}", String.Join(",", input));
Console.WriteLine("output: {0}", String.Join(",", output));
}
}
}