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
|
|
|
|
2021-06-06 16:13:58 -07:00
|
|
|
#include <cstdio>
|
|
|
|
|
|
2026-01-04 16:59:02 -08:00
|
|
|
#include "wpi/cs/UsbCamera.hpp"
|
2025-11-07 19:57:55 -05:00
|
|
|
#include "wpi/util/print.hpp"
|
2016-10-13 00:18:16 -07:00
|
|
|
|
|
|
|
|
int main() {
|
|
|
|
|
CS_Status status = 0;
|
|
|
|
|
|
2025-11-07 20:00:05 -05:00
|
|
|
for (const auto& caminfo : wpi::cs::EnumerateUsbCameras(&status)) {
|
|
|
|
|
wpi::util::print("{}: {} ({})\n", caminfo.dev, caminfo.path, caminfo.name);
|
2018-12-30 11:48:18 -08:00
|
|
|
if (!caminfo.otherPaths.empty()) {
|
2021-06-06 16:13:58 -07:00
|
|
|
std::puts("Other device paths:");
|
2020-12-28 12:58:06 -08:00
|
|
|
for (auto&& path : caminfo.otherPaths) {
|
2025-11-07 20:00:05 -05:00
|
|
|
wpi::util::print(" {}\n", path);
|
2020-12-28 12:58:06 -08:00
|
|
|
}
|
2018-12-30 11:48:18 -08:00
|
|
|
}
|
|
|
|
|
|
2025-11-07 20:00:05 -05:00
|
|
|
wpi::cs::UsbCamera camera{"usbcam", caminfo.dev};
|
2016-10-13 00:18:16 -07:00
|
|
|
|
2021-06-06 16:13:58 -07:00
|
|
|
std::puts("Properties:");
|
2016-10-13 00:18:16 -07:00
|
|
|
for (const auto& prop : camera.EnumerateProperties()) {
|
2025-11-07 20:00:05 -05:00
|
|
|
wpi::util::print(" {}", prop.GetName());
|
2016-11-15 23:54:50 -08:00
|
|
|
switch (prop.GetKind()) {
|
2025-11-07 20:00:05 -05:00
|
|
|
case wpi::cs::VideoProperty::kBoolean:
|
|
|
|
|
wpi::util::print(" (bool): value={} default={}", prop.Get(),
|
2025-11-07 20:01:58 -05:00
|
|
|
prop.GetDefault());
|
2016-10-13 00:18:16 -07:00
|
|
|
break;
|
2025-11-07 20:00:05 -05:00
|
|
|
case wpi::cs::VideoProperty::kInteger:
|
|
|
|
|
wpi::util::print(" (int): value={} min={} max={} step={} default={}",
|
2025-11-07 20:01:58 -05:00
|
|
|
prop.Get(), prop.GetMin(), prop.GetMax(),
|
|
|
|
|
prop.GetStep(), prop.GetDefault());
|
2016-10-13 00:18:16 -07:00
|
|
|
break;
|
2025-11-07 20:00:05 -05:00
|
|
|
case wpi::cs::VideoProperty::kString:
|
|
|
|
|
wpi::util::print(" (string): {}", prop.GetString());
|
2016-10-13 00:18:16 -07:00
|
|
|
break;
|
2025-11-07 20:00:05 -05:00
|
|
|
case wpi::cs::VideoProperty::kEnum: {
|
|
|
|
|
wpi::util::print(" (enum): value={}", prop.Get());
|
2016-10-13 00:18:16 -07:00
|
|
|
auto choices = prop.GetChoices();
|
|
|
|
|
for (size_t i = 0; i < choices.size(); ++i) {
|
2021-06-06 16:13:58 -07:00
|
|
|
if (!choices[i].empty()) {
|
2025-11-07 20:00:05 -05:00
|
|
|
wpi::util::print("\n {}: {}", i, choices[i]);
|
2020-12-28 12:58:06 -08:00
|
|
|
}
|
2016-10-13 00:18:16 -07:00
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
default:
|
|
|
|
|
break;
|
|
|
|
|
}
|
2021-06-06 16:13:58 -07:00
|
|
|
std::fputc('\n', stdout);
|
2016-10-13 00:18:16 -07:00
|
|
|
}
|
|
|
|
|
|
2021-06-06 16:13:58 -07:00
|
|
|
std::puts("Video Modes:");
|
2016-10-13 00:18:16 -07:00
|
|
|
for (const auto& mode : camera.EnumerateVideoModes()) {
|
2021-06-06 16:13:58 -07:00
|
|
|
const char* pixelFormat;
|
2016-10-13 00:18:16 -07:00
|
|
|
switch (mode.pixelFormat) {
|
2026-01-04 16:59:02 -08:00
|
|
|
case wpi::util::PixelFormat::kMJPEG:
|
2021-06-06 16:13:58 -07:00
|
|
|
pixelFormat = "MJPEG";
|
2017-08-25 17:48:06 -07:00
|
|
|
break;
|
2026-01-04 16:59:02 -08:00
|
|
|
case wpi::util::PixelFormat::kYUYV:
|
2021-06-06 16:13:58 -07:00
|
|
|
pixelFormat = "YUYV";
|
2017-08-25 17:48:06 -07:00
|
|
|
break;
|
2026-01-04 16:59:02 -08:00
|
|
|
case wpi::util::PixelFormat::kRGB565:
|
2021-06-06 16:13:58 -07:00
|
|
|
pixelFormat = "RGB565";
|
2017-08-25 17:48:06 -07:00
|
|
|
break;
|
|
|
|
|
default:
|
2021-06-06 16:13:58 -07:00
|
|
|
pixelFormat = "Unknown";
|
2017-08-25 17:48:06 -07:00
|
|
|
break;
|
2016-10-13 00:18:16 -07:00
|
|
|
}
|
2025-11-07 20:01:58 -05:00
|
|
|
wpi::util::print(" PixelFormat:{} Width:{} Height:{} FPS:{}\n",
|
|
|
|
|
pixelFormat, mode.width, mode.height, mode.fps);
|
2016-10-13 00:18:16 -07:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|