Skip to content

Commit

Permalink
fix(rviz_plugin): fix screen capture plugin (tier4#1492)
Browse files Browse the repository at this point in the history
Signed-off-by: tanaka3 <ttatcoder@outlook.jp>
  • Loading branch information
taikitanaka3 authored and boyali committed Oct 3, 2022
1 parent 5f096aa commit ad0d63b
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ AutowareScreenCapturePanel::AutowareScreenCapturePanel(QWidget * parent)
connect(screen_capture_button_ptr_, SIGNAL(clicked()), this, SLOT(onClickScreenCapture()));
cap_layout->addWidget(screen_capture_button_ptr_);
cap_layout->addWidget(ros_time_label_);
// initialize file name system clock is better for identification.
setFormatDate(ros_time_label_, rclcpp::Clock().now().seconds());
cap_layout->addWidget(new QLabel(" [.mp4] "));
}

Expand Down Expand Up @@ -104,13 +106,6 @@ void AutowareScreenCapturePanel::onClickScreenCapture()
return;
}

void AutowareScreenCapturePanel::convertPNGImagesToMP4()
{
writer.release();
// remove temporary created folder
std::filesystem::remove_all(root_folder_);
}

void AutowareScreenCapturePanel::onClickVideoCapture()
{
const int clock = static_cast<int>(1e3 / capture_hz_->value());
Expand All @@ -130,9 +125,7 @@ void AutowareScreenCapturePanel::onClickVideoCapture()
case State::WAITING_FOR_CAPTURE:
// initialize setting
{
counter_ = 0;
root_folder_ = ros_time_label_->text().toStdString();
std::filesystem::create_directory(root_folder_);
capture_file_name_ = ros_time_label_->text().toStdString();
}
capture_to_mp4_button_ptr_->setText("capturing rviz screen");
capture_to_mp4_button_ptr_->setStyleSheet("background-color: #FF0000;");
Expand All @@ -146,17 +139,14 @@ void AutowareScreenCapturePanel::onClickVideoCapture()
.size();
current_movie_size = cv::Size(qsize.width(), qsize.height());
writer.open(
"capture/" + root_folder_ + ".mp4", fourcc, capture_hz_->value(), current_movie_size);
"capture/" + capture_file_name_ + ".mp4", fourcc, capture_hz_->value(),
current_movie_size);
}
capture_timer_->start(clock);
state_ = State::CAPTURING;
break;
case State::CAPTURING: {
case State::CAPTURING:
capture_timer_->stop();
}
capture_to_mp4_button_ptr_->setText("writing to video");
capture_to_mp4_button_ptr_->setStyleSheet("background-color: #FFFF00;");
convertPNGImagesToMP4();
capture_to_mp4_button_ptr_->setText("waiting for capture");
capture_to_mp4_button_ptr_->setStyleSheet("background-color: #00FF00;");
state_ = State::WAITING_FOR_CAPTURE;
Expand All @@ -181,7 +171,6 @@ void AutowareScreenCapturePanel::onTimer()
cv::Mat new_image;
cv::resize(image, new_image, current_movie_size);
writer.write(new_image);

} else {
writer.write(image);
}
Expand All @@ -190,17 +179,14 @@ void AutowareScreenCapturePanel::onTimer()

void AutowareScreenCapturePanel::update()
{
setFormatDate(ros_time_label_, raw_node_->get_clock()->now().seconds());
setFormatDate(ros_time_label_, rclcpp::Clock().now().seconds());
}

void AutowareScreenCapturePanel::save(rviz_common::Config config) const { Panel::save(config); }

void AutowareScreenCapturePanel::load(const rviz_common::Config & config) { Panel::load(config); }

AutowareScreenCapturePanel::~AutowareScreenCapturePanel()
{
std::filesystem::remove_all(root_folder_);
}
AutowareScreenCapturePanel::~AutowareScreenCapturePanel() = default;

#include <pluginlib/class_list_macros.hpp>
PLUGINLIB_EXPORT_CLASS(AutowareScreenCapturePanel, rviz_common::Panel)
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@ class AutowareScreenCapturePanel : public rviz_common::Panel
void onInitialize() override;
void createWallTimer();
void onTimer();
void convertPNGImagesToMP4();
void save(rviz_common::Config config) const override;
void load(const rviz_common::Config & config) override;
void onCaptureTrigger(
Expand All @@ -67,7 +66,6 @@ class AutowareScreenCapturePanel : public rviz_common::Panel

public Q_SLOTS:
void onClickScreenCapture();
void onClickCaptureToVideo();
void onClickVideoCapture();
void onRateChanged();

Expand All @@ -80,8 +78,7 @@ public Q_SLOTS:
QMainWindow * main_window_;
enum class State { WAITING_FOR_CAPTURE, CAPTURING };
State state_;
std::string root_folder_;
size_t counter_;
std::string capture_file_name_;
bool is_capture_;
cv::VideoWriter writer;
cv::Size current_movie_size;
Expand Down

0 comments on commit ad0d63b

Please sign in to comment.