WPILibC++ 2027.0.0-alpha-4
Loading...
Searching...
No Matches
UsbCamera.hpp
Go to the documentation of this file.
1// Copyright (c) FIRST and other WPILib contributors.
2// Open Source Software; you can modify and/or share it under the terms of
3// the WPILib BSD license file in the root directory of this project.
4
5#pragma once
6
7#include <string>
8#include <string_view>
9#include <vector>
10
12#include "wpi/cs/cscore_cpp.hpp"
13
14namespace wpi::cs {
15
16/**
17 * A source that represents a USB camera.
18 */
19class UsbCamera : public VideoCamera {
20 public:
21 UsbCamera() = default;
22
23 /**
24 * Create a source for a USB camera based on device number.
25 *
26 * @param name Source name (arbitrary unique identifier)
27 * @param dev Device number (e.g. 0 for /dev/video0)
28 */
29 UsbCamera(std::string_view name, int dev) {
31 }
32
33 /**
34 * Create a source for a USB camera based on device path.
35 *
36 * @param name Source name (arbitrary unique identifier)
37 * @param path Path to device (e.g. "/dev/video0" on Linux)
38 */
39 UsbCamera(std::string_view name, std::string_view path) {
41 }
42
43 /**
44 * Enumerate USB cameras on the local system.
45 *
46 * @return Vector of USB camera information (one for each camera)
47 */
48 static std::vector<UsbCameraInfo> EnumerateUsbCameras() {
49 CS_Status status = 0;
50 return ::wpi::cs::EnumerateUsbCameras(&status);
51 }
52
53 /**
54 * Change the path to the device.
55 */
56 void SetPath(std::string_view path) {
57 m_status = 0;
58 return ::wpi::cs::SetUsbCameraPath(m_handle, path, &m_status);
59 }
60
61 /**
62 * Get the path to the device.
63 */
64 std::string GetPath() const {
65 m_status = 0;
66 return ::wpi::cs::GetUsbCameraPath(m_handle, &m_status);
67 }
68
69 /**
70 * Get the full camera information for the device.
71 */
73 m_status = 0;
74 return ::wpi::cs::GetUsbCameraInfo(m_handle, &m_status);
75 }
76
77 /**
78 * Set how verbose the camera connection messages are.
79 *
80 * @param level 0=don't display Connecting message, 1=do display message
81 */
82 void SetConnectVerbose(int level) {
83 m_status = 0;
84 SetProperty(GetSourceProperty(m_handle, "connect_verbose", &m_status),
85 level, &m_status);
86 }
87};
88
89} // namespace wpi::cs
@ name
Definition base.h:690
UsbCamera(std::string_view name, int dev)
Create a source for a USB camera based on device number.
Definition UsbCamera.hpp:29
void SetPath(std::string_view path)
Change the path to the device.
Definition UsbCamera.hpp:56
static std::vector< UsbCameraInfo > EnumerateUsbCameras()
Enumerate USB cameras on the local system.
Definition UsbCamera.hpp:48
void SetConnectVerbose(int level)
Set how verbose the camera connection messages are.
Definition UsbCamera.hpp:82
UsbCamera(std::string_view name, std::string_view path)
Create a source for a USB camera based on device path.
Definition UsbCamera.hpp:39
UsbCameraInfo GetInfo() const
Get the full camera information for the device.
Definition UsbCamera.hpp:72
std::string GetPath() const
Get the path to the device.
Definition UsbCamera.hpp:64
CS_Status m_status
Definition VideoSource.hpp:372
CS_Source m_handle
Video source handle.
Definition VideoSource.hpp:375
void SetProperty(CS_Property property, int value, CS_Status *status)
CS_Source CreateUsbCameraPath(std::string_view name, std::string_view path, CS_Status *status)
CS_Source CreateUsbCameraDev(std::string_view name, int dev, CS_Status *status)
CS_Property GetSourceProperty(CS_Source source, std::string_view name, CS_Status *status)
int CS_Status
Definition cscore_c.h:41
CameraServer (cscore) namespace.
Definition CvSource.hpp:15
USB camera information.
Definition UsbCameraInfo.hpp:15