Implement a (kinda gross) workaround

This commit is contained in:
Matt
2019-11-21 21:49:25 -08:00
parent 48da9f5dfd
commit 87e65baf23
2 changed files with 16 additions and 9 deletions

View File

@@ -33,7 +33,7 @@ public class Main {
private static boolean manageNetwork = true; private static boolean manageNetwork = true;
private static boolean ignoreRoot = false; private static boolean ignoreRoot = false;
private static String ntClientModeServer = null; private static String ntClientModeServer = null;
private static boolean testMode = false; private static boolean testMode = true;
private static class NTLogger implements Consumer<LogMessage> { private static class NTLogger implements Consumer<LogMessage> {

View File

@@ -25,6 +25,10 @@ public class VisionProcess {
private final CVPipelineSettings driverVisionSettings = new CVPipelineSettings(); private final CVPipelineSettings driverVisionSettings = new CVPipelineSettings();
// shitty stuff
private volatile Mat lastCmameraFrame = new Mat();
private volatile CVPipelineResult lastPipelineResult;
public VisionProcess(CameraProcess cameraProcess, String name) { public VisionProcess(CameraProcess cameraProcess, String name) {
this.cameraProcess = cameraProcess; this.cameraProcess = cameraProcess;
@@ -35,6 +39,10 @@ public class VisionProcess {
// TODO: fix video modes!!! // TODO: fix video modes!!!
this.cameraRunnable = new CameraFrameRunnable(cameraProcess.getProperties().videoModes.get(0).fps); this.cameraRunnable = new CameraFrameRunnable(cameraProcess.getProperties().videoModes.get(0).fps);
lastPipelineResult = new DriverVisionPipeline.DriverPipelineResult(
null, cameraRunnable.getFrame(new Mat()), 0
);
// Thread to put frames on the dashboard // Thread to put frames on the dashboard
this.cameraStreamer = new CameraStreamer(cameraProcess, name); this.cameraStreamer = new CameraStreamer(cameraProcess, name);
this.streamRunnable = new CameraStreamerRunnable(1000L/32, cameraStreamer); this.streamRunnable = new CameraStreamerRunnable(1000L/32, cameraStreamer);
@@ -110,9 +118,10 @@ public class VisionProcess {
if (camData.getLeft().cols() > 0) { if (camData.getLeft().cols() > 0) {
// System.out.println("grabbing frame"); // System.out.println("grabbing frame");
// synchronized (frameLock) { // synchronized (frameLock) {
cameraFrame = camData.getLeft(); // cameraFrame = camData.getLeft();
// } // }
timestampMicros = camData.getRight(); timestampMicros = camData.getRight();
camData.getLeft().copyTo(lastCmameraFrame);
} }
} }
} }
@@ -126,9 +135,6 @@ public class VisionProcess {
return dst; return dst;
} }
public long getTimestampMicros() {
return timestampMicros;
}
} }
/** /**
@@ -142,9 +148,10 @@ public class VisionProcess {
@Override @Override
public void run() { public void run() {
while(!Thread.interrupted()) { while(!Thread.interrupted()) {
streamBuffer = cameraRunnable.getFrame(streamBuffer); lastCmameraFrame.copyTo(streamBuffer); // = //cameraRunnable.getFrame(streamBuffer);
if (streamBuffer.cols() > 0 && streamBuffer.rows() > 0) { if (streamBuffer.cols() > 0 && streamBuffer.rows() > 0) {
result = currentPipeline.runPipeline(streamBuffer); result = currentPipeline.runPipeline(streamBuffer);
lastPipelineResult = result;
} else { } else {
// System.err.println("Bad streambuffer mat"); // System.err.println("Bad streambuffer mat");
} }
@@ -165,11 +172,11 @@ public class VisionProcess {
@Override @Override
protected void process() { protected void process() {
CVPipelineResult latestResult = visionRunnable.result; CVPipelineResult latestResult = lastPipelineResult; //visionRunnable.result;
if (latestResult != null) { if (latestResult != null) {
Mat toStreamMat = visionRunnable.result.outputMat; Mat toStreamMat = visionRunnable.result.outputMat;
streamBuffer = toStreamMat; toStreamMat.copyTo(streamBuffer);
streamer.runStream(toStreamMat); streamer.runStream(streamBuffer);
// if (toStreamMat != null && toStreamMat.cols() > 0) { // if (toStreamMat != null && toStreamMat.cols() > 0) {
// } else { // } else {
// System.out.println("fuuuuck"); // System.out.println("fuuuuck");