Best Way to Detect Contours Consistently? [closed]
Hi all, this is my first time in the forum.
I've been working a project to detect the contours of an object from a live video feed. My goal is to implement this in a robot so it's able to follow the object around based on the contour's position in the screen. For testing purposes, I've been working in a dark room with a bright yellow notepad, as I assumed the contrast between the notepad and the dark background would be the best environment for contour finding.
My results have proved otherwise. It does detect contours, but whenever I move the object around or there's a slight change in lighting, the contour will no longer be detected consistently. Rather, it detects other small individual contours all over the screen. I tried in an environment with good even white lighting, but the same problem occurs.
I believe this happens because the threshold boundaries are too specific. I would change the range to be something more broad, but then the object I'm trying to track is no longer properly isolated.
So my question is this: What is a way to properly filter a video feed and isolate an object so it will be detected consistently, rather than having shoddy detection whenever something small is changed? I'm using inRange() to control the range of acceptable HSV values, then finding the contours of the binary image that is created.
Any help would be appreciated! Below is the function of my code that detects the contours.
void detectContours()
{
vector<vector<Point>> contours;
vector<Vec4i> hierarchy;
Canny(morphedFrame, cannyFrame, 200, 255, 3, false);
findContours(cannyFrame, contours, hierarchy, RETR_EXTERNAL, CHAIN_APPROX_NONE);
drawContours(normalFrame, contours, 0, color, 3, LINE_AA, hierarchy, 0, Point());
}