Properly handle empty frames from cscore (#1296)

This commit is contained in:
Matt
2024-03-21 23:23:56 -04:00
committed by GitHub
parent 15da06b24c
commit 2d8b1ec66d
2 changed files with 13 additions and 4 deletions

View File

@@ -18,11 +18,14 @@
package org.photonvision.vision.frame.provider;
import edu.wpi.first.cscore.CvSink;
import org.photonvision.common.util.math.MathUtils;
import org.photonvision.common.logging.LogGroup;
import org.photonvision.common.logging.Logger;
import org.photonvision.vision.opencv.CVMat;
import org.photonvision.vision.processes.VisionSourceSettables;
public class USBFrameProvider extends CpuImageProcessor {
private static final Logger logger = new Logger(USBFrameProvider.class, LogGroup.Camera);
private final CvSink cvSink;
@SuppressWarnings("SpellCheckingInspection")
@@ -43,9 +46,9 @@ public class USBFrameProvider extends CpuImageProcessor {
cvSink.grabFrame(mat.getMat())
* 1000; // Units are microseconds, epoch is the same as the Unix epoch
// Sometimes CSCore gives us a zero frametime.
if (time <= 1e-6) {
time = MathUtils.wpiNanoTime();
if (time == 0) {
var error = cvSink.getError();
logger.error("Error grabbing image: " + error);
}
return new CapturedFrame(mat, settables.getFrameStaticProperties(), time);

View File

@@ -92,6 +92,12 @@ public class VisionRunner {
// Grab the new camera frame
var frame = frameSupplier.get();
// Frame empty -- no point in trying to do anything more?
if (frame.processedImage.getMat().empty() && frame.colorImage.getMat().empty()) {
// give up without increasing loop count
continue;
}
// There's no guarantee the processing type change will occur this tick, so pipelines should
// check themselves
try {