From cc03403a7904293324578bd59fbf9eea9fd44c8d Mon Sep 17 00:00:00 2001 From: =?utf8?q?Tomas=20Wenstr=C3=B6m?= Date: Fri, 14 Apr 2017 17:57:02 +0200 Subject: [PATCH] Added configuration for pixel format and adapted config for new video grabber --- config.properties | 15 ++++++++------- src/kaka/cakelight/Configuration.java | 13 +++++++++++++ src/kaka/cakelight/Frame.java | 4 +++- 3 files changed, 24 insertions(+), 8 deletions(-) diff --git a/config.properties b/config.properties index ad972c2..df7ee04 100644 --- a/config.properties +++ b/config.properties @@ -1,13 +1,14 @@ -# default settings - +# Video info can be found with 'v4l2-ctl --get-fmt-video' +# Supported formats: UYVY, YUYV, YVYU +video.format=UYVY video.width=720 -video.height=576 +video.height=480 video.bpp=2 -video.crop.left=28 -video.crop.right=22 -video.crop.top=8 -video.crop.bottom=120 +video.crop.left=27 +video.crop.right=29 +video.crop.top=18 +video.crop.bottom=18 leds.cols=32 leds.rows=18 diff --git a/src/kaka/cakelight/Configuration.java b/src/kaka/cakelight/Configuration.java index 0d7bf5b..94c5ddd 100644 --- a/src/kaka/cakelight/Configuration.java +++ b/src/kaka/cakelight/Configuration.java @@ -1,5 +1,7 @@ package kaka.cakelight; +import org.opencv.imgproc.Imgproc; + import java.io.FileInputStream; import java.io.IOException; import java.io.InputStream; @@ -59,12 +61,23 @@ public class Configuration { public int width; public int height; public int bpp; + public int format; public CropConfiguration crop; private VideoConfiguration(Properties prop) { width = Integer.parseInt(get(prop, "video.width", "720")); height = Integer.parseInt(get(prop, "video.height", "576")); bpp = Integer.parseInt(get(prop, "video.bpp", "2")); + switch (get(prop, "video.format", "").toUpperCase()) { + case "YUYV": + format = Imgproc.COLOR_YUV2RGB_YUYV; + break; + case "YVYU": + format = Imgproc.COLOR_YUV2RGB_YVYU; + break; + default: + format = Imgproc.COLOR_YUV2RGB_UYVY; + } crop = new CropConfiguration(prop); } diff --git a/src/kaka/cakelight/Frame.java b/src/kaka/cakelight/Frame.java index 07a6ffd..192f013 100644 --- a/src/kaka/cakelight/Frame.java +++ b/src/kaka/cakelight/Frame.java @@ -34,6 +34,7 @@ public class Frame { 3) Resize to 2 images where each led uses 2 pixels: vertical - 16 x <#leds> horizontal - <#leds> x 9 + 4) Resize to cols x rows first, then resize to a vertical and a horizontal like in (3). */ Mat src = new Mat(config.video.height, config.video.width, CvType.CV_8UC2); // 8-bit, unsigned, 2 channels src.put(0, 0, data); @@ -53,7 +54,7 @@ public class Frame { config.video.width - config.video.crop.right ); converted = new Mat(); - Imgproc.cvtColor(cropped, converted, Imgproc.COLOR_YUV2RGB_YUYV); + Imgproc.cvtColor(cropped, converted, config.video.format); // timeIt("model 1", () -> model1(converted, Imgproc.INTER_AREA)); // timeIt("model 2", () -> model2(converted, Imgproc.INTER_AREA)); timeIt("model 3", () -> model3(converted, Imgproc.INTER_AREA)); @@ -81,6 +82,7 @@ public class Frame { } 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); -- 2.11.0