1 package kaka.cakelight;
3 import org.opencv.core.Core;
5 import java.io.FileOutputStream;
6 import java.io.IOException;
7 import java.util.HashMap;
10 public static void main(String[] args) {
11 System.loadLibrary(Core.NATIVE_LIBRARY_NAME);
13 Configuration config = Configuration.from("config.properties");
14 log("Running with config:\n" + config);
16 CakeLight cakelight = new CakeLight(config, new LedController(config));
17 if (args.length > 0) {
18 cakelight.setMode(new AmbientMode(args));
20 cakelight.setMode(new VideoMode());
22 cakelight.startLoop();
23 Runtime.getRuntime().addShutdownHook(new Thread(Main::printTimeStats));
26 public static void saveFile(byte[] data, String filepath) {
28 FileOutputStream fos = new FileOutputStream(filepath);
31 } catch (IOException e) {
36 public static void log(String msg, Object... args) {
37 System.out.println(String.format(msg, args));
40 private static HashMap<String, Double> timeDurations = new HashMap<>();
41 private static HashMap<String, Integer> timeCounts = new HashMap<>();
42 public static double timeIt(String tag, Runnable lambda) {
43 long start = System.nanoTime();
45 long end = System.nanoTime();
46 double duration = (end - start) * 0.000001;
47 // log("duration (ms): " + tag + " = " + duration);
49 if (!timeDurations.containsKey(tag)) {
50 timeDurations.put(tag, 0.0);
51 timeCounts.put(tag, 0);
53 timeDurations.put(tag, timeDurations.get(tag) + duration);
54 timeCounts.put(tag, timeCounts.get(tag) + 1);
58 private static void printTimeStats() {
59 log("Average times in ms:");
60 timeDurations.forEach((tag, duration) -> {
61 log("%s: %s", tag, duration / timeCounts.get(tag));
67 FrameGrabber läser frames asynkront
68 skickar frame till FrameConverter
70 läses av FrameProcessor/CakeLight