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);
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);

View File

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

View File

@ -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)
<< "}";

View File

@ -220,29 +220,51 @@ API::~API() {
VLOG(2) << __func__;
}
std::shared_ptr<API> API::Create() {
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);
std::shared_ptr<API> API::Create(Resolution res) {
auto &&device = device::select();
if (!device)
return nullptr;
device->InitResolution(res);
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(
int argc, char *argv[], std::shared_ptr<Device> 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<API>(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<StreamRequest> &API::GetStreamRequests(

View File

@ -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<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.
* @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.
*/

View File

@ -104,13 +104,14 @@ std::shared_ptr<Device> 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<StandardDevice>(device);
case 'A':
case 2:
return std::make_shared<StandardDevice>(device);
default:
LOG(FATAL) << "No such custom code now";
return std::make_shared<StandardDevice>(device);
// LOG(FATAL) << "No such generation now";
}
} else {
LOG(FATAL) << "MYNT EYE model is not supported now";
@ -432,10 +433,13 @@ std::vector<device::MotionData> 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;
}

View File

@ -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<uvc::device> device_;
std::shared_ptr<DeviceInfo> device_info_;

View File

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

View File

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