blob: add83a6b301cbbdf1dec1e4210093e85398c9cf5 [file] [log] [blame]
James Kuszmaul0c593962023-01-28 16:04:20 -08001#ifndef FRC971_VISION_FOXGLOVE_IMAGE_CONVERTER_H_
2#define FRC971_VISION_FOXGLOVE_IMAGE_CONVERTER_H_
3#include "external/com_github_foxglove_schemas/CompressedImage_generated.h"
4#include "frc971/vision/vision_generated.h"
5#include "aos/events/event_loop.h"
6
7namespace frc971::vision {
8// Empirically, from 2022 logs:
9// PNG is an ~2x space savings relative to raw images.
10// JPEG is an ~10x space savings relative to PNG.
11// Both perform significantly better than attempting to perform in-browser
12// conversion with a user-script in Foxglove Studio.
13enum class ImageCompression { kJpeg, kPng };
14
15flatbuffers::Offset<foxglove::CompressedImage> CompressImage(
16 const CameraImage *raw_image, flatbuffers::FlatBufferBuilder *fbb,
17 ImageCompression compression);
18
19// This class provides a simple converter that will take an AOS CameraImage
20// channel and output
21class FoxgloveImageConverter {
22 public:
23 // Watches for frc971.vision.CameraImage messages on the input_channel and
24 // sends foxglove.CompressedImage messages on the output_channel, using the
25 // specified image compression algorithm.
26 FoxgloveImageConverter(aos::EventLoop *event_loop,
27 std::string_view input_channel,
28 std::string_view output_channel,
29 ImageCompression compression);
30
31 private:
32 aos::EventLoop *event_loop_;
33 aos::Sender<foxglove::CompressedImage> sender_;
34};
35} // namespace frc971::vision
36#endif // FRC971_VISION_FOXGLOVE_IMAGE_CONVERTER_H_