Skip to content

Commit 0e5f270

Browse files
authored
Merge pull request #127 from strykeforce/portrait-aspect
Display stream correctly for portrait orientation
2 parents 3f3b9ef + b84f200 commit 0e5f270

File tree

44 files changed

+781
-311
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+781
-311
lines changed

ansible/roles/deadeye/tasks/deadeyed.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
- -GNinja
2222
- -DCMAKE_BUILD_TYPE={{ build_type }}
2323
- -DCMAKE_INSTALL_PREFIX=/opt/deadeye
24-
- >
24+
- >-
2525
-DCMAKE_CXX_FLAGS_RELEASE=-Ofast
2626
-march=native -mtune=native -flto -ffat-lto-objects
2727
-DNDEBUG

daemon/src/capture/video_test.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,17 @@ VideoTest::VideoTest(const CaptureConfig& config) {
1717
auto background_color = j.value("backgroundColor", "000000");
1818
auto speed = j.value("speed", 0);
1919

20+
std::string_view flip = config.width == 720 && config.height == 1280
21+
? "videoflip method=clockwise !"
22+
: "";
23+
2024
auto pipeline = fmt::format(
2125
"videotestsrc pattern={} foreground-color=0x{} background-color=0x{} "
2226
"horizontal-speed={} ! video/x-raw, width={}, height={}, "
23-
"framerate={}/1 ! videoconvert ! video/x-raw, format=(string)BGR ! "
27+
"framerate={}/1 ! {} videoconvert ! video/x-raw, format=(string)BGR ! "
2428
"appsink",
2529
pattern, foreground_color, background_color, speed, config.width,
26-
config.height, config.frame_rate);
30+
config.height, config.frame_rate, flip);
2731

2832
cap_.open(pipeline, cv::CAP_GSTREAMER);
2933
spdlog::debug("VideoTest: opened cap_: {}", pipeline);

daemon/src/hardware/led_drive.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ using ::deadeye::LedDrive;
77
#ifdef __aarch64__
88
#include <cassert>
99
using ::gpiod::chip;
10+
using ::gpiod::line_request;
1011

1112
LedDrive::LedDrive(int inum) {
1213
assert(inum >= 0 && inum < 5);

daemon/src/pipeline/streamer.cpp

Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -34,17 +34,24 @@ Streamer::Streamer(const Pipeline* pipeline, const cv::Size size)
3434
int hr = h / r;
3535
spdlog::debug("Streamer: capture output: {}x{} ({}:{})", w, h, wr, hr);
3636

37+
tb_border_ = 0;
38+
lr_border_ = 0;
39+
frame_tb_border_ = 2;
40+
frame_lr_border_ = 2;
3741
if (wr == 4 && hr == 3) { // 4:3
38-
border_ = 0;
42+
// no change
3943
} else if (wr == 16 && hr == 9) {
40-
border_ = h / 6;
44+
tb_border_ = h / 6;
45+
} else if (wr == 9 && hr == 16) {
46+
lr_border_ = w * 2 / 3;
47+
frame_tb_border_ = 1;
4148
} else {
4249
spdlog::error("Streamer: invalid aspect ratio: {}:{}", wr, hr);
43-
border_ = 0;
50+
tb_border_ = 0;
4451
}
4552

46-
spdlog::debug("Streamer border: {} {}", border_,
47-
resize_ ? "[output resized]" : "");
53+
spdlog::debug("Streamer tb_border: {}, lr_border_ {} {}", tb_border_,
54+
lr_border_, resize_ ? "[output resized]" : "");
4855

4956
server_.SetSource(source_);
5057
spdlog::info("{} streaming on port {}", *pipeline_, server_.GetPort());
@@ -61,6 +68,9 @@ void Streamer::Process(const cv::Mat& frame, const TargetData* target) {
6168
if (config_.contour != Contour::none) {
6269
output_ = cv::Mat::zeros(frame.size(), CV_8UC3);
6370
}
71+
cv::copyMakeBorder(output_, output_, frame_tb_border_, frame_tb_border_,
72+
frame_lr_border_, frame_lr_border_,
73+
cv::BORDER_CONSTANT, cv::Scalar(255, 255, 255));
6474
break;
6575
case View::original:
6676
if (config_.contour != Contour::none) {
@@ -72,6 +82,9 @@ void Streamer::Process(const cv::Mat& frame, const TargetData* target) {
7282
break;
7383
case View::mask:
7484
cv::cvtColor(pipeline_->GetMask(), output_, cv::COLOR_GRAY2BGR);
85+
cv::copyMakeBorder(output_, output_, frame_tb_border_, frame_tb_border_,
86+
frame_lr_border_, frame_lr_border_,
87+
cv::BORDER_CONSTANT, cv::Scalar(255, 255, 255));
7588
break;
7689
}
7790

@@ -90,8 +103,12 @@ void Streamer::Process(const cv::Mat& frame, const TargetData* target) {
90103
break;
91104
}
92105

93-
if (border_ != 0)
94-
cv::copyMakeBorder(output_, output_, border_, border_, 0, 0,
106+
if (tb_border_ != 0)
107+
cv::copyMakeBorder(output_, output_, tb_border_, tb_border_, 0, 0,
108+
cv::BORDER_CONSTANT, cv::Scalar(0, 0, 0));
109+
110+
if (lr_border_ != 0)
111+
cv::copyMakeBorder(output_, output_, 0, 0, lr_border_, lr_border_,
95112
cv::BORDER_CONSTANT, cv::Scalar(0, 0, 0));
96113

97114
if (resize_) cv::resize(output_, output_, kStreamSize, 0, 0, cv::INTER_AREA);

daemon/src/pipeline/streamer.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,10 @@ class Streamer {
2424
const Pipeline* pipeline_;
2525
cv::Mat output_;
2626
StreamConfig config_;
27-
int border_;
27+
int tb_border_;
28+
int lr_border_;
29+
int frame_tb_border_;
30+
int frame_lr_border_;
2831
bool resize_;
2932
cs::MjpegServer server_;
3033
cs::CvSource source_;

web/.idea/inspectionProfiles/Project_Default.xml

Lines changed: 37 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

web/.idea/jsLinters/eslint.xml

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

web/.idea/prettier.xml

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

web/.idea/templateLanguages.xml

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

web/.idea/watcherTasks.xml

Lines changed: 4 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)