mirror of
https://github.com/PhotonVision/photonvision
synced 2026-06-25 01:41:40 +00:00
Properly handle empty frames from cscore (#1296)
This commit is contained in:
@@ -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);
|
||||
|
||||
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user