You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

基于Discord Bot实现Pokémon Go图片文本提取需求问询

Building a Pokémon Go Image Parsing Discord Bot

Alright, let's walk through building this Pokémon Go image parsing Discord Bot—here's a practical, step-by-step approach that aligns exactly with your requirements:

Core Requirements Recap

First, let's clarify the key data points we need to extract from each image:

  • Universal Data:
    • Location text at the top of the image
    • Time value inside the pink/orange oval
  • Image-Specific Data:
    • For Egg images: Number of face icons below the time (representing Tier 1-5)
    • For Pokémon images: The Pokémon's name
  • You’ll provide supporting option lists (like valid Pokémon names) to boost accuracy

Implementation Steps

1. Set Up Your Dev Environment

Start by installing the tools/libraries you’ll need:

  • Discord Bot framework: Use discord.py (or py-cord/nextcord for newer features)
  • Image processing: opencv-python (for color detection, template matching) and pillow (for cropping/resizing)
  • OCR: pytesseract (make sure to install the Tesseract OCR engine on your system too)
  • Initialize your Discord Bot, grab its token from the Discord Developer Portal, and enable permissions for reading attachments and sending messages.

2. Image Handling & Preprocessing

When a user uploads an image:

  • Download the attachment to a temporary local file
  • Preprocess the image to isolate target regions (this drastically improves OCR accuracy):
    • Crop the top section for location extraction (Pokémon Go uses a consistent header layout)
    • Use color thresholding (in HSV color space) to detect the pink/orange oval, then crop that area for time extraction
    • For Egg images, crop the area below the time where face icons appear; for Pokémon images, target the name display area (usually below the Pokémon sprite)

3. Data Extraction Logic

Break down each extraction task with tailored approaches:

  • Location: Run Tesseract OCR on the cropped header area. Adjust OCR parameters (like language, page segmentation mode) to match the font used in Pokémon Go—you can even train a custom OCR model if default accuracy is low.
  • Time: After cropping the oval region, run OCR to pull the time text. Add validation to ensure it matches common formats (e.g., HH:MM, MM/DD HH:MM).
  • Egg Tier: Use template matching with pre-made face icon templates (one for the standard face) to count how many matches exist in the cropped area. Alternatively, use contour detection to count circular shapes (since the face icons are uniform circles). Cross-reference the count with your Tier list (1 face = Tier 1, etc.).
  • Pokémon Name: Run OCR on the name region, then fuzzy-match the result against your provided Pokémon name list to fix minor OCR errors (e.g., if OCR returns "Dragonit", it’ll map to "Dragonite").

4. Discord Bot Integration

  • Write a message listener that triggers when a user uploads an image (check for message.attachments).
  • Format the extracted data into a clean, user-friendly response. Example outputs:
    For an Egg image:
    📍 Location: Central Park
    ⏰ Time: 14:30
    🥚 Egg Tier: 3 (3 face icons)
    
    For a Pokémon image:
    📍 Location: Times Square
    ⏰ Time: 09:15
    🐉 Pokémon: Dragonite
    
  • Add error handling: If the image isn’t a valid Pokémon Go screenshot, or if data extraction fails, send a polite message like "Hmm, I couldn’t parse that image—make sure it’s a clear Pokémon Go screenshot!"

5. Test with Your Sample Images

Use your 5 sample images to refine the code:

  • Adjust crop coordinates, color thresholds, and OCR parameters until each data point is extracted correctly
  • Tweak template matching thresholds if face counts are off
  • Fine-tune fuzzy matching logic for Pokémon names using your provided list

Pro Tips

  • Cache your face templates and Pokémon name list in memory to speed up processing
  • Add a debug mode that outputs cropped regions and OCR raw text to help troubleshoot
  • Let users adjust accuracy settings (e.g., toggle fuzzy matching) via bot commands if needed

内容的提问来源于stack exchange,提问作者birdman3131

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.26 08:29:58