Issues Finding Elements with Computer Vision (find Method)

Issues Finding Elements with Computer Vision (find Method)

Description

In some cases, users report difficulty locating screen elements using the find method, which is based on computer vision (CV).
This issue can arise due to various factors, such as screen resolution, system theme, visual obstructions, or even timing.
Below is a step-by-step guide to help diagnose and resolve this problem.

To investigate why the find method is not detecting the target element, follow these diagnostic steps:

Diagnostic Steps

  1. Save a screenshot before calling find:

    bot.save_screenshot("debug_find.png")
  2. Save a screenshot immediately after find, before performing any other action:

    bot.save_screenshot("debug_after_find.png")
  3. Request the image crop of the element (the “needle”) the user is trying to detect.
    Save it as needle.jpg or a similar name.

  4. Rename the pre-find screenshot as haystack.png.

  5. Run the following test script to check if the image can be detected and adjust the confidence level as needed:

    from botcity.core.cv2find import locate_all_opencv elements = list(locate_all_opencv("needle.jpg", "haystack.png", confidence=0.97)) print(elements)

What to Look For

Based on the screenshots and script results, you can assess several possibilities:

  • Insufficient wait time: The element might not be on screen yet. Try increasing the waiting_time parameter.

  • Screenshot blocking: Some systems (e.g., banking software) prevent screen captures, which can disrupt CV operations.

  • Overlapping elements: Another visual component may be covering the target element.

  • Different screen resolution: The image crop may have been created on a different display setup.

  • Theme mismatch: The element may appear differently depending on the OS theme (dark vs light mode).


Conclusion

Using screenshot comparisons and image matching is an effective way to diagnose why the find method might not be working.
This process reveals issues related to visibility, capture restrictions, UI changes, or user error when preparing the element crop.

For more technical references, visit the official BotCity documentation.