Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

only inferring a single image frame once for a huge performance boost… #301

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 43 additions & 19 deletions darknet_ros/src/YoloObjectDetector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -484,29 +484,53 @@ void YoloObjectDetector::yolo() {
}

demoTime_ = what_time_is_it_now();

while (!demoDone_) {
// TODO: see issue of bounding boxes calculated multiple times per image: https://github.com/leggedrobotics/darknet_ros/issues/150
// Fix0: keep track of what std_msgs::Header id this is (consecutively increasing)
int prevSeq_ = 0;
while (!demoDone_)
{
buffIndex_ = (buffIndex_ + 1) % 3;
fetch_thread = std::thread(&YoloObjectDetector::fetchInThread, this);
detect_thread = std::thread(&YoloObjectDetector::detectInThread, this);
if (!demoPrefix_) {
fps_ = 1. / (what_time_is_it_now() - demoTime_);
demoTime_ = what_time_is_it_now();
if (viewImage_) {
displayInThread(0);
} else {
generate_image(buff_[(buffIndex_ + 1) % 3], ipl_);

// Fix1: check this isn't an image already seen
if (prevSeq_ != headerBuff_[buffIndex_].seq)
{
// Fix2: only detect if this is an image we haven't see before
detect_thread = std::thread(&YoloObjectDetector::detectInThread, this);

if (!demoPrefix_)
{
fps_ = 1. / (what_time_is_it_now() - demoTime_);
demoTime_ = what_time_is_it_now();
if (viewImage_)
{
displayInThread(0);
}
else
{
generate_image(buff_[(buffIndex_ + 1) % 3], ipl_);
}
publishInThread();
}
publishInThread();
} else {
char name[256];
sprintf(name, "%s_%08d", demoPrefix_, count);
save_image(buff_[(buffIndex_ + 1) % 3], name);
else
{
char name[256];
sprintf(name, "%s_%08d", demoPrefix_, count);
save_image(buff_[(buffIndex_ + 1) % 3], name);
}
// Fix3: increment the new sequence number to avoid detecting more than once
prevSeq_ = headerBuff_[buffIndex_].seq;
fetch_thread.join();
detect_thread.join();
++count;
}
fetch_thread.join();
detect_thread.join();
++count;
if (!isNodeRunning()) {
else
{
// Fix4: no detection made, so let thread execution complete so that it can be destroyed safely
fetch_thread.join();
}
if (!isNodeRunning())
{
demoDone_ = true;
}
}
Expand Down