VisionServer  v2.1.1-1-g21dc5465
FRC vision library
visioncamera.h
Go to the documentation of this file.
1#pragma once
2
3#include <opencv2/opencv.hpp>
4
5#include <networktables/NetworkTableInstance.h>
6#include <networktables/NetworkTable.h>
7#include <networktables/IntegerTopic.h>
8#include <cameraserver/CameraServer.h>
9#include <wpi/json.h>
10
11
15class VisionCamera final: public cs::VideoCamera {
16public:
17 inline static const cv::Mat_<float>
18 default_matrix{cv::Mat_<float>::zeros(3, 3)},
19 default_distort{cv::Mat_<float>::zeros(1, 5)}
20 ;
21
22 //VisionCamera() = default;
27 VisionCamera(CS_Source source_handle);
33 VisionCamera(const cs::VideoSource& source, const wpi::json& config = wpi::json());
39 VisionCamera(const cs::UsbCamera& source, const wpi::json& config = wpi::json()); // these were not working
45 VisionCamera(const cs::HttpCamera& source, const wpi::json& config = wpi::json()); // ^
51 VisionCamera(const wpi::json& source_config, const wpi::json& calibration);
56 VisionCamera(const wpi::json& source_config);
57 VisionCamera(const VisionCamera&) = delete;
59 // inline VisionCamera(const VisionCamera&) { std::cout << "VCamera copied." << std::endl; }
60 // inline VisionCamera(VisionCamera&&) { std::cout << "VCamera moved." << std::endl; }
65
66 inline VisionCamera& operator=(const VisionCamera&) = delete;
68 // inline VisionCamera& operator=(const VisionCamera&) { std::cout << "VCamera copied via operator." << std::endl; }
69 // inline VisionCamera& operator=(VisionCamera&&) { std::cout << "VCamera moved via operator." << std::endl; }
70
75 bool isValidJson() const;
80 const wpi::json& getJson() const;
85 bool isValidStreamJson() const;
90 wpi::json getStreamJson() const;
91
97 bool getJsonCameraMatrix(cv::Mat_<double>& array) const;
103 bool getJsonCameraMatrix(cv::Mat_<float>& array) const;
109 bool getJsonDistortionCoefs(cv::Mat_<double>& array) const;
115 bool getJsonDistortionCoefs(cv::Mat_<float>& array) const;
120 inline const cv::Mat_<float>& getCameraMatrix() const { return this->camera_matrix; }
125 inline const cv::Mat_<float>& getDistortionCoefs() const { return this->distortion; }
126
127 bool setCalibrationJson(const wpi::json&);
128 bool setCameraMatrix(const cv::Mat_<float>&);
129 bool setDistortionCoefs(const cv::Mat_<float>&);
130
137 uint64_t getFrame(cv::Mat& o_frame, double timeout = 0.225) const;
143 uint64_t getFrameNoTmO(cv::Mat& o_frame) const;
148 inline const cs::CvSink& getSink() const { return this->raw; }
149
154 int getWidth() const;
159 int getHeight() const;
164 int getPixels() const;
169 int getConfigFPS() const;
174 cv::Size getResolution() const;
175
180 int getBrightness() const;
185 int getExposure() const;
190 int getWhiteBalance() const;
191
196 void setBrightness(int b); // ranges 0 through 100 (a percent)
201 void setWhiteBalance(int wb); // ranges 0 through ~7000(+?) (look up) -> -1 sets to auto
206 void setExposure(int e); // ranges 0 through 100 -> -1 sets to auto
207
212 void setNetworkBase(const std::shared_ptr<nt::NetworkTable>& table);
217
218protected:
219 int _setBrightness(int b);
220 int _setWhiteBalance(int wb);
221 int _setExposure(int e);
222
223private:
224 wpi::json config, calibration;
225 cs::CvSink raw;
227 cs::VideoMode properties;
228
229 std::shared_ptr<nt::NetworkTable> ntable{
230 nt::NetworkTableInstance::GetDefault().GetTable("Cameras")->GetSubTable(this->GetName())};
231 nt::IntegerEntry
233 NT_Listener listener_handle{0};
234
235
236};
int getWidth() const
VisionCamera(CS_Source source_handle)
Definition: visioncamera.cpp:9
bool getJsonDistortionCoefs(cv::Mat_< double > &array) const
int getPixels() const
nt::IntegerEntry nt_whitebalance
Definition: visioncamera.h:232
void setNetworkBase(const std::shared_ptr< nt::NetworkTable > &table)
wpi::json getStreamJson() const
uint64_t getFrameNoTmO(cv::Mat &o_frame) const
int _setExposure(int e)
cs::VideoMode properties
Definition: visioncamera.h:227
VisionCamera & operator=(const VisionCamera &)=delete
cv::Size getResolution() const
nt::IntegerEntry nt_brightness
Definition: visioncamera.h:232
wpi::json config
Definition: visioncamera.h:224
NT_Listener listener_handle
Definition: visioncamera.h:233
int getBrightness() const
int _setWhiteBalance(int wb)
nt::IntegerEntry nt_exposure
Definition: visioncamera.h:232
std::shared_ptr< nt::NetworkTable > ntable
Definition: visioncamera.h:229
int getExposure() const
void setBrightness(int b)
bool getJsonCameraMatrix(cv::Mat_< double > &array) const
static const cv::Mat_< float > default_matrix
Definition: visioncamera.h:18
cv::Mat_< float > camera_matrix
Definition: visioncamera.h:226
cs::CvSink raw
Definition: visioncamera.h:225
const cv::Mat_< float > & getDistortionCoefs() const
Definition: visioncamera.h:125
wpi::json calibration
Definition: visioncamera.h:224
VisionCamera(const VisionCamera &)=delete
bool isValidJson() const
const cs::CvSink & getSink() const
Definition: visioncamera.h:148
void setWhiteBalance(int wb)
int getHeight() const
const cv::Mat_< float > & getCameraMatrix() const
Definition: visioncamera.h:120
int getConfigFPS() const
int getWhiteBalance() const
const wpi::json & getJson() const
void setNetworkAdjustable()
void setExposure(int e)
cv::Mat_< float > distortion
Definition: visioncamera.h:226
bool isValidStreamJson() const
bool setCalibrationJson(const wpi::json &)
int _setBrightness(int b)
bool setDistortionCoefs(const cv::Mat_< float > &)
bool setCameraMatrix(const cv::Mat_< float > &)
static const cv::Mat_< float > default_distort
Definition: visioncamera.h:19
uint64_t getFrame(cv::Mat &o_frame, double timeout=0.225) const