Add some resolution,format and frame rate.

This commit is contained in:
Kalman 2018-08-05 23:18:51 +08:00
parent b139fd21c3
commit 33d3f15b86
13 changed files with 205 additions and 75 deletions

View File

@ -76,6 +76,8 @@ enum class Capabilities : std::uint8_t {
STEREO, STEREO,
/** Provides color stream */ /** Provides color stream */
COLOR, COLOR,
/** Provide stereo color stream */
STEREO_COLOR,
/** Provides depth stream */ /** Provides depth stream */
DEPTH, DEPTH,
/** Provides point cloud stream */ /** Provides point cloud stream */
@ -227,6 +229,40 @@ enum class AddOns : std::uint8_t {
LAST LAST
}; };
/**
* @ingroup enumerations
* @brief Camera supported resolution.
*/
enum class Resolution : std::uint8_t {
/** 480x752 */
RES_480x752,
/** 1280x400 */
RES_1280x400,
/** 2560x800 */
RES_2560x800,
/** Last guard */
LAST
};
/**
* @ingroup enumerations
* @brief Camera supported frame rate.
*/
enum class FrameRate : std::uint8_t {
/** 10 fps */
RATE_10_FPS,
/** 20 fps */
RATE_20_FPS,
/** 20 fps */
RATE_25_FPS,
/** 30 fps */
RATE_30_FPS,
/** 60 fps */
RATE_60_FPS,
/** Last guard */
LAST
};
#define MYNTEYE_ENUM_HELPERS(TYPE) \ #define MYNTEYE_ENUM_HELPERS(TYPE) \
MYNTEYE_API const char *to_string(const TYPE &value); \ MYNTEYE_API const char *to_string(const TYPE &value); \
inline bool is_valid(const TYPE &value) { \ inline bool is_valid(const TYPE &value) { \
@ -250,6 +286,8 @@ MYNTEYE_ENUM_HELPERS(Info)
MYNTEYE_ENUM_HELPERS(Option) MYNTEYE_ENUM_HELPERS(Option)
MYNTEYE_ENUM_HELPERS(Source) MYNTEYE_ENUM_HELPERS(Source)
MYNTEYE_ENUM_HELPERS(AddOns) MYNTEYE_ENUM_HELPERS(AddOns)
MYNTEYE_ENUM_HELPERS(Resolution)
MYNTEYE_ENUM_HELPERS(FrameRate)
#undef MYNTEYE_ENUM_HELPERS #undef MYNTEYE_ENUM_HELPERS
@ -266,6 +304,8 @@ enum class Format : std::uint32_t {
GREY = MYNTEYE_FOURCC('G', 'R', 'E', 'Y'), GREY = MYNTEYE_FOURCC('G', 'R', 'E', 'Y'),
/** YUV 4:2:2, 16 bits per pixel */ /** YUV 4:2:2, 16 bits per pixel */
YUYV = MYNTEYE_FOURCC('Y', 'U', 'Y', 'V'), YUYV = MYNTEYE_FOURCC('Y', 'U', 'Y', 'V'),
/** RGB 8:8:8, 24 bits per pixel */
RGB888 = MYNTEYE_FOURCC('R', 'G', 'B', '3'),
/** Last guard */ /** Last guard */
LAST LAST
}; };
@ -293,6 +333,52 @@ struct MYNTEYE_API StreamRequest {
/** Stream frames per second (unused) */ /** Stream frames per second (unused) */
std::uint16_t fps; std::uint16_t fps;
StreamRequest() {}
StreamRequest(
std::uint16_t width, std::uint16_t height, Format format,
std::uint16_t fps)
: width(width), height(height), format(format), fps(fps) {}
StreamRequest(Resolution res, Format format, FrameRate rate)
: format(format) {
switch (res) {
case Resolution::RES_480x752:
width = 480, height = 752;
break;
case Resolution::RES_1280x400:
width = 1280, height = 400;
break;
case Resolution::RES_2560x800:
width = 2560, height = 800;
break;
default:
width = 480, height = 752;
break;
}
switch (rate) {
case FrameRate::RATE_10_FPS:
fps = 10;
break;
case FrameRate::RATE_20_FPS:
fps = 20;
break;
case FrameRate::RATE_25_FPS:
fps = 25;
break;
case FrameRate::RATE_30_FPS:
fps = 30;
break;
case FrameRate::RATE_60_FPS:
fps = 60;
break;
default:
fps = 25;
break;
}
}
bool operator==(const StreamRequest &other) const { bool operator==(const StreamRequest &other) const {
return width == other.width && height == other.height && return width == other.width && height == other.height &&
format == other.format && fps == other.fps; format == other.format && fps == other.fps;

View File

@ -24,7 +24,8 @@ 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(
Resolution::RES_2560x800, Format::YUYV, 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

@ -50,6 +50,8 @@ int main(int argc, char *argv[]) {
// device->RunOptionAction(Option::ZERO_DRIFT_CALIBRATION); // device->RunOptionAction(Option::ZERO_DRIFT_CALIBRATION);
std::size_t left_count = 0; std::size_t left_count = 0;
device->SetStreamRequest(
Resolution::RES_2560x800, Format::YUYV, 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

@ -108,7 +108,7 @@ int main(int argc, char *argv[]) {
const auto frame_empty = [&frame]() { return frame == nullptr; }; const auto frame_empty = [&frame]() { return frame == nullptr; };
uvc::set_device_mode( uvc::set_device_mode(
*device, 1280, 480, static_cast<int>(Format::YUYV), 25, *device, 1280, 400, static_cast<int>(Format::RGB888), 20,
[&mtx, &cv, &frame, &frame_ready]( [&mtx, &cv, &frame, &frame_ready](
const void *data, std::function<void()> continuation) { const void *data, std::function<void()> continuation) {
// reinterpret_cast<const std::uint8_t *>(data); // reinterpret_cast<const std::uint8_t *>(data);
@ -143,8 +143,8 @@ int main(int argc, char *argv[]) {
} }
// only lastest frame is valid // only lastest frame is valid
cv::Mat img(480, 1280, CV_8UC2, const_cast<void *>(frame->data)); cv::Mat img(400, 1280, CV_8UC3, const_cast<void *>(frame->data));
cv::cvtColor(img, img, cv::COLOR_YUV2BGR_YUY2); // cv::cvtColor(img, img, cv::COLOR_YUV2BGR_YUY2);
cv::imshow("frame", img); cv::imshow("frame", img);
frame = nullptr; frame = nullptr;

View File

@ -280,6 +280,11 @@ bool API::Supports(const AddOns &addon) const {
return device_->Supports(addon); return device_->Supports(addon);
} }
void API::SetStreamRequest(
const Resolution &res, const Format &format, const FrameRate &rate) {
device_->SetStreamRequest(res, format, rate);
}
const std::vector<StreamRequest> &API::GetStreamRequests( const std::vector<StreamRequest> &API::GetStreamRequests(
const Capabilities &capability) const { const Capabilities &capability) const {
return device_->GetStreamRequests(capability); return device_->GetStreamRequests(capability);

View File

@ -144,6 +144,11 @@ class MYNTEYE_API API {
*/ */
bool Supports(const AddOns &addon) const; bool Supports(const AddOns &addon) const;
/**
* set the stream request.
*/
void SetStreamRequest(
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

@ -11,14 +11,10 @@
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and // See the License for the specific language governing permissions and
// limitations under the License. // limitations under the License.
#include "api/synthetic.h"
#include <glog/logging.h>
#include <algorithm> #include <algorithm>
#include <functional> #include <functional>
#include <stdexcept> #include <stdexcept>
#include <opencv2/imgproc/imgproc.hpp>
#include "api/plugin.h" #include "api/plugin.h"
#include "api/processor/depth_processor.h" #include "api/processor/depth_processor.h"
#include "api/processor/disparity_normalized_processor.h" #include "api/processor/disparity_normalized_processor.h"
@ -27,6 +23,7 @@
#include "api/processor/points_processor.h" #include "api/processor/points_processor.h"
#include "api/processor/processor.h" #include "api/processor/processor.h"
#include "api/processor/rectify_processor.h" #include "api/processor/rectify_processor.h"
#include "api/synthetic.h"
#include "device/device.h" #include "device/device.h"
#define RECTIFY_PROC_PERIOD 0 #define RECTIFY_PROC_PERIOD 0
@ -42,9 +39,15 @@ namespace {
cv::Mat frame2mat(const std::shared_ptr<device::Frame> &frame) { cv::Mat frame2mat(const std::shared_ptr<device::Frame> &frame) {
// TODO(JohnZhao) Support different format frame to cv::Mat // TODO(JohnZhao) Support different format frame to cv::Mat
CHECK_EQ(frame->format(), Format::YUYV); CHECK_EQ(frame->format(), Format::YUYV);
if (frame->format() == Format::YUYV) {
cv::Mat img(frame->height(), frame->width(), CV_8UC2, frame->data()); cv::Mat img(frame->height(), frame->width(), CV_8UC2, frame->data());
cv::cvtColor(img, img, cv::COLOR_YUV2BGR_YUY2); cv::cvtColor(img, img, cv::COLOR_YUV2BGR_YUY2);
return img; return img;
} else if (frame->format() == Format::RGB888) {
return cv::Mat(frame->height(), frame->width(), CV_8UC3, frame->data());
} else {
return cv::Mat(frame->height(), frame->width(), CV_8UC1, frame->data());
}
} }
api::StreamData data2api(const device::StreamData &data) { api::StreamData data2api(const device::StreamData &data) {

View File

@ -432,13 +432,22 @@ std::vector<device::MotionData> Device::GetMotionDatas() {
return motions_->GetMotionDatas(); return motions_->GetMotionDatas();
} }
void Device::SetStreamRequest(
const Resolution &res, const Format &format, const FrameRate &rate) {
StreamRequest request(res, format, rate);
request_ = request;
}
const StreamRequest &Device::GetStreamRequest(const Capabilities &capability) { const StreamRequest &Device::GetStreamRequest(const Capabilities &capability) {
try { try {
return stream_config_requests_.at(capability); return stream_config_requests_.at(capability);
} catch (const std::out_of_range &e) { } catch (const std::out_of_range &e) {
auto &&requests = GetStreamRequests(capability); auto &&requests = GetStreamRequests(capability);
if (requests.size() >= 1) { if (requests.size() >= 1) {
VLOG(2) << "Select the first one stream request of " << capability; for (auto &&request : requests) {
if (request == request_)
return request;
}
return requests[0]; return requests[0];
} else { } else {
LOG(FATAL) << "Please config the stream request of " << capability; LOG(FATAL) << "Please config the stream request of " << capability;
@ -455,28 +464,22 @@ void Device::StartVideoStreaming() {
streams_ = std::make_shared<Streams>(GetKeyStreams()); streams_ = std::make_shared<Streams>(GetKeyStreams());
// if stream capabilities are supported with subdevices of device_ // if stream capabilities are supported with subdevices of device_
/*
Capabilities stream_capabilities[] = { Capabilities stream_capabilities[] = {
Capabilities::STEREO, Capabilities::STEREO, Capabilities::COLOR,
Capabilities::COLOR, Capabilities::STEREO_COLOR, Capabilities::DEPTH,
Capabilities::DEPTH, Capabilities::POINTS, Capabilities::FISHEYE,
Capabilities::POINTS, Capabilities::INFRARED, Capabilities::INFRARED2};
Capabilities::FISHEYE,
Capabilities::INFRARED,
Capabilities::INFRARED2
};
for (auto &&capability : stream_capabilities) { for (auto &&capability : stream_capabilities) {
} if (Supports(capability)) {
*/
if (Supports(Capabilities::STEREO)) {
// do stream request selection if more than one request of each stream // do stream request selection if more than one request of each stream
auto &&stream_request = GetStreamRequest(Capabilities::STEREO); auto &&stream_request = GetStreamRequest(capability);
streams_->ConfigStream(Capabilities::STEREO, stream_request); streams_->ConfigStream(capability, stream_request);
uvc::set_device_mode( uvc::set_device_mode(
*device_, stream_request.width, stream_request.height, *device_, stream_request.width, stream_request.height,
static_cast<int>(stream_request.format), stream_request.fps, static_cast<int>(stream_request.format), stream_request.fps,
[this](const void *data, std::function<void()> continuation) { [this, capability](
const void *data, std::function<void()> continuation) {
// drop the first stereo stream data // drop the first stereo stream data
static std::uint8_t drop_count = 1; static std::uint8_t drop_count = 1;
if (drop_count > 0) { if (drop_count > 0) {
@ -487,7 +490,7 @@ void Device::StartVideoStreaming() {
// auto &&time_beg = times::now(); // auto &&time_beg = times::now();
{ {
std::lock_guard<std::mutex> _(mtx_streams_); std::lock_guard<std::mutex> _(mtx_streams_);
if (streams_->PushStream(Capabilities::STEREO, data)) { if (streams_->PushStream(capability, data)) {
CallbackPushedStreamData(Stream::LEFT); CallbackPushedStreamData(Stream::LEFT);
CallbackPushedStreamData(Stream::RIGHT); CallbackPushedStreamData(Stream::RIGHT);
} }
@ -499,9 +502,10 @@ void Device::StartVideoStreaming() {
// << " ms"; // << " ms";
}); });
} else { } else {
LOG(FATAL) << "Not any stream capabilities are supported by this device"; // LOG(FATAL) << "Not any stream capabilities are supported by this
// device";
}
} }
uvc::start_streaming(*device_, 0); uvc::start_streaming(*device_, 0);
video_streaming_ = true; video_streaming_ = true;
} }

View File

@ -103,6 +103,11 @@ class MYNTEYE_API Device {
*/ */
bool Supports(const AddOns &addon) const; bool Supports(const AddOns &addon) const;
/**
* set the stream request.
*/
void SetStreamRequest(
const Resolution &res, const Format &format, const FrameRate &rate);
/** /**
* Get all stream requests of the capability. * Get all stream requests of the capability.
*/ */
@ -286,6 +291,7 @@ class MYNTEYE_API Device {
private: private:
Model model_; Model model_;
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

@ -19,7 +19,7 @@ const std::map<Model, StreamSupports> stream_supports_map = {
{Model::STANDARD, {Stream::LEFT, Stream::RIGHT}}}; {Model::STANDARD, {Stream::LEFT, Stream::RIGHT}}};
const std::map<Model, CapabilitiesSupports> capabilities_supports_map = { const std::map<Model, CapabilitiesSupports> capabilities_supports_map = {
{Model::STANDARD, {Capabilities::STEREO, Capabilities::IMU}}}; {Model::STANDARD, {Capabilities::STEREO_COLOR, Capabilities::IMU}}};
const std::map<Model, OptionSupports> option_supports_map = { const std::map<Model, OptionSupports> option_supports_map = {
{Model::STANDARD, {Model::STANDARD,
@ -31,6 +31,19 @@ const std::map<Model, OptionSupports> option_supports_map = {
const std::map<Model, std::map<Capabilities, StreamRequests>> const std::map<Model, std::map<Capabilities, StreamRequests>>
stream_requests_map = { stream_requests_map = {
{Model::STANDARD, {Model::STANDARD,
{{Capabilities::STEREO, {{1280, 480, Format::YUYV, 25}}}}}}; {{Capabilities::STEREO, {{480, 752, Format::YUYV, 25}}},
{Capabilities::STEREO_COLOR,
{{1280, 400, Format::YUYV, 20},
{1280, 400, Format::YUYV, 30},
{1280, 400, Format::YUYV, 60},
{2560, 800, Format::YUYV, 10},
{2560, 800, Format::YUYV, 20},
{2560, 800, Format::YUYV, 30},
{1280, 400, Format::RGB888, 20},
{1280, 400, Format::RGB888, 30},
{1280, 400, Format::RGB888, 60},
{2560, 800, Format::RGB888, 10},
{2560, 800, Format::RGB888, 20},
{2560, 800, Format::RGB888, 30}}}}}};
MYNTEYE_END_NAMESPACE MYNTEYE_END_NAMESPACE

View File

@ -27,13 +27,18 @@ MYNTEYE_BEGIN_NAMESPACE
using StreamSupports = std::set<Stream>; using StreamSupports = std::set<Stream>;
using CapabilitiesSupports = std::set<Capabilities>; using CapabilitiesSupports = std::set<Capabilities>;
using OptionSupports = std::set<Option>; using OptionSupports = std::set<Option>;
using ResolutionSupports = std::set<Resolution>;
using FrameRateSupports = std::set<FrameRate>;
extern const std::map<Model, StreamSupports> stream_supports_map; extern const std::map<Model, StreamSupports> stream_supports_map;
extern const std::map<Model, CapabilitiesSupports> capabilities_supports_map; extern const std::map<Model, CapabilitiesSupports> capabilities_supports_map;
extern const std::map<Model, OptionSupports> option_supports_map; extern const std::map<Model, OptionSupports> option_supports_map;
extern const std::map<Model, ResolutionSupports> resolution_supports_map;
using StreamRequests = std::vector<StreamRequest>; using StreamRequests = std::vector<StreamRequest>;
extern const std::map<Model, std::map<Resolution, FrameRateSupports>>
framerate_Supports_supports_map;
extern const std::map<Model, std::map<Capabilities, StreamRequests>> extern const std::map<Model, std::map<Capabilities, StreamRequests>>
stream_requests_map; stream_requests_map;

View File

@ -116,7 +116,7 @@ Streams::Streams(const std::vector<Stream> key_streams)
stream_capabilities_( stream_capabilities_(
{Capabilities::STEREO, Capabilities::COLOR, Capabilities::DEPTH, {Capabilities::STEREO, Capabilities::COLOR, Capabilities::DEPTH,
Capabilities::POINTS, Capabilities::FISHEYE, Capabilities::INFRARED, Capabilities::POINTS, Capabilities::FISHEYE, Capabilities::INFRARED,
Capabilities::INFRARED2}), Capabilities::INFRARED2, Capabilities::STEREO_COLOR}),
unpack_img_data_map_( unpack_img_data_map_(
{{Stream::LEFT, unpack_stereo_img_data}, {{Stream::LEFT, unpack_stereo_img_data},
{Stream::RIGHT, unpack_stereo_img_data}}), {Stream::RIGHT, unpack_stereo_img_data}}),
@ -148,7 +148,7 @@ bool Streams::PushStream(const Capabilities &capability, const void *data) {
auto &&request = GetStreamConfigRequest(capability); auto &&request = GetStreamConfigRequest(capability);
bool pushed = false; bool pushed = false;
switch (capability) { switch (capability) {
case Capabilities::STEREO: { case Capabilities::STEREO_COLOR: {
// alloc left // alloc left
AllocStreamData(Stream::LEFT, request, Format::YUYV); AllocStreamData(Stream::LEFT, request, Format::YUYV);
auto &&left_data = stream_datas_map_[Stream::LEFT].back(); auto &&left_data = stream_datas_map_[Stream::LEFT].back();

View File

@ -2,8 +2,8 @@
--- ---
in_left: in_left:
- -
width: 752 width: 1280
height: 480 height: 800
fx: 7.3638305001095546e+02 fx: 7.3638305001095546e+02
fy: 7.2350066150722432e+02 fy: 7.2350066150722432e+02
cx: 3.5691961817119693e+02 cx: 3.5691961817119693e+02
@ -13,8 +13,8 @@ in_left:
0. ] 0. ]
in_right: in_right:
- -
width: 752 width: 1280
height: 480 height: 800
fx: 7.3638305001095546e+02 fx: 7.3638305001095546e+02
fy: 7.2350066150722432e+02 fy: 7.2350066150722432e+02
cx: 4.5668367112303980e+02 cx: 4.5668367112303980e+02