Added Runnables for VisionProcess threads

This commit is contained in:
Banks Troutman
2019-11-15 16:01:50 -05:00
parent cd21186bf7
commit 1e613ee342
9 changed files with 108 additions and 62 deletions

View File

@@ -8,10 +8,9 @@ public interface CameraProcess {
/**
* Get the next camera frame
* @param frame the frame to copy the image into
* @return a Pair of the captured image and how long it took to grab the frame (in uS)
*/
Pair<Mat, Long> getFrame(Mat frame);
Pair<Mat, Long> getFrame();
/**
* Set the exposure of the camera

View File

@@ -1,6 +1,5 @@
package com.chameleonvision.classabstraction.camera;
import com.chameleonvision.vision.camera.CameraManager;
import com.chameleonvision.vision.camera.StreamDivisor;
import com.chameleonvision.web.ServerHandler;
import edu.wpi.cscore.CvSource;
@@ -11,7 +10,6 @@ import org.opencv.core.Size;
import org.opencv.imgproc.Imgproc;
public class CameraStreamer {
private final CameraProcess cameraProcess;
private final String name;
private StreamDivisor divisor = StreamDivisor.NONE;
@@ -27,7 +25,6 @@ public class CameraStreamer {
cameraProcess.getProperties().staticProperties.imageHeight / divisor.value);
}
public void setDivisor(StreamDivisor newDivisor) {
this.divisor = newDivisor;
var camValues = cameraProcess.getProperties();
@@ -42,9 +39,7 @@ public class CameraStreamer {
ServerHandler.sendFullSettings();
}
public void runStream() {
var newFrame = cameraProcess.getFrame(streamBuffer);
var image = newFrame.getLeft();
public void runStream(Mat image) {
if (divisor.value != 1) {
var camVal = cameraProcess.getProperties().staticProperties;
var newWidth = camVal.imageWidth / divisor.value;

View File

@@ -28,13 +28,12 @@ public class USBCameraProcess implements CameraProcess {
}
@Override
public Pair<Mat, Long> getFrame(Mat frame) {
public Pair<Mat, Long> getFrame() {
Long deltaTime;
synchronized (cvSink) {
deltaTime = cvSink.grabFrame(imageBuffer) * 1000L;
imageBuffer.copyTo(frame);
}
return Pair.of(frame, deltaTime);
return Pair.of(imageBuffer, deltaTime);
}
@Override