mirror of
https://github.com/PhotonVision/photonvision
synced 2026-06-20 00:51:41 +00:00
Add video mode change support to VisionProcess
This commit is contained in:
@@ -6,6 +6,7 @@ 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 edu.wpi.cscore.VideoMode;
|
||||
import org.opencv.core.Mat;
|
||||
|
||||
import java.util.ArrayList;
|
||||
@@ -18,6 +19,7 @@ public class VisionProcess {
|
||||
private final CameraFrameRunnable cameraRunnable;
|
||||
private final CameraStramerRunnable streamRunnable;
|
||||
private final VisionProcessRunnable visionRunnable;
|
||||
private final CameraStreamer cameraStreamer;
|
||||
private CVPipeline currentPipeline;
|
||||
|
||||
private final CVPipelineSettings driverVisionSettings = new CVPipelineSettings();
|
||||
@@ -33,7 +35,8 @@ public class VisionProcess {
|
||||
new Thread(cameraRunnable).start();
|
||||
|
||||
// Thread to put frames on the dashboard
|
||||
this.streamRunnable = new CameraStramerRunnable(streamTimeMs, new CameraStreamer(cameraProcess, name));
|
||||
this.cameraStreamer = new CameraStreamer(cameraProcess, name);
|
||||
this.streamRunnable = new CameraStramerRunnable(streamTimeMs, cameraStreamer);
|
||||
new Thread(streamRunnable).start();
|
||||
|
||||
// Thread to process vision data
|
||||
@@ -42,7 +45,6 @@ public class VisionProcess {
|
||||
|
||||
}
|
||||
|
||||
|
||||
public void setPipeline(int pipelineIndex) {
|
||||
CVPipeline newPipeline = pipelines.get(pipelineIndex);
|
||||
if (newPipeline != null) {
|
||||
@@ -55,6 +57,11 @@ public class VisionProcess {
|
||||
currentPipeline.initPipeline(cameraProcess);
|
||||
}
|
||||
|
||||
public void setVideoMode(VideoMode newMode) {
|
||||
cameraProcess.setVideoMode(newMode);
|
||||
cameraStreamer.setNewVideoMode(newMode);
|
||||
}
|
||||
|
||||
public CVPipeline getCurrentPipeline() {
|
||||
return currentPipeline;
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package com.chameleonvision.classabstraction.camera;
|
||||
|
||||
import edu.wpi.cscore.VideoMode;
|
||||
import org.apache.commons.lang3.tuple.Pair;
|
||||
import org.opencv.core.Mat;
|
||||
|
||||
@@ -23,4 +24,10 @@ public interface CameraProcess {
|
||||
* @param brightness the new brightness to set the camera to
|
||||
*/
|
||||
void setBrightness(int brightness);
|
||||
|
||||
/**
|
||||
* Set the video mode (fps and resolution) of the camera
|
||||
* @param mode the wanted mode
|
||||
*/
|
||||
void setVideoMode(VideoMode mode);
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@ package com.chameleonvision.classabstraction.camera;
|
||||
import com.chameleonvision.vision.camera.StreamDivisor;
|
||||
import com.chameleonvision.web.ServerHandler;
|
||||
import edu.wpi.cscore.CvSource;
|
||||
import edu.wpi.cscore.VideoMode;
|
||||
import edu.wpi.first.cameraserver.CameraServer;
|
||||
import org.opencv.core.CvType;
|
||||
import org.opencv.core.Mat;
|
||||
@@ -39,6 +40,12 @@ public class CameraStreamer {
|
||||
ServerHandler.sendFullSettings();
|
||||
}
|
||||
|
||||
public void setNewVideoMode(VideoMode newVideoMode) {
|
||||
// Trick to update cvSource and streamBuffer to the new resolution
|
||||
// Must change the cameraProcess resolution first
|
||||
setDivisor(divisor);
|
||||
}
|
||||
|
||||
public void runStream(Mat image) {
|
||||
image.copyTo(streamBuffer);
|
||||
if (divisor.value != 1) {
|
||||
|
||||
@@ -13,7 +13,7 @@ public class USBCameraProcess implements CameraProcess {
|
||||
private final UsbCamera baseCamera;
|
||||
private final CvSink cvSink;
|
||||
private Mat imageBuffer = new Mat();
|
||||
public final CameraProperties properties;
|
||||
public CameraProperties properties;
|
||||
|
||||
public USBCameraProcess(UsbCamera camera, CameraConfig config) {
|
||||
baseCamera = camera;
|
||||
@@ -53,4 +53,14 @@ public class USBCameraProcess implements CameraProcess {
|
||||
System.err.println("Current camera does not support brightness change");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setVideoMode(VideoMode mode) {
|
||||
try {
|
||||
baseCamera.setVideoMode(mode);
|
||||
properties = new CameraProperties(baseCamera, properties.FOV);
|
||||
} catch (VideoException e) {
|
||||
System.err.println("Current camera does not support resolution change");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user