2020-12-26 14:12:05 -08:00
|
|
|
// Copyright (c) FIRST and other WPILib contributors.
|
|
|
|
|
// Open Source Software; you can modify and/or share it under the terms of
|
|
|
|
|
// the WPILib BSD license file in the root directory of this project.
|
2017-08-25 17:48:06 -07:00
|
|
|
|
|
|
|
|
#include <cstdio>
|
2016-10-13 00:18:16 -07:00
|
|
|
|
2026-01-04 16:59:02 -08:00
|
|
|
#include "wpi/cs/MjpegServer.hpp"
|
|
|
|
|
#include "wpi/cs/RawEvent.hpp"
|
|
|
|
|
#include "wpi/cs/UsbCamera.hpp"
|
|
|
|
|
#include "wpi/cs/cscore_cpp.hpp"
|
2025-11-07 19:57:55 -05:00
|
|
|
#include "wpi/util/print.hpp"
|
2016-11-18 11:44:25 -08:00
|
|
|
|
2016-10-13 00:18:16 -07:00
|
|
|
int main() {
|
2025-11-07 20:00:05 -05:00
|
|
|
wpi::util::print("hostname: {}\n", wpi::cs::GetHostname());
|
2021-06-06 16:13:58 -07:00
|
|
|
std::puts("IPv4 network addresses:");
|
2025-11-07 20:00:05 -05:00
|
|
|
for (const auto& addr : wpi::cs::GetNetworkInterfaces()) {
|
|
|
|
|
wpi::util::print(" {}\n", addr);
|
2020-12-28 12:58:06 -08:00
|
|
|
}
|
2025-11-07 20:00:05 -05:00
|
|
|
wpi::cs::UsbCamera camera{"usbcam", 0};
|
2026-03-15 22:29:01 -07:00
|
|
|
camera.SetVideoMode(wpi::util::PixelFormat::MJPEG, 320, 240, 30);
|
2025-11-07 20:00:05 -05:00
|
|
|
wpi::cs::MjpegServer mjpegServer{"httpserver", 8081};
|
2016-10-15 22:44:26 -07:00
|
|
|
mjpegServer.SetSource(camera);
|
|
|
|
|
|
2018-03-04 21:01:55 -08:00
|
|
|
CS_Status status = 0;
|
2025-11-07 20:00:05 -05:00
|
|
|
wpi::cs::AddListener(
|
|
|
|
|
[&](const wpi::cs::RawEvent& event) {
|
|
|
|
|
wpi::util::print("FPS={} MBPS={}\n", camera.GetActualFPS(),
|
2025-11-07 20:01:58 -05:00
|
|
|
(camera.GetActualDataRate() / 1000000.0));
|
2018-03-07 01:14:21 -08:00
|
|
|
},
|
2025-11-07 20:00:05 -05:00
|
|
|
wpi::cs::RawEvent::kTelemetryUpdated, false, &status);
|
|
|
|
|
wpi::cs::SetTelemetryPeriod(1.0);
|
2018-03-04 21:01:55 -08:00
|
|
|
|
2017-08-25 17:48:06 -07:00
|
|
|
std::getchar();
|
2016-10-13 00:18:16 -07:00
|
|
|
}
|