diff --git a/include/mynteye/types.h b/include/mynteye/types.h index 27c0216..706bc44 100644 --- a/include/mynteye/types.h +++ b/include/mynteye/types.h @@ -304,8 +304,8 @@ enum class Format : std::uint32_t { GREY = MYNTEYE_FOURCC('G', 'R', 'E', 'Y'), /** YUV 4:2:2, 16 bits per pixel */ YUYV = MYNTEYE_FOURCC('Y', 'U', 'Y', 'V'), - /** RGB 8:8:8, 24 bits per pixel */ - RGB888 = MYNTEYE_FOURCC('R', 'G', 'B', '3'), + /** BGR 8:8:8, 24 bits per pixel */ + BGR888 = MYNTEYE_FOURCC('B', 'G', 'R', '3'), /** Last guard */ LAST }; diff --git a/samples/api/camera.cc b/samples/api/camera.cc index 3f9b5fc..b72530c 100644 --- a/samples/api/camera.cc +++ b/samples/api/camera.cc @@ -25,7 +25,7 @@ int main(int argc, char *argv[]) { if (!api) return 1; api->SetStreamRequest( - Resolution::RES_1280x400, Format::RGB888, FrameRate::RATE_20_FPS); + Resolution::RES_1280x400, Format::BGR888, FrameRate::RATE_20_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 b896bce..2132ae4 100644 --- a/samples/device/camera.cc +++ b/samples/device/camera.cc @@ -52,7 +52,7 @@ int main(int argc, char *argv[]) { std::size_t left_count = 0; device->SetStreamRequest( - Resolution::RES_1280x400, Format::RGB888, FrameRate::RATE_30_FPS); + Resolution::RES_1280x400, Format::BGR888, FrameRate::RATE_30_FPS); device->SetStreamCallback( Stream::LEFT, [&left_count](const device::StreamData &data) { CHECK_NOTNULL(data.img); @@ -135,13 +135,15 @@ int main(int argc, char *argv[]) { cv::cvtColor(left_img, left_img, cv::COLOR_YUV2BGR_YUY2); cv::cvtColor(right_img, right_img, cv::COLOR_YUV2BGR_YUY2); cv::hconcat(left_img, right_img, img); - } else if (left_data.frame->format() == Format::RGB888) { + } else if (left_data.frame->format() == Format::BGR888) { cv::Mat left_img( left_data.frame->height(), left_data.frame->width(), CV_8UC3, left_data.frame->data()); cv::Mat right_img( right_data.frame->height(), right_data.frame->width(), CV_8UC3, right_data.frame->data()); + cv::cvtColor(left_img, left_img, CV_BGRA2RGBA); + cv::cvtColor(right_img, right_img, CV_BGRA2RGBA); cv::hconcat(left_img, right_img, img); } else { return -1; diff --git a/samples/uvc/camera.cc b/samples/uvc/camera.cc index 2852d63..1384d7f 100644 --- a/samples/uvc/camera.cc +++ b/samples/uvc/camera.cc @@ -108,7 +108,7 @@ int main(int argc, char *argv[]) { const auto frame_empty = [&frame]() { return frame == nullptr; }; uvc::set_device_mode( - *device, 1280, 400, static_cast(Format::RGB888), 20, + *device, 1280, 400, static_cast(Format::BGR888), 20, [&mtx, &cv, &frame, &frame_ready]( const void *data, std::function continuation) { // reinterpret_cast(data); @@ -144,7 +144,7 @@ int main(int argc, char *argv[]) { // only lastest frame is valid cv::Mat img(400, 1280, CV_8UC3, const_cast(frame->data)); - // cv::cvtColor(img, img, cv::COLOR_YUV2BGR_YUY2); + cv::cvtColor(img, img, CV_BGRA2RGBA); cv::imshow("frame", img); frame = nullptr; diff --git a/src/api/synthetic.cc b/src/api/synthetic.cc index 6e9cb5e..4b6aff4 100644 --- a/src/api/synthetic.cc +++ b/src/api/synthetic.cc @@ -45,8 +45,10 @@ cv::Mat frame2mat(const std::shared_ptr &frame) { cv::Mat img(frame->height(), frame->width(), CV_8UC2, frame->data()); cv::cvtColor(img, img, cv::COLOR_YUV2BGR_YUY2); return img; - } else if (frame->format() == Format::RGB888) { - return cv::Mat(frame->height(), frame->width(), CV_8UC3, frame->data()); + } else if (frame->format() == Format::BGR888) { + cv::Mat img(frame->height(), frame->width(), CV_8UC3, frame->data()); + cv::cvtColor(img, img, CV_BGRA2RGBA); + return img; } else { return cv::Mat(frame->height(), frame->width(), CV_8UC1, frame->data()); } diff --git a/src/internal/config.cc b/src/internal/config.cc index f02bc30..2bf99ab 100644 --- a/src/internal/config.cc +++ b/src/internal/config.cc @@ -33,17 +33,19 @@ const std::map> {Model::STANDARD, {{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}}}}}}; + {// {1280, 400, Format::YUYV, 10}, + // {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::BGR888, 10}, + {1280, 400, Format::BGR888, 20}, + {1280, 400, Format::BGR888, 30}, + {1280, 400, Format::BGR888, 60}, + {2560, 800, Format::BGR888, 10}, + {2560, 800, Format::BGR888, 20}, + {2560, 800, Format::BGR888, 30}}}}}}; MYNTEYE_END_NAMESPACE diff --git a/src/internal/streams.cc b/src/internal/streams.cc index a12459d..4ee742f 100644 --- a/src/internal/streams.cc +++ b/src/internal/streams.cc @@ -79,7 +79,7 @@ bool unpack_left_img_pixels( CHECK_NOTNULL(frame); CHECK_EQ(request.format, frame->format()); auto data_new = reinterpret_cast(data); - if (request.format == Format::YUYV || request.format == Format::RGB888) { + if (request.format == Format::YUYV || request.format == Format::BGR888) { std::size_t n = request.format == Format::YUYV ? 2 : 3; std::size_t w = frame->width() * n; std::size_t h = frame->height(); @@ -105,7 +105,7 @@ bool unpack_right_img_pixels( CHECK_NOTNULL(frame); CHECK_EQ(request.format, frame->format()); auto data_new = reinterpret_cast(data); - if (request.format == Format::YUYV || request.format == Format::RGB888) { + if (request.format == Format::YUYV || request.format == Format::BGR888) { std::size_t n = request.format == Format::YUYV ? 2 : 3; std::size_t w = frame->width() * n; std::size_t h = frame->height(); diff --git a/src/public/types.cc b/src/public/types.cc index 818af76..7516d1b 100644 --- a/src/public/types.cc +++ b/src/public/types.cc @@ -167,7 +167,7 @@ std::size_t bytes_per_pixel(const Format &value) { return 1; case Format::YUYV: return 2; - case Format::RGB888: + case Format::BGR888: return 3; default: LOG(FATAL) << "Unknown format"; diff --git a/tools/dataset/dataset.cc b/tools/dataset/dataset.cc index ef82e14..5a98f68 100644 --- a/tools/dataset/dataset.cc +++ b/tools/dataset/dataset.cc @@ -64,16 +64,36 @@ void Dataset::SaveStreamData( std::stringstream ss; ss << writer->outdir << OS_SEP << std::dec << std::setw(IMAGE_FILENAME_WIDTH) << std::setfill('0') << seq << ".png"; - cv::Mat img( - data.frame->height(), data.frame->width(), CV_8UC2, data.frame->data()); - cv::cvtColor(img, img, cv::COLOR_YUV2BGR_YUY2); - cv::imwrite(ss.str(), img); + if (data.frame->format() == Format::GREY) { + cv::Mat img( + data.frame->height(), data.frame->width(), CV_8UC1, + data.frame->data()); + cv::imwrite(ss.str(), img); + } else if (data.frame->format() == Format::YUYV) { + cv::Mat img( + data.frame->height(), data.frame->width(), CV_8UC2, + data.frame->data()); + cv::cvtColor(img, img, cv::COLOR_YUV2BGR_YUY2); + cv::imwrite(ss.str(), img); + } else if (data.frame->format() == Format::BGR888) { + cv::Mat img( + data.frame->height(), data.frame->width(), CV_8UC3, + data.frame->data()); + cv::cvtColor(img, img, CV_BGRA2RGBA); + cv::imwrite(ss.str(), img); + } else { + cv::Mat img( + data.frame->height(), data.frame->width(), CV_8UC1, + data.frame->data()); + cv::imwrite(ss.str(), img); + } } ++stream_counts_[stream]; } void Dataset::SaveMotionData(const device::MotionData &data) { auto &&writer = GetMotionWriter(); + // auto seq = data.imu->serial_number; auto seq = motion_count_; if (data.imu->flag == 1 || data.imu->flag == 2) { writer->ofs << seq << ", " << data.imu->timestamp << ", " @@ -83,6 +103,13 @@ void Dataset::SaveMotionData(const device::MotionData &data) { << data.imu->temperature << std::endl; ++motion_count_; } + /* + if(motion_count_ != seq) { + LOG(INFO) << "motion_count_ != seq !" << " motion_count_: " << motion_count_ + << " seq: " << seq; + motion_count_ = seq; + } + */ } Dataset::writer_t Dataset::GetStreamWriter(const Stream &stream) { diff --git a/tools/dataset/record.cc b/tools/dataset/record.cc index 5ecdc14..96307aa 100644 --- a/tools/dataset/record.cc +++ b/tools/dataset/record.cc @@ -31,6 +31,8 @@ int main(int argc, char *argv[]) { auto &&device = device::select(); if (!device) return 1; + device->SetStreamRequest( + Resolution::RES_1280x400, Format::BGR888, FrameRate::RATE_30_FPS); /* { // auto-exposure device->SetOptionValue(Option::EXPOSURE_MODE, 0); @@ -79,16 +81,40 @@ int main(int argc, char *argv[]) { auto &&left_frame = left_datas.back().frame; auto &&right_frame = right_datas.back().frame; - cv::Mat left_img( - left_frame->height(), left_frame->width(), CV_8UC2, left_frame->data()); - cv::Mat right_img( - right_frame->height(), right_frame->width(), CV_8UC2, - right_frame->data()); cv::Mat img; - cv::cvtColor(left_img, left_img, cv::COLOR_YUV2BGR_YUY2); - cv::cvtColor(right_img, right_img, cv::COLOR_YUV2BGR_YUY2); - cv::hconcat(left_img, right_img, img); + + if (left_frame->format() == Format::GREY) { + cv::Mat left_img( + left_frame->height(), left_frame->width(), CV_8UC1, + left_frame->data()); + cv::Mat right_img( + right_frame->height(), right_frame->width(), CV_8UC1, + right_frame->data()); + cv::hconcat(left_img, right_img, img); + } else if (left_frame->format() == Format::YUYV) { + cv::Mat left_img( + left_frame->height(), left_frame->width(), CV_8UC2, + left_frame->data()); + cv::Mat right_img( + right_frame->height(), right_frame->width(), CV_8UC2, + right_frame->data()); + cv::cvtColor(left_img, left_img, cv::COLOR_YUV2BGR_YUY2); + cv::cvtColor(right_img, right_img, cv::COLOR_YUV2BGR_YUY2); + cv::hconcat(left_img, right_img, img); + } else if (left_frame->format() == Format::BGR888) { + cv::Mat left_img( + left_frame->height(), left_frame->width(), CV_8UC3, + left_frame->data()); + cv::cvtColor(left_img, left_img, CV_BGRA2RGBA); + cv::Mat right_img( + right_frame->height(), right_frame->width(), CV_8UC3, + right_frame->data()); + cv::cvtColor(right_img, right_img, CV_BGRA2RGBA); + cv::hconcat(left_img, right_img, img); + } else { + return -1; + } cv::imshow("frame", img); { // save 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 054e484..866d057 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 @@ -532,6 +532,8 @@ class ROSWrapperNodelet : public nodelet::Nodelet { } api_ = API::Create(device); + api_->SetStreamRequest( + Resolution::RES_1280x400, Format::BGR888, FrameRate::RATE_20_FPS); } sensor_msgs::CameraInfoPtr getCameraInfo(const Stream &stream) {