mirror of
https://github.com/PhotonVision/photonvision
synced 2026-06-20 00:51:41 +00:00
Added Runnables for VisionProcess threads
This commit is contained in:
@@ -2,8 +2,10 @@ package com.chameleonvision.classabstraction;
|
||||
|
||||
import com.chameleonvision.classabstraction.camera.CameraProcess;
|
||||
import com.chameleonvision.classabstraction.pipeline.CVPipeline;
|
||||
import com.chameleonvision.classabstraction.pipeline.CVPipelineResult;
|
||||
import com.chameleonvision.classabstraction.pipeline.CVPipelineSettings;
|
||||
import com.chameleonvision.classabstraction.pipeline.DriverVisionPipeline;
|
||||
import org.opencv.core.Mat;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
@@ -14,6 +16,8 @@ public class VisionProcess {
|
||||
private final List<CVPipeline> pipelines = new ArrayList<>();
|
||||
private CVPipeline currentPipeline;
|
||||
|
||||
private final CameraFrameRunnable cameraFrameRunnable;
|
||||
|
||||
private final CVPipelineSettings driverVisionSettings = new CVPipelineSettings();
|
||||
|
||||
public VisionProcess(CameraProcess cameraProcess) {
|
||||
@@ -21,6 +25,8 @@ public class VisionProcess {
|
||||
|
||||
pipelines.add(new DriverVisionPipeline(() -> driverVisionSettings));
|
||||
setPipeline(pipelines.get(0));
|
||||
|
||||
cameraFrameRunnable = new CameraFrameRunnable();
|
||||
}
|
||||
|
||||
public void setPipeline(int pipelineIndex) {
|
||||
@@ -38,4 +44,42 @@ public class VisionProcess {
|
||||
public CVPipeline getCurrentPipeline() {
|
||||
return currentPipeline;
|
||||
}
|
||||
|
||||
protected class CameraFrameRunnable implements Runnable {
|
||||
private Mat cameraFrame = new Mat();
|
||||
private long timestampMicros;
|
||||
|
||||
private final Object frameLock = new Object();
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
while(Thread.interrupted()) {
|
||||
var camData = cameraProcess.getFrame();
|
||||
synchronized (frameLock) {
|
||||
cameraFrame = camData.getLeft();
|
||||
}
|
||||
timestampMicros = camData.getRight();
|
||||
}
|
||||
}
|
||||
|
||||
public Mat getFrame() {
|
||||
return cameraFrame;
|
||||
}
|
||||
|
||||
public long getTimestampMicros() {
|
||||
return timestampMicros;
|
||||
}
|
||||
}
|
||||
|
||||
private class VisionThread implements Runnable {
|
||||
|
||||
private CVPipelineResult result;
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
while(!Thread.interrupted()) {
|
||||
result = currentPipeline.runPipeline(cameraFrameRunnable.getFrame());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user