Close
0%
0%

Stardew Valley Villager Gift Preferences Bot

Via OpenCV, recognize villagers to display their birthdays, loves, likes, and hates while playing Stardew Valley on LattePanda Alpha.

Similar projects worth following
In this project, I wanted to focus on an emerging field for improving our overall experience while playing and exploring video games, known as computer vision implementation in video games. We have nearly interminable options while employing computer vision to improve video games, from aim assistance bots for first-person shooter (FPS) games to mining bots for role-playing (RPG) games. Although computer vision implementation in video games is commonly utilized for competitive online games, I decided to employ computer vision in one of my favorite video games - Stardew Valley.

In Stardew Valley, even though I played it more than once already, I still needed to scrutinize guides to remember villagers' gift preferences while trying to increase my friendship with certain characters. Thus, I decided to employ computer vision to recognize villagers and display their birthdays and gift preferences (loves, likes, and hates) automatically while playing Stardew Valley.

Since I wanted this project to be as compact as possible, I chose to use a LattePanda Alpha 864s, a high-performance SBC (single-board computer), has an embedded Arduino Leonardo. To recognize villagers while exploring the Stardew Valley world, I deployed the OpenCV template matching. After detecting villagers successfully, to display their gift preferences and birthdays without interrupting the gaming experience or performance, I used the embedded Arduino Leonardo on the LattePanda Alpha. Arduino Leonardo prints the detected villager information on a 3.5" 320x480 TFT LCD Touch Screen (ILI9488) and notifies the player via a buzzer and a 5mm green LED.

Because I was usually struggling to increase my friendship with these eight characters below, I used the OpenCV template matching to recognize them:

  • Abigail
  • Emily
  • Haley
  • Maru
  • Penny
  • Alex
  • Harvey
  • Sam

After running this project and obtaining accurate results, it obviates the need for shrewd gift acumen for villagers while playing Stardew Valley. 😃 🎁

Huge thanks to DFRobot for sponsoring this project.

Sponsored products by DFRobot:

⭐ LattePanda Alpha 864s | Inspect

⭐ DFRobot 8.9" 1920x1200 IPS Touch Display | Inspect

Step 1: Recognizing villagers while playing Stardew Valley with OpenCV

I decided to employ template matching to recognize villagers in Stardew Valley while playing the game. Template Matching is a method for searching and finding the location of a template image in a larger (input) image. OpenCV provides a built-in function - cv.matchTemplate() - for deploying template matching. It basically slides the template image over the input image (as in 2D convolution) and compares the patches of the input image against the template image to find the overlapped patches. When the function finds the overlapped patches, it saves the comparison results. If the input image is of size (W x H) and the template image is of size (w x h), the output (results) image will have a size of (W - w + 1, H - h + 1). You can get more information regarding template matching from this guide.

There are several comparison methods implemented in OpenCV, and each comparison method applies a unique formula to generate results. You can inspect TemplateMatchModes to get more information regarding comparison methods, describing the formulae for the available comparison methods.

I developed an application in Python to recognize villagers in Stardew Valley and send their information (gift preferences and birthdays) to the Arduino Leonardo. As shown below, the application consists of one folder and five code files:

  • main.py
  • windowframe.py
  • vision.py
  • arduino_serial_comm.py
  • pics.py
  • /assets
  • -- templates (cropped villager poses)
  • -- villagers.json

I will elucidate each file in detail in the following steps.

To execute my application to recognize villagers successfully, I installed the required modules on Thonny. If you want, you can use a different Python IDE.

⭐ Download the opencv-python module.

pip install opencv-python

⭐ Download the pywin32 module, which provides access to Windows APIs.

pip install pywin32

Step 1.1: Deriving templates from in-game screenshots and defining villager preferences

First of all, to be able to use template matching to detect villagers in Stardew Valley, I needed to create templates for each villager (character) in my list shown above. Since there are different poses in Stardew Valley for characters, I utilized in-game screenshots to catch unique character poses - sitting, turning right, turning...

Read more »

  • 1 × LattePanda Alpha 864s
  • 1 × Arduino Leonardo (Built-in)
  • 1 × DFRobot 8.9" 1920x1200 IPS Touch Display
  • 1 × 3.5" 320x480 TFT LCD Touch Screen (ILI9488)
  • 2 × Logic Level Converter (Bi-Directional)

View all 10 components

  • 1
    Connections
  • 2
    LattePanda Alpha

View all instructions

Enjoy this project?

Share

Discussions

kutluhan_aktar wrote 11/04/2021 at 20:56 point

Please feel free to leave a comment here if you have any questions or concerns regarding this project 😃

  Are you sure? yes | no

Similar Projects

Does this project spark your interest?

Become a member to follow this project and never miss any updates