diff --git a/samples/api/camera.cc b/samples/api/camera.cc index b72530c..a90c102 100644 --- a/samples/api/camera.cc +++ b/samples/api/camera.cc @@ -24,8 +24,7 @@ int main(int argc, char *argv[]) { auto &&api = API::Create(argc, argv); if (!api) return 1; - api->SetStreamRequest( - Resolution::RES_1280x400, Format::BGR888, FrameRate::RATE_20_FPS); + api->SetStreamRequest(Format::BGR888, FrameRate::RATE_30_FPS); // api->SetOptionValue(Option::FRAME_RATE, 25); // api->SetOptionValue(Option::IMU_FREQUENCY, 500); api->SetOptionValue(Option::IR_CONTROL, 80); diff --git a/samples/device/camera.cc b/samples/device/camera.cc index 19f03d4..e59211c 100644 --- a/samples/device/camera.cc +++ b/samples/device/camera.cc @@ -51,8 +51,8 @@ int main(int argc, char *argv[]) { // device->RunOptionAction(Option::ERASE_CHIP); std::size_t left_count = 0; - device->SetStreamRequest( - Resolution::RES_1280x400, Format::BGR888, FrameRate::RATE_30_FPS); + device->InitResolution(Resolution::RES_1280x400); + device->SetStreamRequest(Format::BGR888, FrameRate::RATE_30_FPS); device->SetStreamCallback( Stream::LEFT, [&left_count](const device::StreamData &data) { CHECK_NOTNULL(data.img); diff --git a/samples/tutorials/data/get_img_params.cc b/samples/tutorials/data/get_img_params.cc index aa79016..3f09524 100644 --- a/samples/tutorials/data/get_img_params.cc +++ b/samples/tutorials/data/get_img_params.cc @@ -21,8 +21,7 @@ int main(int argc, char *argv[]) { auto &&api = API::Create(argc, argv); if (!api) return 1; - api->SetStreamRequest( - Resolution::RES_2560x800, Format::BGR888, FrameRate::RATE_30_FPS); + api->SetStreamRequest(Format::BGR888, FrameRate::RATE_30_FPS); LOG(INFO) << "Intrinsics left: {" << api->GetIntrinsics(Stream::LEFT) << "}"; LOG(INFO) << "Intrinsics right: {" << api->GetIntrinsics(Stream::RIGHT) << "}"; diff --git a/src/api/api.cc b/src/api/api.cc index 50b0893..7751fe6 100644 --- a/src/api/api.cc +++ b/src/api/api.cc @@ -220,29 +220,51 @@ API::~API() { VLOG(2) << __func__; } -std::shared_ptr API::Create() { - return Create(device::select()); -} - -std::shared_ptr API::Create(std::shared_ptr device) { - if (!device) - return nullptr; - return std::make_shared(device); -} - -std::shared_ptr API::Create(int argc, char *argv[]) { - static glog_init _(argc, argv); +std::shared_ptr API::Create(Resolution res) { auto &&device = device::select(); if (!device) return nullptr; + device->InitResolution(res); return std::make_shared(device); } +std::shared_ptr API::Create( + std::shared_ptr device, Resolution res) { + if (!device) + return nullptr; + LOG(INFO) << "API::Create(std::shared_ptr device,Resolution res)"; + device->InitResolution(res); + return std::make_shared(device); +} + +std::shared_ptr API::Create(std::shared_ptr device) { + return Create(device, Resolution::RES_2560x800); +} + +std::shared_ptr API::Create(int argc, char *argv[]) { + auto &&device = device::select(); + return Create(argc, argv, device); +} + std::shared_ptr API::Create( int argc, char *argv[], std::shared_ptr device) { static glog_init _(argc, argv); + int index = 0; + if (argc >= 2) { + try { + index = std::stoi(argv[1]); + } catch (...) { + LOG(WARNING) << "Unexpected index."; + } + } if (!device) return nullptr; + if (index == 0) + device->InitResolution(Resolution::RES_1280x400); + else if (index == 1) + device->InitResolution(Resolution::RES_2560x800); + else + device->InitResolution(Resolution::RES_1280x400); return std::make_shared(device); } @@ -266,10 +288,8 @@ bool API::Supports(const AddOns &addon) const { return device_->Supports(addon); } -void API::SetStreamRequest( - const Resolution &res, const Format &format, const FrameRate &rate) { - device_->SetStreamRequest(res, format, rate); - CheckImageParams(); +void API::SetStreamRequest(const Format &format, const FrameRate &rate) { + device_->SetStreamRequest(format, rate); } const std::vector &API::GetStreamRequests( diff --git a/src/api/api.h b/src/api/api.h index 5f17147..5451ad0 100644 --- a/src/api/api.h +++ b/src/api/api.h @@ -95,7 +95,14 @@ class MYNTEYE_API API { * @return the API instance. * @note This will call device::select() to select a device. */ - static std::shared_ptr Create(); + static std::shared_ptr Create(Resolution res); + /** + * Create the API instance. + * @param device the selected device. + * @return the API instance. + */ + static std::shared_ptr Create( + std::shared_ptr device, Resolution res); /** * Create the API instance. * @param device the selected device. @@ -147,8 +154,7 @@ class MYNTEYE_API API { /** * set the stream request. */ - void SetStreamRequest( - const Resolution &res, const Format &format, const FrameRate &rate); + void SetStreamRequest(const Format &format, const FrameRate &rate); /** * Get all stream requests of the capability. */ diff --git a/src/device/device.cc b/src/device/device.cc index b92208e..c78f850 100644 --- a/src/device/device.cc +++ b/src/device/device.cc @@ -104,13 +104,14 @@ std::shared_ptr Device::Create( VLOG(2) << "MYNE EYE Model: " << model_s; DeviceModel model(model_s); if (model.type == 'S') { - switch (model.custom_code) { - case '0': + switch (model.generation) { + case 1: return std::make_shared(device); - case 'A': + case 2: return std::make_shared(device); default: - LOG(FATAL) << "No such custom code now"; + return std::make_shared(device); + // LOG(FATAL) << "No such generation now"; } } else { LOG(FATAL) << "MYNT EYE model is not supported now"; @@ -432,10 +433,13 @@ std::vector Device::GetMotionDatas() { return motions_->GetMotionDatas(); } -void Device::SetStreamRequest( - const Resolution &res, const Format &format, const FrameRate &rate) { - StreamRequest request(res, format, rate); - ConfigIntrinsics(res); +void Device::InitResolution(const Resolution &res) { + res_ = res; + ConfigIntrinsics(res_); +} + +void Device::SetStreamRequest(const Format &format, const FrameRate &rate) { + StreamRequest request(res_, format, rate); request_ = request; } diff --git a/src/device/device.h b/src/device/device.h index ae9d608..035335e 100644 --- a/src/device/device.h +++ b/src/device/device.h @@ -103,12 +103,14 @@ class MYNTEYE_API Device { * Supports the addon or not. */ bool Supports(const AddOns &addon) const; - + /** + * Init device resolution. + */ + void InitResolution(const Resolution &res); /** * set the stream request. */ - void SetStreamRequest( - const Resolution &res, const Format &format, const FrameRate &rate); + void SetStreamRequest(const Format &format, const FrameRate &rate); /** * Get all stream requests of the capability. */ @@ -296,6 +298,7 @@ class MYNTEYE_API Device { private: Model model_; + Resolution res_ = Resolution::RES_752x480; StreamRequest request_; std::shared_ptr device_; std::shared_ptr device_info_; diff --git a/wrappers/ros/src/mynt_eye_ros_wrapper/CMakeLists.txt b/wrappers/ros/src/mynt_eye_ros_wrapper/CMakeLists.txt index 83ffce1..a8ef045 100644 --- a/wrappers/ros/src/mynt_eye_ros_wrapper/CMakeLists.txt +++ b/wrappers/ros/src/mynt_eye_ros_wrapper/CMakeLists.txt @@ -96,6 +96,7 @@ add_compile_options(-std=c++11) include_directories( ${catkin_INCLUDE_DIRS} + ${SDK_DIR}/src ) set(LINK_LIBS diff --git a/wrappers/ros/src/mynt_eye_ros_wrapper/src/wrapper_nodelet.cc b/wrappers/ros/src/mynt_eye_ros_wrapper/src/wrapper_nodelet.cc index 866d057..e0fddc6 100644 --- a/wrappers/ros/src/mynt_eye_ros_wrapper/src/wrapper_nodelet.cc +++ b/wrappers/ros/src/mynt_eye_ros_wrapper/src/wrapper_nodelet.cc @@ -531,9 +531,8 @@ class ROSWrapperNodelet : public nodelet::Nodelet { } } - api_ = API::Create(device); - api_->SetStreamRequest( - Resolution::RES_1280x400, Format::BGR888, FrameRate::RATE_20_FPS); + api_ = API::Create(device, Resolution::RES_1280x400); + api_->SetStreamRequest(Format::BGR888, FrameRate::RATE_20_FPS); } sensor_msgs::CameraInfoPtr getCameraInfo(const Stream &stream) {