| 1 | package kaka.cakelight; |
| 2 | |
| 3 | import org.opencv.core.Core; |
| 4 | |
| 5 | import java.io.FileOutputStream; |
| 6 | import java.io.IOException; |
| 7 | |
| 8 | public class Main { |
| 9 | |
| 10 | public static void main(String[] args) { |
| 11 | System.loadLibrary(Core.NATIVE_LIBRARY_NAME); |
| 12 | |
| 13 | Configuration config = Configuration.from("config.properties"); |
| 14 | System.out.println("Running with config:\n" + config); |
| 15 | |
| 16 | FrameGrabber grabber = FrameGrabber.from(config); |
| 17 | grabber.prepare(); |
| 18 | Frame frame = grabber.grabFrame(); |
| 19 | double time = 0; |
| 20 | for (int i = 0; i < 100; i++) { |
| 21 | time += timeIt("frame", () -> grabber.grabFrame()); |
| 22 | } |
| 23 | System.out.println("time = " + time); |
| 24 | grabber.close(); |
| 25 | // byte[] data = frame.getData(); |
| 26 | // saveFile(data, "/home/kaka/test.img"); |
| 27 | } |
| 28 | |
| 29 | public static void saveFile(byte[] data, String filepath) { |
| 30 | try { |
| 31 | FileOutputStream fos = new FileOutputStream(filepath); |
| 32 | fos.write(data); |
| 33 | fos.close(); |
| 34 | } catch (IOException e) { |
| 35 | e.printStackTrace(); |
| 36 | } |
| 37 | } |
| 38 | |
| 39 | public static double timeIt(String tag, Runnable lambda) { |
| 40 | long start = System.nanoTime(); |
| 41 | lambda.run(); |
| 42 | long end = System.nanoTime(); |
| 43 | double duration = (end - start) * 0.000001; |
| 44 | System.out.println("duration (ms): " + tag + " = " + duration); |
| 45 | return duration; |
| 46 | } |
| 47 | } |
| 48 | |
| 49 | /* |
| 50 | FrameGrabber läser frames asynkront |
| 51 | skickar frame till FrameConverter |
| 52 | sparas i huvudklassen |
| 53 | läses av FrameProcessor/LedController |
| 54 | */ |