Merge into devel-s210a-merge

This commit is contained in:
John Zhao 2018-12-19 17:44:20 +08:00
commit 3ead1a0c07
7 changed files with 32 additions and 13 deletions

View File

@ -121,8 +121,6 @@ int main(int argc, char *argv[]) {
cv::Mat right_img( cv::Mat right_img(
right_data.frame->height(), right_data.frame->width(), CV_8UC3, right_data.frame->height(), right_data.frame->width(), CV_8UC3,
right_data.frame->data()); right_data.frame->data());
cv::cvtColor(left_img, left_img, CV_BGR2RGB);
cv::cvtColor(right_img, right_img, CV_BGR2RGB);
cv::hconcat(left_img, right_img, img); cv::hconcat(left_img, right_img, img);
} else { } else {
return -1; return -1;

View File

@ -144,7 +144,6 @@ int main(int argc, char *argv[]) {
// only lastest frame is valid // only lastest frame is valid
cv::Mat img(400, 1280, CV_8UC3, const_cast<void *>(frame->data)); cv::Mat img(400, 1280, CV_8UC3, const_cast<void *>(frame->data));
cv::cvtColor(img, img, CV_BGR2RGB);
cv::imshow("frame", img); cv::imshow("frame", img);
frame = nullptr; frame = nullptr;

View File

@ -47,7 +47,6 @@ cv::Mat frame2mat(const std::shared_ptr<device::Frame> &frame) {
return img; return img;
} else if (frame->format() == Format::BGR888) { } else if (frame->format() == Format::BGR888) {
cv::Mat img(frame->height(), frame->width(), CV_8UC3, frame->data()); cv::Mat img(frame->height(), frame->width(), CV_8UC3, frame->data());
cv::cvtColor(img, img, CV_BGR2RGB);
return img; return img;
} else { } else {
return cv::Mat(frame->height(), frame->width(), CV_8UC1, frame->data()); return cv::Mat(frame->height(), frame->width(), CV_8UC1, frame->data());

View File

@ -78,8 +78,8 @@ bool unpack_left_img_pixels(
CHECK_NOTNULL(frame); CHECK_NOTNULL(frame);
CHECK_EQ(request.format, frame->format()); CHECK_EQ(request.format, frame->format());
auto data_new = reinterpret_cast<const std::uint8_t *>(data); auto data_new = reinterpret_cast<const std::uint8_t *>(data);
if (request.format == Format::YUYV || request.format == Format::BGR888) { if (request.format == Format::YUYV) {
std::size_t n = request.format == Format::YUYV ? 2 : 3; std::size_t n = 2;
std::size_t w = frame->width() * n; std::size_t w = frame->width() * n;
std::size_t h = frame->height(); std::size_t h = frame->height();
for (std::size_t i = 0; i < h; i++) { for (std::size_t i = 0; i < h; i++) {
@ -87,6 +87,20 @@ bool unpack_left_img_pixels(
frame->data()[i * w + j] = *(data_new + 2 * i * w + j); frame->data()[i * w + j] = *(data_new + 2 * i * w + j);
} }
} }
} else if (request.format == Format::BGR888) {
std::size_t n = 3;
std::size_t w = frame->width();
std::size_t h = frame->height();
for (std::size_t i = 0; i < h; i++) {
for (std::size_t j = 0; j < w; j++) {
frame->data()[(i * w + j) * n] =
*(data_new + (2 * i * w + j) * n + 2);
frame->data()[(i * w + j) * n + 1] =
*(data_new + (2 * i * w + j) * n + 1);
frame->data()[(i * w + j) * n + 2] =
*(data_new + (2 * i * w + j) * n);
}
}
} else if (request.format == Format::GREY) { } else if (request.format == Format::GREY) {
std::size_t n = frame->width() * frame->height(); std::size_t n = frame->width() * frame->height();
for (std::size_t i = 0; i < n; i++) { for (std::size_t i = 0; i < n; i++) {
@ -105,8 +119,8 @@ bool unpack_right_img_pixels(
CHECK_NOTNULL(frame); CHECK_NOTNULL(frame);
CHECK_EQ(request.format, frame->format()); CHECK_EQ(request.format, frame->format());
auto data_new = reinterpret_cast<const std::uint8_t *>(data); auto data_new = reinterpret_cast<const std::uint8_t *>(data);
if (request.format == Format::YUYV || request.format == Format::BGR888) { if (request.format == Format::YUYV) {
std::size_t n = request.format == Format::YUYV ? 2 : 3; std::size_t n = 2;
std::size_t w = frame->width() * n; std::size_t w = frame->width() * n;
std::size_t h = frame->height(); std::size_t h = frame->height();
for (std::size_t i = 0; i < h; i++) { for (std::size_t i = 0; i < h; i++) {
@ -114,6 +128,20 @@ bool unpack_right_img_pixels(
frame->data()[i * w + j] = *(data_new + (2 * i + 1) * w + j); frame->data()[i * w + j] = *(data_new + (2 * i + 1) * w + j);
} }
} }
} else if (request.format == Format::BGR888) {
std::size_t n = 3;
std::size_t w = frame->width();
std::size_t h = frame->height();
for (std::size_t i = 0; i < h; i++) {
for (std::size_t j = 0; j < w; j++) {
frame->data()[(i * w + j) * n] =
*(data_new + ((2 * i + 1) * w + j) * n + 2);
frame->data()[(i * w + j) * n + 1] =
*(data_new + ((2 * i + 1) * w + j) * n + 1);
frame->data()[(i * w + j) * n + 2] =
*(data_new + ((2 * i + 1) * w + j) * n);
}
}
} else if (request.format == Format::GREY) { } else if (request.format == Format::GREY) {
std::size_t n = frame->width() * frame->height(); std::size_t n = frame->width() * frame->height();
for (std::size_t i = 0; i < n; i++) { for (std::size_t i = 0; i < n; i++) {

View File

@ -80,7 +80,6 @@ void Dataset::SaveStreamData(
cv::Mat img( cv::Mat img(
data.frame->height(), data.frame->width(), CV_8UC3, data.frame->height(), data.frame->width(), CV_8UC3,
data.frame->data()); data.frame->data());
// cv::cvtColor(img, img, CV_BGR2RGB);
cv::imwrite(ss.str(), img); cv::imwrite(ss.str(), img);
} else { } else {
cv::Mat img( cv::Mat img(

View File

@ -87,8 +87,6 @@ int main(int argc, char *argv[]) {
cv::Mat right_img( cv::Mat right_img(
right_frame->height(), right_frame->width(), CV_8UC3, right_frame->height(), right_frame->width(), CV_8UC3,
right_frame->data()); right_frame->data());
cv::cvtColor(left_img, left_img, CV_BGR2RGB);
cv::cvtColor(right_img, right_img, CV_BGR2RGB);
cv::hconcat(left_img, right_img, img); cv::hconcat(left_img, right_img, img);
} else { } else {
return -1; return -1;

View File

@ -90,8 +90,6 @@ int main(int argc, char *argv[]) {
cv::Mat right_img( cv::Mat right_img(
right_frame->height(), right_frame->width(), CV_8UC3, right_frame->height(), right_frame->width(), CV_8UC3,
right_frame->data()); right_frame->data());
cv::cvtColor(left_img, left_img, CV_BGR2RGB);
cv::cvtColor(right_img, right_img, CV_BGR2RGB);
cv::hconcat(left_img, right_img, img); cv::hconcat(left_img, right_img, img);
} else { } else {
return -1; return -1;