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>
|
|
|
|
|
|
2024-05-12 06:25:42 -07:00
|
|
|
#include <wpi/print.h>
|
2016-10-13 00:18:16 -07:00
|
|
|
|
2017-08-25 17:48:06 -07:00
|
|
|
#include "cscore.h"
|
2016-10-13 00:18:16 -07:00
|
|
|
|
|
|
|
|
int main() {
|
|
|
|
|
CS_Status status = 0;
|
|
|
|
|
|
2016-12-04 00:08:47 -08:00
|
|
|
for (const auto& caminfo : cs::EnumerateUsbCameras(&status)) {
|
2024-05-12 06:25:42 -07:00
|
|
|
wpi::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) {
|
2024-05-12 06:25:42 -07:00
|
|
|
wpi::print(" {}\n", path);
|
2020-12-28 12:58:06 -08:00
|
|
|
}
|
2018-12-30 11:48:18 -08:00
|
|
|
}
|
|
|
|
|
|
2016-12-04 00:08:47 -08:00
|
|
|
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()) {
|
2024-05-12 06:25:42 -07:00
|
|
|
wpi::print(" {}", prop.GetName());
|
2016-11-15 23:54:50 -08:00
|
|
|
switch (prop.GetKind()) {
|
2016-10-13 00:18:16 -07:00
|
|
|
case cs::VideoProperty::kBoolean:
|
2024-05-12 06:25:42 -07:00
|
|
|
wpi::print(" (bool): value={} default={}", prop.Get(),
|
2021-06-06 16:13:58 -07:00
|
|
|
prop.GetDefault());
|
2016-10-13 00:18:16 -07:00
|
|
|
break;
|
|
|
|
|
case cs::VideoProperty::kInteger:
|
2024-05-12 06:25:42 -07:00
|
|
|
wpi::print(" (int): value={} min={} max={} step={} default={}",
|
2021-06-06 16:13:58 -07:00
|
|
|
prop.Get(), prop.GetMin(), prop.GetMax(), prop.GetStep(),
|
|
|
|
|
prop.GetDefault());
|
2016-10-13 00:18:16 -07:00
|
|
|
break;
|
|
|
|
|
case cs::VideoProperty::kString:
|
2024-05-12 06:25:42 -07:00
|
|
|
wpi::print(" (string): {}", prop.GetString());
|
2016-10-13 00:18:16 -07:00
|
|
|
break;
|
|
|
|
|
case cs::VideoProperty::kEnum: {
|
2024-05-12 06:25:42 -07:00
|
|
|
wpi::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()) {
|
2024-05-12 06:25:42 -07:00
|
|
|
wpi::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) {
|
2017-08-25 17:48:06 -07:00
|
|
|
case cs::VideoMode::kMJPEG:
|
2021-06-06 16:13:58 -07:00
|
|
|
pixelFormat = "MJPEG";
|
2017-08-25 17:48:06 -07:00
|
|
|
break;
|
|
|
|
|
case cs::VideoMode::kYUYV:
|
2021-06-06 16:13:58 -07:00
|
|
|
pixelFormat = "YUYV";
|
2017-08-25 17:48:06 -07:00
|
|
|
break;
|
|
|
|
|
case cs::VideoMode::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
|
|
|
}
|
2024-05-12 06:25:42 -07:00
|
|
|
wpi::print(" PixelFormat:{} Width:{} Height:{} FPS:{}\n", pixelFormat,
|
2021-06-06 16:13:58 -07:00
|
|
|
mode.width, mode.height, mode.fps);
|
2016-10-13 00:18:16 -07:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|