RoboJackets / software-training-old

RoboJackets Software Training
MIT License
151 stars 189 forks source link

Updates to Project 2 #214

Closed barulicm closed 1 year ago

barulicm commented 2 years ago

Note: This was tested with the changes in https://github.com/RoboJackets/stsl/pull/30

barulicm commented 2 years ago

@matthewhannay567 That looks like you're detecting blue instead of red. Are you sure you used BGR2HSV and not RGB2HSV?

matthewhannay567 commented 2 years ago

capture @barulicm This is my FindColors implementation. Also I'm confused by the fact that the instructions say to use brackets with cv::Scalar, is that actually needed?

barulicm commented 2 years ago

Ah ok, I see what's happening now.

The results you're seeing actually highlight most of the world around you as obstacles, and you're only seeing the blue tags as free space. This is because you're only comparing the hue (the first channel) and ignoring the other two channels (saturation and value). The color comparison if statement is meant to check all three channels (as shown in the reference solution):

if (input_color[0] >= range_min[0] && input_color[0] <= range_max[0] &&
  input_color[1] >= range_min[1] && input_color[1] <= range_max[1] &&
  input_color[2] >= range_min[2] && input_color[2] <= range_max[2])
{
  output.at<uint8_t>(r, c) = 255;
} else {
  output.at<uint8_t>(r, c) = 0;
}

The brackets (assuming you're talking about the [0] part) are required because the OpenCV types used here don't have comparison operators defined on them. We can't just write input_color > range_min because that operator doesn't actually exist. So, instead, we grab each element from the Scalars and compare them individually.

Let me know if you have any ideas on how to make that section of the instructions more clear.