+ src.release();
+ cropped.release();
+ }
+
+ private void model1(Mat src, int interpolation) {
+ Mat resized = new Mat();
+ Imgproc.resize(src, resized, new Size(config.leds.cols, config.leds.rows), 0, 0, interpolation);
+ }
+
+ private void model2(Mat src, int interpolation) {
+ Mat resized = new Mat();
+ Imgproc.resize(src, resized, new Size(16, 9), 0, 0, interpolation);
+ }
+
+ private void model3(Mat src, int interpolation) {
+ colImage = new Mat();
+ rowImage = new Mat();
+ Imgproc.resize(src, colImage, new Size(config.leds.cols, 9), 0, 0, interpolation);
+ Imgproc.resize(src, rowImage, new Size(16, config.leds.rows), 0, 0, interpolation);
+ }
+
+ public Color getLedColor(ListPosition listPosition, int xy) {
+ // TODO: maybe use highest value from pixels? 100 % from 1st, 66 % from 2nd, 33 % from 3rd. colors might be strange.
+ switch (listPosition) {
+ case LEFT:
+ return interpolatedRowColor(xy, 0, 1, 2);
+ case RIGHT:
+ return interpolatedRowColor(xy, 15, 14, 13);
+ case TOP:
+ return interpolatedColColor(xy, 0, 1, 2);
+ case BOTTOM:
+ return interpolatedColColor(xy, 8, 7, 6);
+ }
+ return null;
+ }
+
+ private Color interpolatedRowColor(int y, int x1, int x2, int x3) {
+ return pixelToColor(rowImage, x3, y).interpolate(pixelToColor(rowImage, x2, y), 0.65).interpolate(pixelToColor(rowImage, x1, y), 0.65);
+ }
+
+ private Color interpolatedColColor(int x, int y1, int y2, int y3) {
+ return pixelToColor(colImage, x, y3).interpolate(pixelToColor(colImage, x, y2), 0.65).interpolate(pixelToColor(colImage, x, y1), 0.65);
+ }
+
+ private Color pixelToColor(Mat image, int x, int y) {
+ byte[] rgb = new byte[3];
+ image.get(y, x, rgb);
+ return Color.rgb(rgb[0] & 0xff, rgb[1] & 0xff, rgb[2] & 0xff);