Last active
January 23, 2020 05:55
-
-
Save roman-smirnov/c01630d2e717c0aa07deb70c2168f522 to your computer and use it in GitHub Desktop.
visualize matching bounding boxes in matchBoundingBoxes()
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void matchBoundingBoxes(std::vector<cv::DMatch> &matches, | |
std::map<int, int> &bbBestMatches, | |
DataFrame &prev_frame, | |
DataFrame &curr_frame) { | |
/* TODO: for each bbox in current frame, find the best matching bbox in previous frame */ | |
/* ... */ | |
/* Now visualize bounding box matches */ | |
// copy the previous frame and current frame | |
cv::Mat prv_img = prev_frame.cameraImg.clone(); | |
cv::Mat cur_img = curr_frame.cameraImg.clone(); | |
const auto red = cv::Scalar(0, 0, 255); | |
const auto green = cv::Scalar(0, 255, 0); | |
const auto blue = cv::Scalar(255, 0, 0); | |
cv::putText(prv_img, "Previous Frame", cv::Point(50, 50), cv::FONT_ITALIC, 1, red, 2); | |
cv::putText(cur_img, "Current Frame", cv::Point(50, 50), cv::FONT_ITALIC, 1, blue, 2); | |
for (auto const &kv : bbBestMatches) { | |
auto label = std::to_string(kv.second); | |
auto prv_rect = prev_frame.boundingBoxes[kv.first].roi; | |
cv::rectangle(prv_img, cv::Point(prv_rect.x, prv_rect.y), cv::Point(prv_rect.x + prv_rect.width, prv_rect.y + prv_rect.height), red, 2); | |
cv::putText(prv_img, label, cv::Point(prv_rect.x+prv_rect.width/2, prv_rect.y+prv_rect.height/2), cv::FONT_ITALIC, 1, red, 2); | |
auto cur_rect = curr_frame.boundingBoxes[kv.second].roi; | |
cv::rectangle(cur_img,cv::Point(cur_rect.x, cur_rect.y),cv::Point(cur_rect.x + cur_rect.width, cur_rect.y + cur_rect.height),blue,2); | |
cv::putText(cur_img, label, cv::Point(cur_rect.x+cur_rect.width/2, cur_rect.y+cur_rect.height/2), cv::FONT_ITALIC, 1, blue, 2); | |
} | |
cv::Mat concat_img; | |
cv::vconcat(prv_img, cur_img, concat_img); | |
string windowName = "Matching Bounding Boxes"; | |
cv::namedWindow(windowName, cv::WINDOW_AUTOSIZE); | |
cv::imshow(windowName, concat_img); | |
cv::waitKey(0); // wait for key to be pressed | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void matchBoundingBoxes(std::vector<cv::DMatch> &matches, | |
std::map<int, int> &bbBestMatches, | |
DataFrame &prev_frame, | |
DataFrame &curr_frame) { | |
/* TODO: for each bbox in current frame, find the best matching bbox in previous frame */ | |
/* ... */ | |
/* Now visualize bounding box matches */ | |
// copy the previous frame and current frame | |
cv::Mat prv_img = prev_frame.cameraImg.clone(); | |
cv::Mat cur_img = curr_frame.cameraImg.clone(); | |
const auto red = cv::Scalar(0, 0, 255); | |
const auto green = cv::Scalar(0, 255, 0); | |
const auto blue = cv::Scalar(255, 0, 0); | |
cv::putText(prv_img, "Previous Frame", cv::Point(50, 50), cv::FONT_ITALIC, 0.75, red, 2); | |
cv::putText(cur_img, "Current Frame", cv::Point(50, 50), cv::FONT_ITALIC, 0.75, blue, 2); | |
std::vector<std::pair<cv::Point2i,cv::Point2i>> lines; | |
for (auto const &kv : bbBestMatches) { | |
std::cout << "BBOX MATCH IDS: " << std::to_string(kv.first) + " -> " + std::to_string(kv.second) << std::endl; | |
auto prv_rect = prev_frame.boundingBoxes[kv.first].roi; | |
cv::rectangle(prv_img, cv::Point(prv_rect.x, prv_rect.y), cv::Point(prv_rect.x + prv_rect.width, prv_rect.y + prv_rect.height), red, 1); | |
auto cur_rect = curr_frame.boundingBoxes[kv.second].roi; | |
cv::rectangle(cur_img,cv::Point(cur_rect.x, cur_rect.y),cv::Point(cur_rect.x + cur_rect.width, cur_rect.y + cur_rect.height),blue,1); | |
lines.emplace_back(cv::Point(prv_rect.x, prv_rect.y), cv::Point(cur_rect.x, cur_rect.y+prv_img.size().height) ); | |
} | |
cv::Mat concat_img; | |
cv::vconcat(prv_img, cur_img, concat_img); | |
for(auto &end_pts : lines ){ | |
cv::line(concat_img, end_pts.first, end_pts.second, green, 1); | |
} | |
string windowName = "Matching Bounding Boxes"; | |
cv::namedWindow(windowName, cv::WINDOW_AUTOSIZE); | |
cv::imshow(windowName, concat_img); | |
cv::waitKey(0); // wait for key to be pressed | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment