-
Notifications
You must be signed in to change notification settings - Fork 0
/
Calibrator.java
75 lines (66 loc) · 2.16 KB
/
Calibrator.java
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
package pkg2014vision;
import java.io.File;
import org.bytedeco.javacpp.opencv_core.CvMat;
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
/**
*
* @author Jared "Jär Bär" Gentner
*/
public abstract class Calibrator {
public abstract Character[] calibrateHSV(CvMat image);
public static Character[] combineCalibratedArrays(Character[]
... cal){
int length = 0;
for (Character[] arr : cal) {
if(arr == null){
continue;
}
length += arr.length;
}
System.out.println("LENGTH:" + length);
Character[] ret = new Character[length];
int pos = 0;
for (Character[] arr : cal) {
if(arr == null){
continue;
}
int len = arr.length;
System.arraycopy(arr, 0, ret, pos, len);
pos += len;
}
return ret;
}
public static Threshold calibratedArrayToThreshold(Character[] cal,
int[] lower, int[] upper) {
if(cal == null)
return new Threshold(new Character[] {0,0,0}, new Character[] {0,0,0});
Character[][] thresh = new Character[((cal.length / 3) * 2)][3];
for (int i = 0; i < (cal.length / 3); ++i) {
for (int j = 0; j < 3; ++j) {
char low = (char) (cal[(i+1) * j - i] - lower[(i+1) * j - i]);
if (low < 0 || low > cal[i]) {
low = 0;
}
thresh[i][j] = low;
char high = (char) (cal[(i+1)*j - i] + upper[(i+1)*j - i]);
if (high > 255 || high < cal[i]) {
high = 255;
}
if (j == 0 && high > 180) {
high = 180;
}
thresh[i + 1][j] = high;
}
}
return new Threshold(thresh);
}
public static void writeCalibratedArray(String out, Character[] cal) {
}
public static File readCalibratedArray(String in) {
return null;
}
}