Test addons support and add tutorial ir control

This commit is contained in:
John Zhao 2018-05-04 15:57:12 +08:00
parent 2e31a79b1a
commit e041d43183
9 changed files with 76 additions and 1 deletions

View File

@ -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

View File

@ -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()

View File

@ -0,0 +1,47 @@
#include <opencv2/highgui/highgui.hpp>
#include <glog/logging.h>
#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<char>(cv::waitKey(1));
if (key == 27 || key == 'q' || key == 'Q') { // ESC/Q
break;
}
}
api->Stop(Source::ALL);
return 0;
}

View File

@ -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<StreamRequest> &API::GetStreamRequests(
const Capabilities &capability) const {
return device_->GetStreamRequests(capability);

View File

@ -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<StreamRequest> &GetStreamRequests(
const Capabilities &capability) const;

View File

@ -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<StreamRequest> &Device::GetStreamRequests(
const Capabilities &capability) const {
if (!Supports(capability)) {

View File

@ -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<StreamRequest> &GetStreamRequests(
const Capabilities &capability) const;

View File

@ -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