Package edu.wpi.first.cscore
Class CvSink
java.lang.Object
edu.wpi.first.cscore.VideoSink
edu.wpi.first.cscore.ImageSink
edu.wpi.first.cscore.CvSink
- All Implemented Interfaces:
AutoCloseable
A sink for user code to accept video frames as OpenCV images. These sinks require the WPILib
OpenCV builds. For an alternate OpenCV, see the documentation how to build your own with RawSink.
-
Nested Class Summary
Nested classes/interfaces inherited from class edu.wpi.first.cscore.VideoSink
VideoSink.Kind
-
Field Summary
-
Constructor Summary
ConstructorDescriptionCreate a sink for accepting OpenCV images.CvSink
(String name, PixelFormat pixelFormat) Create a sink for accepting OpenCV images. -
Method Summary
Modifier and TypeMethodDescriptionvoid
close()
Get the direct backing mat for this sink.long
Get the last time a frame was grabbed.Get the time source for the timestamp the last frame was grabbed at.long
Wait for the next frame and get the image.long
Wait for the next frame and get the image.long
Wait for the next frame and store the image.long
grabFrameDirect
(double timeout) Wait for the next frame and store the image.long
grabFrameNoTimeout
(Mat image) Wait for the next frame and get the image.long
Wait for the next frame and store the image.Methods inherited from class edu.wpi.first.cscore.ImageSink
getError, setDescription, setEnabled
Methods inherited from class edu.wpi.first.cscore.VideoSink
enumerateProperties, enumerateSinks, equals, getConfigJson, getDescription, getHandle, getKind, getKindFromInt, getName, getProperty, getSource, getSourceProperty, hashCode, isValid, setConfigJson, setSource
-
Constructor Details
-
CvSink
Create a sink for accepting OpenCV images. grabFrame() must be called on the created sink to get each new image.- Parameters:
name
- Sink name (arbitrary unique identifier)pixelFormat
- Source pixel format
-
CvSink
Create a sink for accepting OpenCV images. WaitForFrame() must be called on the created sink to get each new image. Defaults to kBGR for pixelFormat- Parameters:
name
- Source name (arbitrary unique identifier)
-
-
Method Details
-
close
- Specified by:
close
in interfaceAutoCloseable
- Overrides:
close
in classVideoSink
-
grabFrame
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.- Parameters:
image
- Where to store the image.- Returns:
- Frame time, or 0 on error (call GetError() to obtain the error message)
-
grabFrame
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.- Parameters:
image
- Where to store the image.timeout
- Retrieval timeout in seconds.- Returns:
- Frame time, or 0 on error (call GetError() to obtain the error message); the frame time is in 1 us increments.
-
grabFrameNoTimeout
Wait for the next frame and get the image. May block forever. The provided image will have the pixelFormat this class was constructed with.- Parameters:
image
- Where to store the image.- Returns:
- Frame time, or 0 on error (call GetError() to obtain the error message); the frame time is in 1 us increments.
-
getDirectMat
Get the direct backing mat for this sink.This mat can be invalidated any time any of the grab* methods are called, or when the CvSink is closed.
- Returns:
- The backing mat.
-
grabFrameDirect
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.- Returns:
- Frame time, or 0 on error (call GetError() to obtain the error message)
-
grabFrameDirect
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.- Parameters:
timeout
- Retrieval timeout in seconds.- Returns:
- Frame time, or 0 on error (call GetError() to obtain the error message); the frame time is in 1 us increments.
-
grabFrameNoTimeoutDirect
Wait for the next frame and store the image. May block forever. The provided image will have the pixelFormat this class was constructed with. Use getDirectMat() to grab the image.- Returns:
- Frame time, or 0 on error (call GetError() to obtain the error message); the frame time is in 1 us increments.
-
getLastFrameTime
Get the last time a frame was grabbed. This uses the same time base as wpi::Now().- Returns:
- Time in 1 us increments.
-
getLastFrameTimeSource
Get the time source for the timestamp the last frame was grabbed at.- Returns:
- Time source
-