Skip to content

Commit

Permalink
Add default overrides to CvSink
Browse files Browse the repository at this point in the history
  • Loading branch information
mcm001 committed Dec 23, 2024
1 parent 18abf66 commit 4a98816
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ public class VisionRunner<P extends VisionPipeline> {
private final CvSink m_cvSink = new CvSink("VisionRunner CvSink");
private final P m_pipeline;
private final Mat m_image = new Mat();
private long m_lastFrameTime = 0;
private final Listener<? super P> m_listener;
private volatile boolean m_enabled = true;

Expand Down Expand Up @@ -81,7 +82,7 @@ public void runOnce() {
}

private void runOnceInternal() {
long frameTime = m_cvSink.grabFrame(m_image, 0);
long frameTime = m_cvSink.grabFrame(m_image, m_lastFrameTime);
if (frameTime == 0) {
// There was an error, report it
String error = m_cvSink.getError();
Expand All @@ -90,6 +91,8 @@ private void runOnceInternal() {
// No errors, process the image
m_pipeline.process(m_image);
m_listener.copyPipelineOutputs(m_pipeline);

m_lastFrameTime = frameTime;
}
}

Expand Down
51 changes: 51 additions & 0 deletions cscore/src/main/java/edu/wpi/first/cscore/CvSink.java
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,17 @@ public CvSink(String name) {
this(name, PixelFormat.kBGR);
}

/**
* Wait for the next frame and get the image. Times out (returning 0) after 0.225 seconds. The
* provided image will have the pixelFormat this class was constructed with.
*
* @param image Where to store the image.
* @return Frame time, or 0 on error (call GetError() to obtain the error message)
*/
public long grabFrame(Mat image) {
return grabFrame(image, 0.225, 0);
}

/**
* Wait for the next frame and get the image. Times out (returning 0) after 0.225 seconds. The
* provided image will have the pixelFormat this class was constructed with.
Expand All @@ -76,6 +87,21 @@ public long grabFrame(Mat image, long lastFrameTime) {
return grabFrame(image, 0.225, lastFrameTime);
}


/**
* Wait for the next frame and get the image. Times out (returning 0) after timeout seconds. The
* provided image will have the pixelFormat this class was constructed with.
*
* @param image Where to store the image.
* @param timeout Retrieval timeout in seconds.
* @return Frame time, or 0 on error (call GetError() to obtain the error message); the frame time
* is in 1 us increments.
*/
public long grabFrame(Mat image, double timeout) {
return grabFrame(image, timeout, 0);
}


/**
* Wait for the next frame and get the image. Times out (returning 0) after timeout seconds. The
* provided image will have the pixelFormat this class was constructed with.
Expand Down Expand Up @@ -138,6 +164,31 @@ public long grabFrameDirect(long lastFrameTime) {
return grabFrameDirect(0.225, lastFrameTime);
}

/**
* Wait for the next frame and store the image. Times out (returning 0) after 0.225 seconds. The
* provided image will have the pixelFormat this class was constructed with. Use getDirectMat() to
* grab the image.
*
* @return Frame time, or 0 on error (call GetError() to obtain the error message)
*/
public long grabFrameDirect() {
return grabFrameDirect(0.225, 0);
}

/**
* Wait for the next frame and store the image. Times out (returning 0) after timeout seconds. The
* provided image will have the pixelFormat this class was constructed with. Use getDirectMat() to
* grab the image.
*
* @param timeout Retrieval timeout in seconds.
* @return Frame time, or 0 on error (call GetError() to obtain the error message); the frame time
* is in 1 us increments.
*/
@SuppressWarnings("PMD.CompareObjectsWithEquals")
public long grabFrameDirect(double timeout) {
return grabFrameDirect(timeout);
}

/**
* Wait for the next frame and store the image. Times out (returning 0) after timeout seconds. The
* provided image will have the pixelFormat this class was constructed with. Use getDirectMat() to
Expand Down

0 comments on commit 4a98816

Please sign in to comment.