Avatar ·

Improving the algorithm for recognizing a Coca-Cola can in an image

Greetings, colleagues. I am writing a program for recognizing a Coca-Cola can in photos using OpenCV in C++. The idea is simple: the can is red, cylindrical, with a white stripe. I use color filtering (HSV) to highlight red areas, then find contours and approximate them with ellipses. It seems logical, but there is a big problem: the algorithm is terribly glitchy on real images. Here is my current code: ```cpp cv::Mat hsv, mask; cv::cvtColor(img, hsv, cv::COLOR_BGR2HSV); cv::inRange(hsv, cv::Scalar(0, 100, 100), cv::Scalar(10, 255, 255), mask); // Also adding the lower red boundary (from 160 to 180) cv::Mat mask2; cv::inRange(hsv, cv::Scalar(160, 100, 100), cv::Scalar(180, 255, 255), mask2); mask = mask | mask2; std::vector> contours; cv::findContours