CvSink

class cscore.CvSink(*args, **kwargs)

Bases: ImageSink

A sink for user code to accept video frames as OpenCV images.

Overloaded function.

  1. __init__(self: cscore._cscore.CvSink, name: str, pixelFormat: cscore._cscore.VideoMode.PixelFormat = <PixelFormat.kBGR: 4>) -> None

Create a sink for accepting OpenCV images.

WaitForFrame() must be called on the created sink to get each new image.

Parameters:
  • name – Source name (arbitrary unique identifier)

  • pixelFormat – Source pixel format

  1. __init__(self: cscore._cscore.CvSink, name: str, processFrame: Callable[[int], None], pixelFormat: cscore._cscore.VideoMode.PixelFormat = <PixelFormat.kBGR: 4>) -> None

Create a sink for accepting OpenCV images in a separate thread.

A thread will be created that calls WaitForFrame() and calls the processFrame() callback each time a new frame arrives.

Parameters:
  • name – Source name (arbitrary unique identifier)

  • processFrame – Frame processing function; will be called with a time=0 if an error occurred. processFrame should call GetImage() or GetError() as needed, but should not call (except in very unusual circumstances) WaitForImage().

  • pixelFormat – Source pixel format

grabFrame(image: numpy.ndarray, timeout: float = 0.225) tuple[int, numpy.ndarray]

Wait for the next frame and get the image. Times out (returning 0) after timeout seconds. The provided image will have three 8-bit channels stored in BGR order.

Returns:

Frame time, or 0 on error (call GetError() to obtain the error message); the frame time is in the same time base as wpi::Now(), and is in 1 us increments.

grabFrameNoTimeout(image: numpy.ndarray) tuple[int, numpy.ndarray]

Wait for the next frame and get the image. May block forever. The provided image will have three 8-bit channels stored in BGR order.

Returns:

Frame time, or 0 on error (call GetError() to obtain the error message); the frame time is in the same time base as wpi::Now(), and is in 1 us increments.