fixed Stream divisor problems see issue 19 in github issues

This commit is contained in:
Omer
2019-12-09 01:45:14 +02:00
parent 857172efc9
commit 0a051a88a3
4 changed files with 27 additions and 18 deletions

View File

@@ -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

View File

@@ -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

View File

@@ -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);
} }

View File

@@ -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": {