Skip to content

Commit

Permalink
Adding a static delay from first received camera image till we start …
Browse files Browse the repository at this point in the history
…processing them. This may alleviate issues caused when the software shader starts running immediately after loading it in.
  • Loading branch information
ViktorWalter committed Mar 21, 2024
1 parent 7585e34 commit 139b79d
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
2 changes: 1 addition & 1 deletion include/detect/uv_led_detect_fast_gpu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ bool uvdar::UVDARLedDetectFASTGPU::processImage(const cv::Mat i_image, std::vect
image_size = i_image.size();
/* std::cerr << "[UVDARDetectorFASTGPU]: First image, initializing..." << std::endl; */
init();
/* return false; */
return false;
}

if (mask_id >= (int)(masks_.size())) {
Expand Down
21 changes: 21 additions & 0 deletions src/detector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ class UVDARDetector : public nodelet::Nodelet{
}
//}


// Create callbacks, timers and process objects for each camera
for (unsigned int i = 0; i < _camera_count_; ++i) {
image_callback_t callback = [image_index=i,this] (const sensor_msgs::ImageConstPtr& image_msg) {
Expand All @@ -87,6 +88,9 @@ class UVDARDetector : public nodelet::Nodelet{
detected_points_.push_back(std::vector<cv::Point>());
sun_points_.push_back(std::vector<cv::Point>());

image_yet_received_.push_back(false);
initial_delay_.push_back(ros::Time::now());

/* mutex_camera_image_.push_back(std::make_unique<std::mutex>()); */

ROS_INFO("[UVDARDetector]: Initializing FAST-based marker detection...");
Expand Down Expand Up @@ -141,6 +145,7 @@ class UVDARDetector : public nodelet::Nodelet{
}



ROS_INFO("[UVDARDetector]: Waiting for time...");
ros::Time::waitForValid();

Expand Down Expand Up @@ -215,6 +220,18 @@ class UVDARDetector : public nodelet::Nodelet{
* @param image_index - index of the camera that produced this image
*/
void processSingleImage([[maybe_unused]] const ros::TimerEvent& te, const cv_bridge::CvImageConstPtr image, int image_index) {

if (!image_yet_received_[image_index]){
initial_delay_[image_index] = ros::Time::now();
image_yet_received_[image_index] = true;
}

if ((ros::Time::now() - initial_delay_[image_index]).toSec() < 2.0){
ROS_WARN_STREAM_THROTTLE(1.0, "[UVDARDetector]: Ignoring message for 2s...");
return;
}


if (!initialized_){
ROS_WARN_STREAM_THROTTLE(1.0,"[UVDARDetector]: Not yet initialized, dropping message...");
return;
Expand Down Expand Up @@ -393,6 +410,10 @@ class UVDARDetector : public nodelet::Nodelet{
std::mutex mutex_pub_;
std::vector<ros::Timer> timer_process_;

std::vector<bool> image_yet_received_;
std::vector<ros::Time> initial_delay_;


};


Expand Down

0 comments on commit 139b79d

Please sign in to comment.