sendFrames method

  1. @override
Future<void> sendFrames()
override

Reads a frame from the camera and sends it to the dashboard.

When overriding this function, be sure to check for errors, such as:

  • If the camera does not respond, alert the dashboard
  • If the frame is too large, reduces the quality (increases JPG compression)
  • If the quality is already low, alert the dashboard

Implementation

@override
Future<void> sendFrames() async {
  // Get frames from RealSense
  final frames = camera.getFrames();
  if (frames == nullptr) return;

  // Compress colorized frame
  final Pointer<Uint8> rawColorized = frames.ref.colorized_data;
  if (rawColorized == nullptr) return;
  final colorizedMatrix = rawColorized.toOpenCVMat(camera.depthResolution, length: frames.ref.colorized_length);
  final colorizedJpg = colorizedMatrix.encodeJpg(quality: details.quality);

  if (colorizedJpg == null) {
    sendLog(LogLevel.debug, "Could not encode colorized frame");
  } else {
    sendFrame(colorizedJpg);
  }

  sendRgbFrame(frames.ref.rgb_data);

  fpsCount++;
  // send(DepthFramePayload(frames.address));  // For autonomy
  colorizedMatrix.dispose();
  frames.dispose();
}