1 package kaka.cakelight;
3 import org.opencv.core.CvType;
4 import org.opencv.core.Mat;
5 import org.opencv.core.Size;
6 import org.opencv.imgproc.Imgproc;
8 import static kaka.cakelight.Main.saveFile;
9 import static kaka.cakelight.Main.timeIt;
13 private Configuration config;
15 private Frame(byte[] data) {
19 public static Frame of(byte[] data, Configuration config) {
20 Frame frame = new Frame(data);
21 frame.config = config;
26 private void convert() {
27 Mat src = new Mat(config.video.height, config.video.width, CvType.CV_8UC2); // 8-bit, unsigned, 2 channels
30 Mat converted = new Mat();
31 Mat resized = new Mat();
33 timeIt("total", () -> {
34 timeIt("yuyv2rgb", () -> Imgproc.cvtColor(src, converted, Imgproc.COLOR_YUV2RGB_YUYV)); // 3.5 - 4.0 ms
35 timeIt("resizing", () -> Imgproc.resize(converted, resized, new Size(config.leds.cols, config.leds.rows), 0, 0, Imgproc.INTER_AREA)); // INTER_AREA is the best for shrinking, but also the slowest (~1.5 ms)
37 // save(converted, "/home/kaka/test-converted.data");
38 // save(resized, "/home/kaka/test-resized.data");
41 private void save(Mat mat, String filepath) {
42 byte[] data = new byte[mat.cols() * mat.rows() * mat.channels()];
44 saveFile(data, filepath);
47 public byte[] getData() {