Add initReslution

This commit is contained in:
Kalman 2018-09-21 19:25:27 +08:00
parent 30332a80de
commit fbdbb5b6f6
9 changed files with 70 additions and 39 deletions

View File

@ -24,8 +24,7 @@ int main(int argc, char *argv[]) {
auto &&api = API::Create(argc, argv); auto &&api = API::Create(argc, argv);
if (!api) if (!api)
return 1; return 1;
api->SetStreamRequest( api->SetStreamRequest(Format::BGR888, FrameRate::RATE_30_FPS);
Resolution::RES_1280x400, Format::BGR888, FrameRate::RATE_20_FPS);
// api->SetOptionValue(Option::FRAME_RATE, 25); // api->SetOptionValue(Option::FRAME_RATE, 25);
// api->SetOptionValue(Option::IMU_FREQUENCY, 500); // api->SetOptionValue(Option::IMU_FREQUENCY, 500);
api->SetOptionValue(Option::IR_CONTROL, 80); api->SetOptionValue(Option::IR_CONTROL, 80);

View File

@ -51,8 +51,8 @@ int main(int argc, char *argv[]) {
// device->RunOptionAction(Option::ERASE_CHIP); // device->RunOptionAction(Option::ERASE_CHIP);
std::size_t left_count = 0; std::size_t left_count = 0;
device->SetStreamRequest( device->InitResolution(Resolution::RES_1280x400);
Resolution::RES_1280x400, Format::BGR888, FrameRate::RATE_30_FPS); device->SetStreamRequest(Format::BGR888, FrameRate::RATE_30_FPS);
device->SetStreamCallback( device->SetStreamCallback(
Stream::LEFT, [&left_count](const device::StreamData &data) { Stream::LEFT, [&left_count](const device::StreamData &data) {
CHECK_NOTNULL(data.img); CHECK_NOTNULL(data.img);

View File

@ -21,8 +21,7 @@ int main(int argc, char *argv[]) {
auto &&api = API::Create(argc, argv); auto &&api = API::Create(argc, argv);
if (!api) if (!api)
return 1; return 1;
api->SetStreamRequest( api->SetStreamRequest(Format::BGR888, FrameRate::RATE_30_FPS);
Resolution::RES_2560x800, Format::BGR888, FrameRate::RATE_30_FPS);
LOG(INFO) << "Intrinsics left: {" << api->GetIntrinsics(Stream::LEFT) << "}"; LOG(INFO) << "Intrinsics left: {" << api->GetIntrinsics(Stream::LEFT) << "}";
LOG(INFO) << "Intrinsics right: {" << api->GetIntrinsics(Stream::RIGHT) LOG(INFO) << "Intrinsics right: {" << api->GetIntrinsics(Stream::RIGHT)
<< "}"; << "}";

View File

@ -220,29 +220,51 @@ API::~API() {
VLOG(2) << __func__; VLOG(2) << __func__;
} }
std::shared_ptr<API> API::Create() { std::shared_ptr<API> API::Create(Resolution res) {
return Create(device::select());
}
std::shared_ptr<API> API::Create(std::shared_ptr<Device> device) {
if (!device)
return nullptr;
return std::make_shared<API>(device);
}
std::shared_ptr<API> API::Create(int argc, char *argv[]) {
static glog_init _(argc, argv);
auto &&device = device::select(); auto &&device = device::select();
if (!device) if (!device)
return nullptr; return nullptr;
device->InitResolution(res);
return std::make_shared<API>(device); return std::make_shared<API>(device);
} }
std::shared_ptr<API> API::Create(
std::shared_ptr<Device> device, Resolution res) {
if (!device)
return nullptr;
LOG(INFO) << "API::Create(std::shared_ptr<Device> device,Resolution res)";
device->InitResolution(res);
return std::make_shared<API>(device);
}
std::shared_ptr<API> API::Create(std::shared_ptr<Device> device) {
return Create(device, Resolution::RES_2560x800);
}
std::shared_ptr<API> API::Create(int argc, char *argv[]) {
auto &&device = device::select();
return Create(argc, argv, device);
}
std::shared_ptr<API> API::Create( std::shared_ptr<API> API::Create(
int argc, char *argv[], std::shared_ptr<Device> device) { int argc, char *argv[], std::shared_ptr<Device> device) {
static glog_init _(argc, argv); static glog_init _(argc, argv);
int index = 0;
if (argc >= 2) {
try {
index = std::stoi(argv[1]);
} catch (...) {
LOG(WARNING) << "Unexpected index.";
}
}
if (!device) if (!device)
return nullptr; 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<API>(device); return std::make_shared<API>(device);
} }
@ -266,10 +288,8 @@ bool API::Supports(const AddOns &addon) const {
return device_->Supports(addon); return device_->Supports(addon);
} }
void API::SetStreamRequest( void API::SetStreamRequest(const Format &format, const FrameRate &rate) {
const Resolution &res, const Format &format, const FrameRate &rate) { device_->SetStreamRequest(format, rate);
device_->SetStreamRequest(res, format, rate);
CheckImageParams();
} }
const std::vector<StreamRequest> &API::GetStreamRequests( const std::vector<StreamRequest> &API::GetStreamRequests(

View File

@ -95,7 +95,14 @@ class MYNTEYE_API API {
* @return the API instance. * @return the API instance.
* @note This will call device::select() to select a device. * @note This will call device::select() to select a device.
*/ */
static std::shared_ptr<API> Create(); static std::shared_ptr<API> Create(Resolution res);
/**
* Create the API instance.
* @param device the selected device.
* @return the API instance.
*/
static std::shared_ptr<API> Create(
std::shared_ptr<Device> device, Resolution res);
/** /**
* Create the API instance. * Create the API instance.
* @param device the selected device. * @param device the selected device.
@ -147,8 +154,7 @@ class MYNTEYE_API API {
/** /**
* set the stream request. * set the stream request.
*/ */
void SetStreamRequest( void SetStreamRequest(const Format &format, const FrameRate &rate);
const Resolution &res, const Format &format, const FrameRate &rate);
/** /**
* Get all stream requests of the capability. * Get all stream requests of the capability.
*/ */

View File

@ -104,13 +104,14 @@ std::shared_ptr<Device> Device::Create(
VLOG(2) << "MYNE EYE Model: " << model_s; VLOG(2) << "MYNE EYE Model: " << model_s;
DeviceModel model(model_s); DeviceModel model(model_s);
if (model.type == 'S') { if (model.type == 'S') {
switch (model.custom_code) { switch (model.generation) {
case '0': case 1:
return std::make_shared<StandardDevice>(device); return std::make_shared<StandardDevice>(device);
case 'A': case 2:
return std::make_shared<StandardDevice>(device); return std::make_shared<StandardDevice>(device);
default: default:
LOG(FATAL) << "No such custom code now"; return std::make_shared<StandardDevice>(device);
// LOG(FATAL) << "No such generation now";
} }
} else { } else {
LOG(FATAL) << "MYNT EYE model is not supported now"; LOG(FATAL) << "MYNT EYE model is not supported now";
@ -432,10 +433,13 @@ std::vector<device::MotionData> Device::GetMotionDatas() {
return motions_->GetMotionDatas(); return motions_->GetMotionDatas();
} }
void Device::SetStreamRequest( void Device::InitResolution(const Resolution &res) {
const Resolution &res, const Format &format, const FrameRate &rate) { res_ = res;
StreamRequest request(res, format, rate); ConfigIntrinsics(res_);
ConfigIntrinsics(res); }
void Device::SetStreamRequest(const Format &format, const FrameRate &rate) {
StreamRequest request(res_, format, rate);
request_ = request; request_ = request;
} }

View File

@ -103,12 +103,14 @@ class MYNTEYE_API Device {
* Supports the addon or not. * Supports the addon or not.
*/ */
bool Supports(const AddOns &addon) const; bool Supports(const AddOns &addon) const;
/**
* Init device resolution.
*/
void InitResolution(const Resolution &res);
/** /**
* set the stream request. * set the stream request.
*/ */
void SetStreamRequest( void SetStreamRequest(const Format &format, const FrameRate &rate);
const Resolution &res, const Format &format, const FrameRate &rate);
/** /**
* Get all stream requests of the capability. * Get all stream requests of the capability.
*/ */
@ -296,6 +298,7 @@ class MYNTEYE_API Device {
private: private:
Model model_; Model model_;
Resolution res_ = Resolution::RES_752x480;
StreamRequest request_; StreamRequest request_;
std::shared_ptr<uvc::device> device_; std::shared_ptr<uvc::device> device_;
std::shared_ptr<DeviceInfo> device_info_; std::shared_ptr<DeviceInfo> device_info_;

View File

@ -96,6 +96,7 @@ add_compile_options(-std=c++11)
include_directories( include_directories(
${catkin_INCLUDE_DIRS} ${catkin_INCLUDE_DIRS}
${SDK_DIR}/src
) )
set(LINK_LIBS set(LINK_LIBS

View File

@ -531,9 +531,8 @@ class ROSWrapperNodelet : public nodelet::Nodelet {
} }
} }
api_ = API::Create(device); api_ = API::Create(device, Resolution::RES_1280x400);
api_->SetStreamRequest( api_->SetStreamRequest(Format::BGR888, FrameRate::RATE_20_FPS);
Resolution::RES_1280x400, Format::BGR888, FrameRate::RATE_20_FPS);
} }
sensor_msgs::CameraInfoPtr getCameraInfo(const Stream &stream) { sensor_msgs::CameraInfoPtr getCameraInfo(const Stream &stream) {