mirror of
https://github.com/PhotonVision/photonvision
synced 2026-06-21 01:01:41 +00:00
fixed Stream divisor problems see issue 19 in github issues
This commit is contained in:
@@ -57,7 +57,7 @@ public class VisionProcess {
|
||||
pipelineManager = new PipelineManager(this, loadedPipelineSettings);
|
||||
|
||||
// Thread to put frames on the dashboard
|
||||
this.cameraStreamer = new CameraStreamer(cameraCapture, name);
|
||||
this.cameraStreamer = new CameraStreamer(cameraCapture, name,pipelineManager.getCurrentPipeline().settings.streamDivisor);
|
||||
this.streamRunnable = new CameraStreamerRunnable(30, cameraStreamer);
|
||||
|
||||
// Thread to process vision data
|
||||
|
||||
@@ -14,13 +14,14 @@ import org.opencv.imgproc.Imgproc;
|
||||
public class CameraStreamer {
|
||||
private final CameraCapture cameraCapture;
|
||||
private final String name;
|
||||
private StreamDivisor divisor = StreamDivisor.NONE;
|
||||
private StreamDivisor divisor;
|
||||
private CvSource cvSource;
|
||||
private final Object streamBufferLock = new Object();
|
||||
private Mat streamBuffer = new Mat();
|
||||
private Size size;
|
||||
|
||||
public CameraStreamer(CameraCapture cameraCapture, String name) {
|
||||
public CameraStreamer(CameraCapture cameraCapture, String name,StreamDivisor div) {
|
||||
this.divisor = div;
|
||||
this.cameraCapture = cameraCapture;
|
||||
this.name = name;
|
||||
this.cvSource = CameraServer.getInstance().putVideo(name,
|
||||
@@ -35,28 +36,33 @@ public class CameraStreamer {
|
||||
}
|
||||
|
||||
public void setDivisor(StreamDivisor newDivisor, boolean updateUI) {
|
||||
if (divisor != newDivisor) {
|
||||
this.divisor = newDivisor;
|
||||
var camValues = cameraCapture.getProperties();
|
||||
var newWidth = camValues.getStaticProperties().imageWidth / newDivisor.value;
|
||||
var newHeight = camValues.getStaticProperties().imageHeight / newDivisor.value;
|
||||
this.size = new Size(newWidth, newHeight);
|
||||
synchronized (streamBufferLock) {
|
||||
this.streamBuffer = new Mat(newWidth, newHeight, CvType.CV_8UC3);
|
||||
this.cvSource = CameraServer.getInstance().putVideo(this.name,
|
||||
cameraCapture.getProperties().getStaticProperties().imageWidth / divisor.value,
|
||||
cameraCapture.getProperties().getStaticProperties().imageHeight / divisor.value);
|
||||
}
|
||||
if (updateUI) {
|
||||
SocketHandler.sendFullSettings();
|
||||
}
|
||||
this.divisor = newDivisor;
|
||||
var camValues = cameraCapture.getProperties();
|
||||
var newWidth = camValues.getStaticProperties().imageWidth / newDivisor.value;
|
||||
var newHeight = camValues.getStaticProperties().imageHeight / newDivisor.value;
|
||||
this.size = new Size(newWidth, newHeight);
|
||||
synchronized (streamBufferLock) {
|
||||
this.streamBuffer = new Mat(newWidth, newHeight, CvType.CV_8UC3);
|
||||
VideoMode oldVideoMode = cvSource.getVideoMode();
|
||||
cvSource.setVideoMode(new VideoMode(oldVideoMode.pixelFormat,
|
||||
cameraCapture.getProperties().getStaticProperties().imageWidth / divisor.value,
|
||||
cameraCapture.getProperties().getStaticProperties().imageHeight / divisor.value,
|
||||
oldVideoMode.fps));
|
||||
}
|
||||
if (updateUI) {
|
||||
SocketHandler.sendFullSettings();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public StreamDivisor getDivisor() {
|
||||
return divisor;
|
||||
}
|
||||
|
||||
public void recalculateDivision() {
|
||||
setDivisor(this.divisor, false);
|
||||
}
|
||||
|
||||
public void setNewVideoMode(VideoMode newVideoMode) {
|
||||
// Trick to update cvSource and streamBuffer to the new resolution
|
||||
// Must change the cameraProcess resolution first
|
||||
|
||||
@@ -137,6 +137,8 @@ public class PipelineManager {
|
||||
}
|
||||
}
|
||||
newPipeline.initPipeline(parentProcess.getCamera());
|
||||
if(parentProcess.cameraStreamer!=null)
|
||||
parentProcess.cameraStreamer.setDivisor(newPipeline.settings.streamDivisor,true);
|
||||
if(ntIndexEntry != null) {
|
||||
ntIndexEntry.setDouble(index);
|
||||
}
|
||||
|
||||
@@ -180,6 +180,7 @@ public class SocketHandler {
|
||||
if (currentPipeline instanceof CVPipeline2d)
|
||||
((CVPipeline2d) currentPipeline).settings.point = new ArrayList<>();//This will reset the calibration
|
||||
currentCamera.setVideoMode((Integer) entry.getValue());
|
||||
currentProcess.cameraStreamer.recalculateDivision();
|
||||
break;
|
||||
}
|
||||
case "streamDivisor": {
|
||||
|
||||
Reference in New Issue
Block a user