Get real exposure time and draw

This commit is contained in:
John Zhao 2018-05-13 10:34:03 +08:00
parent aca1f8b183
commit 9e7c2cfa68
7 changed files with 83 additions and 9 deletions

View File

@ -368,7 +368,7 @@ struct MYNTEYE_API ImgData {
std::uint16_t frame_id; std::uint16_t frame_id;
/** Image timestamp in 0.01ms */ /** Image timestamp in 0.01ms */
std::uint32_t timestamp; std::uint32_t timestamp;
/** Image exposure time in 0.01ms */ /** Image exposure time, virtual value in [1, 480] */
std::uint16_t exposure_time; std::uint16_t exposure_time;
void Reset() { void Reset() {

View File

@ -30,6 +30,15 @@ MYNTEYE_API std::shared_ptr<Device> select();
} // namespace device } // namespace device
namespace utils {
/** Get real exposure time in ms from virtual value, according to its frame rate
*/
MYNTEYE_API float get_real_exposure_time(
std::int32_t frame_rate, std::uint16_t exposure_time);
} // namespace utils
MYNTEYE_END_NAMESPACE MYNTEYE_END_NAMESPACE
#endif // MYNTEYE_UTILS_H_ NOLINT #endif // MYNTEYE_UTILS_H_ NOLINT

View File

@ -43,7 +43,7 @@ int main(int argc, char *argv[]) {
api->Start(Source::VIDEO_STREAMING); api->Start(Source::VIDEO_STREAMING);
CVPainter painter; CVPainter painter(api->GetOptionValue(Option::FRAME_RATE));
cv::namedWindow("frame"); cv::namedWindow("frame");

View File

@ -41,7 +41,7 @@ int main(int argc, char *argv[]) {
api->Start(Source::VIDEO_STREAMING); api->Start(Source::VIDEO_STREAMING);
CVPainter painter; CVPainter painter(api->GetOptionValue(Option::FRAME_RATE));
cv::namedWindow("frame"); cv::namedWindow("frame");

View File

@ -22,6 +22,8 @@
#include <memory> #include <memory>
#include <utility> #include <utility>
#include "mynteye/utils.h"
#define FONT_FACE cv::FONT_HERSHEY_PLAIN #define FONT_FACE cv::FONT_HERSHEY_PLAIN
#define FONT_SCALE 1 #define FONT_SCALE 1
#define FONT_COLOR cv::Scalar(255, 255, 255) #define FONT_COLOR cv::Scalar(255, 255, 255)
@ -32,8 +34,10 @@ namespace {
std::shared_ptr<std::ios> NewFormat(int width, int prec, char fillch = ' ') { std::shared_ptr<std::ios> NewFormat(int width, int prec, char fillch = ' ') {
auto fmt = std::make_shared<std::ios>(nullptr); auto fmt = std::make_shared<std::ios>(nullptr);
fmt->setf(std::ios::fixed); fmt->setf(std::ios::fixed);
fmt->width(std::move(width)); if (width > 0)
fmt->precision(std::move(prec)); fmt->width(std::move(width));
if (prec > 0)
fmt->precision(std::move(prec));
fmt->fill(std::move(fillch)); fmt->fill(std::move(fillch));
return fmt; return fmt;
} }
@ -53,7 +57,8 @@ std::ostream &operator<<(
return os; return os;
} }
CVPainter::CVPainter() { CVPainter::CVPainter(std::int32_t frame_rate)
: frame_rate_(std::move(frame_rate)) {
VLOG(2) << __func__; VLOG(2) << __func__;
} }
@ -74,9 +79,18 @@ cv::Rect CVPainter::DrawImgData(
if (gravity == BOTTOM_LEFT || gravity == BOTTOM_RIGHT) if (gravity == BOTTOM_LEFT || gravity == BOTTOM_RIGHT)
sign = -1; sign = -1;
static auto fmt_time = NewFormat(0, 2);
std::ostringstream ss; std::ostringstream ss;
ss << "frame_id: " << data.frame_id << ", stamp: " << data.timestamp ss << "frame_id: " << data.frame_id;
<< ", expo: " << data.exposure_time; ss << ", stamp: " << fmt_time << (0.01f * data.timestamp); // ms
ss << ", expo: ";
if (frame_rate_ == 0) {
ss << data.exposure_time;
} else {
ss << fmt_time << mynteye::utils::get_real_exposure_time(
frame_rate_, data.exposure_time);
}
cv::Rect rect_i = DrawText(img, ss.str(), gravity, 5); cv::Rect rect_i = DrawText(img, ss.str(), gravity, 5);
Clear(ss) << "size: " << img.cols << "x" << img.rows; Clear(ss) << "size: " << img.cols << "x" << img.rows;

View File

@ -30,7 +30,7 @@ class CVPainter {
BOTTOM_RIGHT BOTTOM_RIGHT
} gravity_t; } gravity_t;
CVPainter(); explicit CVPainter(std::int32_t frame_rate = 0);
~CVPainter(); ~CVPainter();
cv::Rect DrawSize(const cv::Mat &img, const gravity_t &gravity = TOP_LEFT); cv::Rect DrawSize(const cv::Mat &img, const gravity_t &gravity = TOP_LEFT);
@ -45,6 +45,9 @@ class CVPainter {
const cv::Mat &img, const std::string &text, const cv::Mat &img, const std::string &text,
const gravity_t &gravity = TOP_LEFT, const int &margin = 5, const gravity_t &gravity = TOP_LEFT, const int &margin = 5,
const int &offset_x = 0, const int &offset_y = 0); const int &offset_x = 0, const int &offset_y = 0);
private:
std::int32_t frame_rate_;
}; };
#endif // MYNTEYE_TUTORIALS_CV_PAINTER_H_ NOLINT #endif // MYNTEYE_TUTORIALS_CV_PAINTER_H_ NOLINT

View File

@ -60,4 +60,52 @@ std::shared_ptr<Device> select() {
} // namespace device } // namespace device
namespace utils {
float get_real_exposure_time(
std::int32_t frame_rate, std::uint16_t exposure_time) {
float real_max = 0;
switch (frame_rate) {
case 10:
real_max = 18;
break;
case 15:
real_max = 18;
break;
case 20:
real_max = 18;
break;
case 25:
real_max = 18;
break;
case 30:
real_max = 18;
break;
case 35:
real_max = 18;
break;
case 40:
real_max = 18;
break;
case 45:
real_max = 18;
break;
case 50:
real_max = 17;
break;
case 55:
real_max = 16.325;
break;
case 60:
real_max = 15;
break;
default:
LOG(ERROR) << "Invalid frame rate: " << frame_rate;
return exposure_time;
}
return exposure_time * real_max / 480.f;
}
} // namespace utils
MYNTEYE_END_NAMESPACE MYNTEYE_END_NAMESPACE