Search for an icon on an image OpenCV

71 views Asked by At

I am new to the field of computer vision and have a challenge finding an fish icon within an image(example1, example2, example3). Specifically, I need to locate the fish icon from a game and obtain its coordinates. The icon's size changes depending on its position within the water, as well as its color when the fish is being pulled. Additionally, the effects within the game often hinder the process of searching for the icon. The main issue is that the icon frequently changes its scale. As a result, the methods I have attempted to use for searching have gotten lost or have only rarely yielded a normal result.

To begin with, I tried using Template matching, but it doesn't look good if the icon is a different size. I also tried to make an array of several sizes, but it worked very unstable and slowed down the algorithm very much.

std::vector<Mat> fishIcon;
const std::vector<double> SCALES = { 0.4, 0.5, 0.6, 0.8, 1.0, 1.2, 1.4 };

//Code for creating multiple masterstabs
for (double scale : SCALES) {
    Mat resIcon;
    resize(sourceIcon, resIcon, Size(0, 0), scale, scale);

    fishIcon.push_back(resIcon);
}

//A method for searching for an icon in an image
bool FindObject(Mat& templateForFind, Mat& screenshot, Point& maxLoc, Mat& result, bool debug, double confid) {
    matchTemplate(screenshot, templateForFind, result, TM_CCOEFF_NORMED);
    double minVal, maxVal;
    minMaxLoc(result, &minVal, &maxVal, NULL, &maxLoc);

    if (debug) {
        std::cout << maxVal << std::endl;
    }

    if (maxVal >= confid) {
        return true;
    }
    else {
        return false;
    }
}

//Going through all the scales until you find the right one
for (Mat ic : fishIcon) {
    if (FindObject(ic, screenshotGray, max_loc, result, true, 0.8)) {
        fishIconPosition = Point(max_loc.x, max_loc.y);
        found = true;
        break;
    }
}

And I tried the basic search method using ORB and histogram, which were shown on the OpenCV website, but they did not show good results either.

Therefore, I want to find out if there are no simpler and better methods? I will be grateful for any hint

0

There are 0 answers