diff --git a/include/mynteye/types.h b/include/mynteye/types.h index 1f3aa98..a6282ed 100644 --- a/include/mynteye/types.h +++ b/include/mynteye/types.h @@ -419,6 +419,9 @@ struct MYNTEYE_API OptionInfo { std::int32_t def; }; +MYNTEYE_API +std::ostream &operator<<(std::ostream &os, const OptionInfo &info); + MYNTEYE_END_NAMESPACE #endif // MYNTEYE_TYPES_H_ NOLINT diff --git a/samples/tutorials/CMakeLists.txt b/samples/tutorials/CMakeLists.txt index 47a6d03..37766aa 100644 --- a/samples/tutorials/CMakeLists.txt +++ b/samples/tutorials/CMakeLists.txt @@ -36,6 +36,8 @@ endmacro() if(WITH_API) -make_executable(get_device_info SRCS get_device_info.cc) +make_executable(get_device_info SRCS data/get_device_info.cc) + +make_executable(ctrl_infrared SRCS control/infrared.cc WITH_OPENCV) endif() diff --git a/samples/tutorials/control/infrared.cc b/samples/tutorials/control/infrared.cc new file mode 100644 index 0000000..ad54780 --- /dev/null +++ b/samples/tutorials/control/infrared.cc @@ -0,0 +1,47 @@ +#include + +#include + +#include "mynteye/api.h" + +MYNTEYE_USE_NAMESPACE + +int main(int argc, char *argv[]) { + auto &&api = API::Create(argc, argv); + + // Detect infrared add-ons + LOG(INFO) << "Support infrared: " << std::boolalpha + << api->Supports(AddOns::INFRARED); + LOG(INFO) << "Support infrared2: " << std::boolalpha + << api->Supports(AddOns::INFRARED2); + + // Get infrared intensity range + auto &&info = api->GetOptionInfo(Option::IR_CONTROL); + LOG(INFO) << Option::IR_CONTROL << ": {" << info << "}"; + + // Set infrared intensity value + api->SetOptionValue(Option::IR_CONTROL, 80); + + api->Start(Source::VIDEO_STREAMING); + + cv::namedWindow("frame"); + + while (true) { + api->WaitForStreams(); + + auto &&left_data = api->GetStreamData(Stream::LEFT); + auto &&right_data = api->GetStreamData(Stream::RIGHT); + + cv::Mat img; + cv::hconcat(left_data.frame, right_data.frame, img); + cv::imshow("frame", img); + + char key = static_cast(cv::waitKey(1)); + if (key == 27 || key == 'q' || key == 'Q') { // ESC/Q + break; + } + } + + api->Stop(Source::ALL); + return 0; +} diff --git a/samples/tutorials/get_device_info.cc b/samples/tutorials/data/get_device_info.cc similarity index 100% rename from samples/tutorials/get_device_info.cc rename to samples/tutorials/data/get_device_info.cc diff --git a/src/api/api.cc b/src/api/api.cc index 57a8ae7..cf3f364 100644 --- a/src/api/api.cc +++ b/src/api/api.cc @@ -56,6 +56,10 @@ bool API::Supports(const Option &option) const { return device_->Supports(option); } +bool API::Supports(const AddOns &addon) const { + return device_->Supports(addon); +} + const std::vector &API::GetStreamRequests( const Capabilities &capability) const { return device_->GetStreamRequests(capability); diff --git a/src/api/api.h b/src/api/api.h index 0cc6cc5..0e43de7 100644 --- a/src/api/api.h +++ b/src/api/api.h @@ -49,6 +49,7 @@ class MYNTEYE_API API { bool Supports(const Stream &stream) const; bool Supports(const Capabilities &capability) const; bool Supports(const Option &option) const; + bool Supports(const AddOns &addon) const; const std::vector &GetStreamRequests( const Capabilities &capability) const; diff --git a/src/device/device.cc b/src/device/device.cc index b97dafe..7720af1 100644 --- a/src/device/device.cc +++ b/src/device/device.cc @@ -91,6 +91,18 @@ bool Device::Supports(const Option &option) const { return supports.find(option) != supports.end(); } +bool Device::Supports(const AddOns &addon) const { + CHECK_NOTNULL(device_info_); + auto &&hw_flag = device_info_->hardware_version.flag(); + switch (addon) { + case AddOns::INFRARED: + return hw_flag[0]; + case AddOns::INFRARED2: + return hw_flag[1]; + default: { LOG(FATAL) << "Unknown add-on"; } + } +} + const std::vector &Device::GetStreamRequests( const Capabilities &capability) const { if (!Supports(capability)) { diff --git a/src/device/device.h b/src/device/device.h index d22b1e5..5ec1249 100644 --- a/src/device/device.h +++ b/src/device/device.h @@ -54,6 +54,7 @@ class MYNTEYE_API Device { bool Supports(const Stream &stream) const; bool Supports(const Capabilities &capability) const; bool Supports(const Option &option) const; + bool Supports(const AddOns &addon) const; const std::vector &GetStreamRequests( const Capabilities &capability) const; diff --git a/src/public/types.cc b/src/public/types.cc index 4914705..5ecfde3 100644 --- a/src/public/types.cc +++ b/src/public/types.cc @@ -225,4 +225,9 @@ std::ostream &operator<<(std::ostream &os, const Extrinsics &ex) { return os; } +std::ostream &operator<<(std::ostream &os, const OptionInfo &info) { + return os << "min: " << info.min << ", max: " << info.max + << ", def: " << info.def; +} + MYNTEYE_END_NAMESPACE