mirror of
https://github.com/PhotonVision/photonvision
synced 2026-06-22 01:11:40 +00:00
Merge branch 'dev' of https://github.com/chameleon-vision/Chameleon-Vision into dev
This commit is contained in:
@@ -21,7 +21,8 @@
|
||||
</div>
|
||||
</v-col>
|
||||
<v-col :cols="3" class="colsClass">
|
||||
<CVselect v-if="isPipelineEdit === false" name="Pipeline" :list="['Driver Mode'].concat(pipelineList)"
|
||||
<CVselect v-if="isPipelineEdit === false" name="Pipeline"
|
||||
:list="['Driver Mode'].concat(pipelineList)"
|
||||
v-model="currentPipelineIndex"
|
||||
@input="handleInput('currentPipeline',currentPipelineIndex - 1)"/>
|
||||
<CVinput v-else name="Pipeline" v-model="newPipelineName" @Enter="savePipelineNameChange"/>
|
||||
@@ -252,7 +253,7 @@
|
||||
},
|
||||
selectedComponent: {
|
||||
get() {
|
||||
if (this.currentPipelineIndex === 0){
|
||||
if (this.currentPipelineIndex === 0) {
|
||||
return "InputTab"
|
||||
}
|
||||
switch (this.selectedTab) {
|
||||
@@ -273,11 +274,7 @@
|
||||
let p = this.$store.state.point.calculated;
|
||||
let fps = this.$store.state.point.fps;
|
||||
if (p !== undefined) {
|
||||
try {
|
||||
return `Pitch: ${parseFloat(p['pitch']).toFixed(2)}, Yaw: ${parseFloat(p['yaw']).toFixed(2)}, Area: ${p['area'].toFixed(2)}, FPS: ${fps.toFixed(2)}`
|
||||
} catch (e) {
|
||||
return ""
|
||||
}
|
||||
return `Pitch: ${parseFloat(p['pitch']).toFixed(2)}, Yaw: ${parseFloat(p['yaw']).toFixed(2)}, Area: ${parseFloat(p['area']).toFixed(2)}, FPS: ${parseFloat(fps).toFixed(2)}`
|
||||
} else {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
72
chameleon-server/chameleon-vision.iml
Normal file
72
chameleon-server/chameleon-vision.iml
Normal file
@@ -0,0 +1,72 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<module org.jetbrains.idea.maven.project.MavenProjectsManager.isMavenModule="true" type="JAVA_MODULE" version="4">
|
||||
<component name="NewModuleRootManager" LANGUAGE_LEVEL="JDK_12">
|
||||
<output url="file://$MODULE_DIR$/target/classes" />
|
||||
<output-test url="file://$MODULE_DIR$/target/test-classes" />
|
||||
<content url="file://$MODULE_DIR$">
|
||||
<sourceFolder url="file://$MODULE_DIR$/src/main/java" isTestSource="false" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/src/main/resources" type="java-resource" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/src/test/java" isTestSource="true" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/target" />
|
||||
</content>
|
||||
<orderEntry type="inheritedJdk" />
|
||||
<orderEntry type="sourceFolder" forTests="false" />
|
||||
<orderEntry type="library" name="Maven: io.javalin:javalin:3.4.1" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.3.31" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.jetbrains.kotlin:kotlin-stdlib:1.3.31" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.jetbrains.kotlin:kotlin-stdlib-common:1.3.31" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.jetbrains:annotations:13.0" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.3.31" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.slf4j:slf4j-api:1.7.26" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.eclipse.jetty:jetty-server:9.4.19.v20190610" level="project" />
|
||||
<orderEntry type="library" name="Maven: javax.servlet:javax.servlet-api:3.1.0" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.eclipse.jetty:jetty-http:9.4.19.v20190610" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.eclipse.jetty:jetty-util:9.4.19.v20190610" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.eclipse.jetty:jetty-io:9.4.19.v20190610" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.eclipse.jetty:jetty-webapp:9.4.19.v20190610" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.eclipse.jetty:jetty-xml:9.4.19.v20190610" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.eclipse.jetty:jetty-servlet:9.4.19.v20190610" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.eclipse.jetty:jetty-security:9.4.19.v20190610" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.eclipse.jetty.websocket:websocket-server:9.4.19.v20190610" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.eclipse.jetty.websocket:websocket-common:9.4.19.v20190610" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.eclipse.jetty.websocket:websocket-api:9.4.19.v20190610" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.eclipse.jetty.websocket:websocket-client:9.4.19.v20190610" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.eclipse.jetty:jetty-client:9.4.19.v20190610" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.eclipse.jetty.websocket:websocket-servlet:9.4.19.v20190610" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.json:json:20190722" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.slf4j:slf4j-nop:1.7.26" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.apache.commons:commons-math3:3.6.1" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.msgpack:msgpack-core:0.8.18" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.msgpack:jackson-dataformat-msgpack:0.8.18" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.apache.commons:commons-lang3:3.9" level="project" />
|
||||
<orderEntry type="library" name="Maven: com.fasterxml.jackson.core:jackson-core:2.10.1" level="project" />
|
||||
<orderEntry type="library" name="Maven: com.fasterxml.jackson.core:jackson-annotations:2.10.1" level="project" />
|
||||
<orderEntry type="library" name="Maven: com.fasterxml.jackson.core:jackson-databind:2.10.1" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.junit.jupiter:junit-jupiter-engine:5.5.2" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.apiguardian:apiguardian-api:1.1.0" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.junit.platform:junit-platform-engine:1.5.2" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.opentest4j:opentest4j:1.2.0" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.junit.platform:junit-platform-commons:1.5.2" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.junit.jupiter:junit-jupiter-api:5.5.2" level="project" />
|
||||
<orderEntry type="library" name="Maven: edu.wpi.first.cscore:cscore-java:2020.1.1-beta-3-12-gb8c1024" level="project" />
|
||||
<orderEntry type="library" name="Maven: edu.wpi.first.cscore:cscore-jni:linuxaarch64bionic:2020.1.1-beta-3-12-gb8c1024" level="project" />
|
||||
<orderEntry type="library" name="Maven: edu.wpi.first.cscore:cscore-jni:linuxraspbian:2020.1.1-beta-3-12-gb8c1024" level="project" />
|
||||
<orderEntry type="library" name="Maven: edu.wpi.first.cscore:cscore-jni:linuxx86-64:2020.1.1-beta-3-12-gb8c1024" level="project" />
|
||||
<orderEntry type="library" name="Maven: edu.wpi.first.cscore:cscore-jni:osxx86-64:2020.1.1-beta-3-12-gb8c1024" level="project" />
|
||||
<orderEntry type="library" name="Maven: edu.wpi.first.cscore:cscore-jni:windowsx86-64:2020.1.1-beta-3-12-gb8c1024" level="project" />
|
||||
<orderEntry type="library" name="Maven: edu.wpi.first.cameraserver:cameraserver-java:2020.1.1-beta-3-12-gb8c1024" level="project" />
|
||||
<orderEntry type="library" name="Maven: edu.wpi.first.ntcore:ntcore-java:2020.1.1-beta-3-12-gb8c1024" level="project" />
|
||||
<orderEntry type="library" name="Maven: edu.wpi.first.ntcore:ntcore-jni:osxx86-64:2020.1.1-beta-3-12-gb8c1024" level="project" />
|
||||
<orderEntry type="library" name="Maven: edu.wpi.first.ntcore:ntcore-jni:linuxraspbian:2020.1.1-beta-3-12-gb8c1024" level="project" />
|
||||
<orderEntry type="library" name="Maven: edu.wpi.first.ntcore:ntcore-jni:linuxx86-64:2020.1.1-beta-3-12-gb8c1024" level="project" />
|
||||
<orderEntry type="library" name="Maven: edu.wpi.first.ntcore:ntcore-jni:linuxaarch64bionic:2020.1.1-beta-3-12-gb8c1024" level="project" />
|
||||
<orderEntry type="library" name="Maven: edu.wpi.first.ntcore:ntcore-jni:windowsx86-64:2020.1.1-beta-3-12-gb8c1024" level="project" />
|
||||
<orderEntry type="library" name="Maven: edu.wpi.first.wpiutil:wpiutil-java:2020.1.1-beta-3-12-gb8c1024" level="project" />
|
||||
<orderEntry type="library" name="Maven: edu.wpi.first.thirdparty.frc2020.opencv:opencv-java:3.4.7-2" level="project" />
|
||||
<orderEntry type="library" name="Maven: edu.wpi.first.thirdparty.frc2020.opencv:opencv-jni:linuxaarch64bionic:3.4.7-2" level="project" />
|
||||
<orderEntry type="library" name="Maven: edu.wpi.first.thirdparty.frc2020.opencv:opencv-jni:linuxraspbian:3.4.7-2" level="project" />
|
||||
<orderEntry type="library" name="Maven: edu.wpi.first.thirdparty.frc2020.opencv:opencv-jni:linuxx86-64:3.4.7-2" level="project" />
|
||||
<orderEntry type="library" name="Maven: edu.wpi.first.thirdparty.frc2020.opencv:opencv-jni:osxx86-64:3.4.7-2" level="project" />
|
||||
<orderEntry type="library" name="Maven: edu.wpi.first.thirdparty.frc2020.opencv:opencv-jni:windowsx86-64:3.4.7-2" level="project" />
|
||||
</component>
|
||||
</module>
|
||||
@@ -2,45 +2,65 @@ package com.chameleonvision.util;
|
||||
|
||||
public class MemoryManager {
|
||||
|
||||
private static final long MEGABYTE_FACTOR = 1024L * 1024L;
|
||||
private static final long MEGABYTE_FACTOR = 1024L * 1024L;
|
||||
|
||||
private int collectionThreshold;
|
||||
private int lastUsedMb = 0;
|
||||
private int collectionThreshold;
|
||||
private long collectionPeriodMillis = -1;
|
||||
|
||||
public MemoryManager(int collectionThreshold) {
|
||||
this.collectionThreshold = collectionThreshold;
|
||||
}
|
||||
private double lastUsedMb = 0;
|
||||
private long lastCollectionMillis = 0;
|
||||
|
||||
public void setCollectionThreshold(int collectionThreshold) {
|
||||
this.collectionThreshold = collectionThreshold;
|
||||
}
|
||||
public MemoryManager(int collectionThreshold) {
|
||||
this.collectionThreshold = collectionThreshold;
|
||||
}
|
||||
|
||||
public static long getUsedMemory() {
|
||||
return Runtime.getRuntime().totalMemory() - Runtime.getRuntime().freeMemory();
|
||||
}
|
||||
public MemoryManager(int collectionThreshold, long collectionPeriodMillis) {
|
||||
this.collectionThreshold = collectionThreshold;
|
||||
this.collectionPeriodMillis = collectionPeriodMillis;
|
||||
}
|
||||
|
||||
public static int getUsedMemoryMB() {
|
||||
return (int) (getUsedMemory() / MEGABYTE_FACTOR);
|
||||
}
|
||||
public void setCollectionThreshold(int collectionThreshold) {
|
||||
this.collectionThreshold = collectionThreshold;
|
||||
}
|
||||
|
||||
private static void collect() {
|
||||
System.gc();
|
||||
System.runFinalization();
|
||||
}
|
||||
public void setCollectionPeriodMillis(long collectionPeriodMillis) {
|
||||
this.collectionPeriodMillis = collectionPeriodMillis;
|
||||
}
|
||||
|
||||
public void run() { run(false); }
|
||||
private static long getUsedMemory() {
|
||||
return Runtime.getRuntime().totalMemory() - Runtime.getRuntime().freeMemory();
|
||||
}
|
||||
|
||||
public void run(boolean print) {
|
||||
var usedMem = getUsedMemoryMB();
|
||||
private static double getUsedMemoryMB() {
|
||||
return ((double) getUsedMemory() / MEGABYTE_FACTOR);
|
||||
}
|
||||
|
||||
if (usedMem != lastUsedMb) {
|
||||
lastUsedMb = usedMem;
|
||||
if (print) System.out.printf("Memory usage: %dMB\n", usedMem);
|
||||
}
|
||||
private void collect() {
|
||||
System.gc();
|
||||
System.runFinalization();
|
||||
}
|
||||
|
||||
if (usedMem >= collectionThreshold) {
|
||||
collect();
|
||||
if (print) System.out.printf("Garbage collected at %dMB\n", usedMem);
|
||||
}
|
||||
}
|
||||
public void run() {
|
||||
run(false);
|
||||
}
|
||||
|
||||
public void run(boolean print) {
|
||||
var usedMem = getUsedMemoryMB();
|
||||
|
||||
if (usedMem != lastUsedMb) {
|
||||
lastUsedMb = usedMem;
|
||||
if (print) System.out.printf("Memory usage: %.2fMB\n", usedMem);
|
||||
}
|
||||
|
||||
boolean collectionThresholdPassed = usedMem >= collectionThreshold;
|
||||
boolean collectionPeriodPassed = collectionPeriodMillis != -1 && (System.currentTimeMillis() - lastCollectionMillis >= collectionPeriodMillis);
|
||||
|
||||
if (collectionThresholdPassed || collectionPeriodPassed) {
|
||||
collect();
|
||||
lastCollectionMillis = System.currentTimeMillis();
|
||||
if (print) {
|
||||
System.out.printf("Garbage collected at %.2fMB\n", usedMem);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -159,16 +159,18 @@ public class VisionProcess {
|
||||
} else if (data instanceof CVPipeline3d.CVPipeline3dResult) {
|
||||
// TODO: (2.1) 3d stuff in UI
|
||||
} else {
|
||||
center.add(0.0);
|
||||
center.add(0.0);
|
||||
calculated.put("pitch", 0);
|
||||
calculated.put("yaw", 0);
|
||||
center.add(null);
|
||||
center.add(null);
|
||||
calculated.put("pitch", null);
|
||||
calculated.put("yaw", null);
|
||||
calculated.put("area", null);
|
||||
}
|
||||
} else {
|
||||
center.add(0.0);
|
||||
center.add(0.0);
|
||||
calculated.put("pitch", 0);
|
||||
calculated.put("yaw", 0);
|
||||
center.add(null);
|
||||
center.add(null);
|
||||
calculated.put("pitch", null);
|
||||
calculated.put("yaw", null);
|
||||
calculated.put("area", null);
|
||||
}
|
||||
point.put("fps", visionRunnable.fps);
|
||||
point.put("calculated", calculated);
|
||||
@@ -246,6 +248,7 @@ public class VisionProcess {
|
||||
Mat camFrame = camData.getLeft();
|
||||
if (camFrame.cols() > 0 && camFrame.rows() > 0) {
|
||||
CVPipelineResult result = pipelineManager.getCurrentPipeline().runPipeline(camFrame);
|
||||
camFrame.release();
|
||||
|
||||
if (result != null) {
|
||||
result.setTimestamp(camData.getRight());
|
||||
@@ -258,7 +261,6 @@ public class VisionProcess {
|
||||
try {
|
||||
streamFrameQueue.clear();
|
||||
streamFrameQueue.add(lastPipelineResult.outputMat);
|
||||
camFrame.release();
|
||||
} catch (Exception e) {
|
||||
Debug.printInfo("Vision running faster than stream.");
|
||||
}
|
||||
@@ -284,6 +286,7 @@ public class VisionProcess {
|
||||
private class CameraStreamerRunnable extends LoopingRunnable {
|
||||
|
||||
final CameraStreamer streamer;
|
||||
private Mat bufferMat = new Mat();
|
||||
|
||||
private CameraStreamerRunnable(int cameraFPS, CameraStreamer streamer) {
|
||||
// add 2 FPS to allow for a bit of overhead
|
||||
@@ -295,7 +298,16 @@ public class VisionProcess {
|
||||
protected void process() {
|
||||
if (!streamFrameQueue.isEmpty()) {
|
||||
try {
|
||||
streamer.runStream(streamFrameQueue.take());
|
||||
|
||||
bufferMat = streamFrameQueue.take();
|
||||
|
||||
try {
|
||||
streamer.runStream(bufferMat);
|
||||
bufferMat.release();
|
||||
} catch (Exception e) {
|
||||
// do nothing
|
||||
}
|
||||
|
||||
} catch (InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
@@ -40,7 +40,10 @@ public class USBCameraCapture implements CameraCapture {
|
||||
public Pair<Mat, Long> getFrame() {
|
||||
Long deltaTime;
|
||||
// TODO: Why multiply by 1000 here?
|
||||
deltaTime = cvSink.grabFrame(imageBuffer) * 1000L;
|
||||
Mat tempMat = new Mat();
|
||||
deltaTime = cvSink.grabFrame(tempMat) * 1000L;
|
||||
tempMat.copyTo(imageBuffer);
|
||||
tempMat.release();
|
||||
return Pair.of(imageBuffer, deltaTime);
|
||||
}
|
||||
|
||||
|
||||
@@ -79,7 +79,7 @@ public class CVPipeline2d extends CVPipeline<CVPipeline2dResult, CVPipeline2dSet
|
||||
outputMatPipe = new OutputMatPipe(settings.isBinary);
|
||||
}
|
||||
|
||||
private final MemoryManager memManager = new MemoryManager(120);
|
||||
private final MemoryManager memManager = new MemoryManager(120, 20000);
|
||||
|
||||
@Override
|
||||
public CVPipeline2dResult runPipeline(Mat inputMat) {
|
||||
@@ -125,10 +125,10 @@ public class CVPipeline2d extends CVPipeline<CVPipeline2dResult, CVPipeline2dSet
|
||||
Pair<Mat, Long> rotateFlipResult = rotateFlipPipe.run(inputMat);
|
||||
totalPipelineTimeNanos += rotateFlipResult.getRight();
|
||||
|
||||
Pair<Mat, Long> blurResult = blurPipe.run(rotateFlipResult.getLeft());
|
||||
totalPipelineTimeNanos += blurResult.getRight();
|
||||
// Pair<Mat, Long> blurResult = blurPipe.run(rotateFlipResult.getLeft());
|
||||
// totalPipelineTimeNanos += blurResult.getRight();
|
||||
|
||||
Pair<Mat, Long> erodeDilateResult = erodeDilatePipe.run(blurResult.getLeft());
|
||||
Pair<Mat, Long> erodeDilateResult = erodeDilatePipe.run(rotateFlipResult.getLeft());
|
||||
totalPipelineTimeNanos += erodeDilateResult.getRight();
|
||||
|
||||
Pair<Mat, Long> hsvResult = hsvPipe.run(erodeDilateResult.getLeft());
|
||||
@@ -163,7 +163,7 @@ public class CVPipeline2d extends CVPipeline<CVPipeline2dResult, CVPipeline2dSet
|
||||
if (Main.testMode) {
|
||||
pipelineTimeString += String.format("PipeInit: %.2fms, ", pipeInitTimeNanos / 1000000.0);
|
||||
pipelineTimeString += String.format("RotateFlip: %.2fms, ", rotateFlipResult.getRight() / 1000000.0);
|
||||
pipelineTimeString += String.format("Blur: %.2fms, ", blurResult.getRight() / 1000000.0);
|
||||
// pipelineTimeString += String.format("Blur: %.2fms, ", blurResult.getRight() / 1000000.0);
|
||||
pipelineTimeString += String.format("ErodeDilate: %.2fms, ", erodeDilateResult.getRight() / 1000000.0);
|
||||
pipelineTimeString += String.format("HSV: %.2fms, ", hsvResult.getRight() / 1000000.0);
|
||||
pipelineTimeString += String.format("FindContours: %.2fms, ", findContoursResult.getRight() / 1000000.0);
|
||||
@@ -184,7 +184,7 @@ public class CVPipeline2d extends CVPipeline<CVPipeline2dResult, CVPipeline2dSet
|
||||
System.out.printf("full pipeline run time was %.3fms (%.2fFPS)\n", truePipelineTimeMillis, truePipelineFPS);
|
||||
}
|
||||
|
||||
memManager.run(Main.testMode);
|
||||
memManager.run();
|
||||
|
||||
return new CVPipeline2dResult(collect2dTargetsResult.getLeft(), draw2dContoursResult.getLeft(), totalPipelineTimeNanos);
|
||||
}
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
package com.chameleonvision.vision.pipeline;
|
||||
|
||||
import com.chameleonvision.Main;
|
||||
import com.chameleonvision.util.MemoryManager;
|
||||
import com.chameleonvision.vision.camera.CameraCapture;
|
||||
import com.chameleonvision.vision.pipeline.pipes.Draw2dContoursPipe;
|
||||
@@ -20,7 +19,7 @@ public class DriverVisionPipeline extends CVPipeline<DriverPipelineResult, CVPip
|
||||
private Draw2dContoursPipe.Draw2dContoursSettings draw2dContoursSettings = new Draw2dContoursPipe.Draw2dContoursSettings();
|
||||
private final List<RotatedRect> blankList = List.of();
|
||||
|
||||
private final MemoryManager memoryManager = new MemoryManager(50);
|
||||
private final MemoryManager memoryManager = new MemoryManager(200, 20000);
|
||||
|
||||
public DriverVisionPipeline(CVPipelineSettings settings) {
|
||||
super(settings);
|
||||
@@ -38,15 +37,13 @@ public class DriverVisionPipeline extends CVPipeline<DriverPipelineResult, CVPip
|
||||
@Override
|
||||
public DriverPipelineResult runPipeline(Mat inputMat) {
|
||||
|
||||
// inputMat.copyTo(outputMat);
|
||||
|
||||
rotateFlipPipe.setConfig(settings.rotationMode, settings.flipMode);
|
||||
draw2dContoursPipe.setConfig(false, cameraCapture.getProperties().getStaticProperties());
|
||||
|
||||
Pair<Mat, Long> rotateFlipResult = rotateFlipPipe.run(inputMat);
|
||||
Pair<Mat, Long> draw2dContoursResult = draw2dContoursPipe.run(Pair.of(rotateFlipResult.getLeft(), blankList));
|
||||
|
||||
memoryManager.run(Main.testMode);
|
||||
memoryManager.run();
|
||||
|
||||
return new DriverPipelineResult(null, draw2dContoursResult.getLeft(), 0);
|
||||
}
|
||||
|
||||
@@ -25,20 +25,20 @@ public class BlurPipe implements Pipe<Mat, Mat> {
|
||||
public Pair<Mat, Long> run(Mat input) {
|
||||
long processStartNanos = System.nanoTime();
|
||||
|
||||
if (blurSize > 0) {
|
||||
input.copyTo(processBuffer);
|
||||
try {
|
||||
Imgproc.blur(processBuffer, processBuffer, new Size(blurSize, blurSize));
|
||||
processBuffer.copyTo(outputMat);
|
||||
processBuffer.release();
|
||||
} catch (CvException e) {
|
||||
System.err.println("(BlurPipe) Exception thrown by OpenCV: \n" + e.getMessage());
|
||||
}
|
||||
} else {
|
||||
input.copyTo(outputMat);
|
||||
}
|
||||
// if (blurSize > 0) {
|
||||
// input.copyTo(processBuffer);
|
||||
// try {
|
||||
// Imgproc.blur(processBuffer, processBuffer, new Size(blurSize, blurSize));
|
||||
// processBuffer.copyTo(outputMat);
|
||||
// processBuffer.release();
|
||||
// } catch (CvException e) {
|
||||
// System.err.println("(BlurPipe) Exception thrown by OpenCV: \n" + e.getMessage());
|
||||
// }
|
||||
// } else {
|
||||
// input.copyTo(outputMat);
|
||||
// }
|
||||
|
||||
long processTime = System.nanoTime() - processStartNanos;
|
||||
return Pair.of(outputMat, processTime);
|
||||
return Pair.of(input, processTime);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,6 +21,7 @@ public class Draw2dContoursPipe implements Pipe<Pair<Mat, List<RotatedRect>>, Ma
|
||||
|
||||
private Point[] vertices = new Point[4];
|
||||
private List<MatOfPoint> drawnContours = new ArrayList<>();
|
||||
private MatOfPoint contour = new MatOfPoint();
|
||||
@SuppressWarnings("FieldCanBeLocal")
|
||||
private Point xMax = new Point(), xMin = new Point(), yMax = new Point(), yMin = new Point();
|
||||
|
||||
@@ -41,7 +42,7 @@ public class Draw2dContoursPipe implements Pipe<Pair<Mat, List<RotatedRect>>, Ma
|
||||
|
||||
if (settings.showCrosshair || settings.showCentroid || settings.showMaximumBox || settings.showRotatedBox) {
|
||||
// input.getLeft().copyTo(processBuffer);
|
||||
processBuffer = input.getLeft();
|
||||
// processBuffer = input.getLeft();
|
||||
|
||||
if (input.getRight().size() > 0) {
|
||||
for (int i = 0; i < input.getRight().size(); i++) {
|
||||
@@ -55,21 +56,24 @@ public class Draw2dContoursPipe implements Pipe<Pair<Mat, List<RotatedRect>>, Ma
|
||||
drawnContours.clear();
|
||||
|
||||
r.points(vertices);
|
||||
MatOfPoint contour = new MatOfPoint(vertices);
|
||||
contour.fromArray(vertices);
|
||||
// MatOfPoint contour = new MatOfPoint(vertices);
|
||||
drawnContours.add(contour);
|
||||
|
||||
if (settings.showCentroid) {
|
||||
Imgproc.circle(processBuffer, r.center, 3, Helpers.colorToScalar(settings.centroidColor));
|
||||
Imgproc.circle(input.getLeft(), r.center, 3, Helpers.colorToScalar(settings.centroidColor));
|
||||
}
|
||||
|
||||
if (settings.showRotatedBox) {
|
||||
Imgproc.drawContours(processBuffer, drawnContours, 0, Helpers.colorToScalar(settings.rotatedBoxColor), settings.boxOutlineSize);
|
||||
Imgproc.drawContours(input.getLeft(), drawnContours, 0, Helpers.colorToScalar(settings.rotatedBoxColor), settings.boxOutlineSize);
|
||||
}
|
||||
|
||||
if (settings.showMaximumBox) {
|
||||
Rect box = Imgproc.boundingRect(contour);
|
||||
Imgproc.rectangle(processBuffer, new Point(box.x, box.y), new Point((box.x + box.width), (box.y + box.height)), Helpers.colorToScalar(settings.maximumBoxColor), settings.boxOutlineSize);
|
||||
Imgproc.rectangle(input.getLeft(), new Point(box.x, box.y), new Point((box.x + box.width), (box.y + box.height)), Helpers.colorToScalar(settings.maximumBoxColor), settings.boxOutlineSize);
|
||||
}
|
||||
|
||||
// contour.release();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -78,8 +82,8 @@ public class Draw2dContoursPipe implements Pipe<Pair<Mat, List<RotatedRect>>, Ma
|
||||
xMin.set(new double[] {camProps.centerX - 10, camProps.centerY});
|
||||
yMax.set(new double[] {camProps.centerX, camProps.centerY + 10});
|
||||
yMin.set(new double[] {camProps.centerX, camProps.centerY - 10});
|
||||
Imgproc.line(processBuffer, xMax, xMin, Helpers.colorToScalar(settings.crosshairColor), 2);
|
||||
Imgproc.line(processBuffer, yMax, yMin, Helpers.colorToScalar(settings.crosshairColor), 2);
|
||||
Imgproc.line(input.getLeft(), xMax, xMin, Helpers.colorToScalar(settings.crosshairColor), 2);
|
||||
Imgproc.line(input.getLeft(), yMax, yMin, Helpers.colorToScalar(settings.crosshairColor), 2);
|
||||
}
|
||||
|
||||
// processBuffer.copyTo(outputMat);
|
||||
@@ -89,7 +93,7 @@ public class Draw2dContoursPipe implements Pipe<Pair<Mat, List<RotatedRect>>, Ma
|
||||
}
|
||||
|
||||
long processTime = System.nanoTime() - processStartNanos;
|
||||
return Pair.of(processBuffer, processTime);
|
||||
return Pair.of(input.getLeft(), processTime);
|
||||
}
|
||||
|
||||
public static class Draw2dContoursSettings {
|
||||
|
||||
@@ -31,23 +31,23 @@ public class ErodeDilatePipe implements Pipe<Mat, Mat> {
|
||||
long processStartNanos = System.nanoTime();
|
||||
|
||||
if (erode || dilate) {
|
||||
input.copyTo(processBuffer);
|
||||
// input.copyTo(processBuffer);
|
||||
|
||||
if (erode) {
|
||||
Imgproc.erode(processBuffer, processBuffer, kernel);
|
||||
Imgproc.erode(input, input, kernel);
|
||||
}
|
||||
|
||||
if (dilate) {
|
||||
Imgproc.dilate(processBuffer, processBuffer, kernel);
|
||||
Imgproc.dilate(input, input, kernel);
|
||||
}
|
||||
|
||||
processBuffer.copyTo(outputMat);
|
||||
processBuffer.release();
|
||||
// processBuffer.copyTo(outputMat);
|
||||
// processBuffer.release();
|
||||
} else {
|
||||
input.copyTo(outputMat);
|
||||
// input.copyTo(outputMat);
|
||||
}
|
||||
|
||||
long processTime = System.nanoTime() - processStartNanos;
|
||||
return Pair.of(outputMat, processTime);
|
||||
return Pair.of(input, processTime);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -128,17 +128,13 @@ public class GroupContoursPipe implements Pipe<List<MatOfPoint>, List<RotatedRec
|
||||
switch (intersection) {
|
||||
case Up: {
|
||||
if (intersectionY < massY) {
|
||||
if (mA > 0 && mB < 0) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
case Down: {
|
||||
if (intersectionY > massY) {
|
||||
if (mA < 0 && mB > 0) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
@@ -29,18 +29,15 @@ public class HsvPipe implements Pipe<Mat, Mat> {
|
||||
public Pair<Mat, Long> run(Mat input) {
|
||||
long processStartNanos = System.nanoTime();
|
||||
|
||||
input.copyTo(processBuffer);
|
||||
input.copyTo(outputMat);
|
||||
|
||||
try {
|
||||
Imgproc.cvtColor(processBuffer, processBuffer, Imgproc.COLOR_BGR2HSV, 3);
|
||||
Core.inRange(processBuffer, hsvLower, hsvUpper, processBuffer);
|
||||
Imgproc.cvtColor(outputMat, outputMat, Imgproc.COLOR_BGR2HSV, 3);
|
||||
Core.inRange(outputMat, hsvLower, hsvUpper, outputMat);
|
||||
} catch (CvException e) {
|
||||
System.err.println("(HsvPipe) Exception thrown by OpenCV: \n" + e.getMessage());
|
||||
}
|
||||
|
||||
processBuffer.copyTo(outputMat);
|
||||
processBuffer.release();
|
||||
|
||||
long processTime = System.nanoTime() - processStartNanos;
|
||||
return Pair.of(outputMat, processTime);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user