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);
17 cakelight.setMode(new VideoMode());
18 cakelight.startLoop();
20 // Thread.sleep(1000);
21 // } catch (InterruptedException e) {
22 // e.printStackTrace();
24 // cakelight.setMode(null);
25 Runtime.getRuntime().addShutdownHook(new Thread(Main::printTimeStats));
28 public static void saveFile(byte[] data, String filepath) {
30 FileOutputStream fos = new FileOutputStream(filepath);
33 } catch (IOException e) {
38 public static void log(String msg, Object... args) {
39 System.out.println(String.format(msg, args));
42 private static HashMap<String, Double> timeDurations = new HashMap<>();
43 private static HashMap<String, Integer> timeCounts = new HashMap<>();
44 public static double timeIt(String tag, Runnable lambda) {
45 long start = System.nanoTime();
47 long end = System.nanoTime();
48 double duration = (end - start) * 0.000001;
49 // log("duration (ms): " + tag + " = " + duration);
51 if (!timeDurations.containsKey(tag)) {
52 timeDurations.put(tag, 0.0);
53 timeCounts.put(tag, 0);
55 timeDurations.put(tag, timeDurations.get(tag) + duration);
56 timeCounts.put(tag, timeCounts.get(tag) + 1);
60 private static void printTimeStats() {
61 log("Average times in ms:");
62 timeDurations.forEach((tag, duration) -> {
63 log("%s: %s", tag, duration / timeCounts.get(tag));
69 FrameGrabber läser frames asynkront
70 skickar frame till FrameConverter
72 läses av FrameProcessor/CakeLight