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