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

Marshall Vielmetti Starter Project PR #1

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

MarshallVielmetti
Copy link
Collaborator

No description provided.

@MarshallVielmetti MarshallVielmetti changed the title Mvielmet Marshall Vielmetti Starter Project PR Oct 3, 2023
Copy link

@qhdwight qhdwight left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

initial perception review

@@ -0,0 +1,156 @@
#include "tag_detector.hpp"

namespace mrover {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you may want to make a commit to remove src/perception/tag_detector from this branch

@@ -45,6 +49,9 @@ namespace mrover {
std::vector<StarterProjectTag> mTags;
ros::Publisher mTagPublisher;

size_t image_width;
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would instead modify selectTag to take in a cv::Mat instead of keeping track of global state

ret.first = center_x;
ret.second = center_y;

return ret;
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just do return {center_x, center_y}

// TODO: implement me!
return {};
float center_x = float(tagCorners[0].x + tagCorners[1].x) / float(2.0);
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can use cv::Point2f from OpenCV which implements element-wise operations. It saves you from defining multiple variables and repetition.

// TODO: implement me!
return {};
float center_x = float(tagCorners[0].x + tagCorners[1].x) / float(2.0);
float center_y = float(tagCorners[0].y + tagCorners[3].y) / float(2.0);
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Prefer static_cast<float>(...) instead of float(...)


for (int i = 1; i < tags.size(); i++) {
if ((tags[i].xTagCenterPixel*tags[i].xTagCenterPixel + tags[i].yTagCenterPixel*tags[i].yTagCenterPixel) < best_dist) {
best_dist = tags[i].xTagCenterPixel*tags[i].xTagCenterPixel + tags[i].yTagCenterPixel*tags[i].yTagCenterPixel;
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you also reuse it here, so may as well name it

// }

StarterProjectTag Perception::selectTag(std::vector<StarterProjectTag> const& tags) const { // NOLINT(*-convert-member-functions-to-static)
if (tags.empty())
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good

StarterProjectTag best = tags[0];
double best_dist = best.xTagCenterPixel*best.xTagCenterPixel + best.yTagCenterPixel*best.yTagCenterPixel;

for (int i = 1; i < tags.size(); i++) {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider using https://en.cppreference.com/w/cpp/algorithm/ranges/min_element with a projection function

Also tags.size() returns a size_t so int i is narrowing


float corner_area = abs((tagCorners[1].x - tagCorners[0].x) * (tagCorners[0].y - tagCorners[3].y));

return 1 - float((1.0*corner_area) / (1.0*total_area));
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull out float((1.0*corner_area) / (1.0*total_area)); as a variable for readability


cv::aruco::detectMarkers(image, mTagDictionary, mTagCorners, mTagIds, mTagDetectorParams);

std::vector<float> closeness_metrics;
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think these collections are redundant. You have everything you need in mTagCorners and mTagIds right. The following two for loops could just be one

@qhdwight
Copy link

qhdwight commented Oct 7, 2023

also fyi you can run ./style.sh and ./lint.sh in the starter project folder to see why CI is failing

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants