RocoM-Scrcpy-Ocr is an automated collection tool for the Roco Kingdom mobile game's traveling merchant, built on scrcpy, OpenCV, YOLOv8, and AI. It uses ADB to control an Android device, handles in-game navigation clicks, captures shop screenshots, extracts item information with AI, and stores the results in SQLite. It also exposes an HTTP API for external calls.

What it can do

  • Automated navigation: YOLO object detection, OpenCV template matching, and OCR work together to handle the full click flow from opening the menu to entering the shop.
  • Quick mode: after the escape check and returning to the game, it directly looks for rocom_merchant_dialog with YOLO. If it finds the dialog, it skips the intermediate navigation steps.
  • AI recognition: screenshots are sent to a large model to extract the item name, price, and remaining time.
  • Time-slot alignment: the screenshot filename timestamp plus the remaining time are used to infer end_time, which is aligned to the exact 4-hour boundary.
  • SQLite storage: collected data is stored persistently, with support for querying historical items by date or time slot, plus occurrence statistics.
  • HTTP API: provides both real-time data and historical query interfaces.
  • Scheduled collection: runs automatically every day at 08:00, 12:00, 16:00, and 20:00.
  • Screenshot retries: if a screenshot fails, it retries up to 5 times with a 1-second interval.
  • Business-hour checks: from 00:00 to 08:00 it returns 403 for the closed state; when a time slot switches and new data is not ready yet, it returns 403 running.
  • Email alerts: sends mail after 5 failed retries, and also alerts when OCR detects keywords such as “restart” or “update”.

Regular merchant periods

<table> <thead> <tr> <th>Period</th> <th>Time range</th> </tr> </thead> <tbody> <tr> <td>Morning</td> <td>08:00 - 12:00</td> </tr> <tr> <td>Afternoon 1</td> <td>12:00 - 16:00</td> </tr> <tr> <td>Afternoon 2</td> <td>16:00 - 20:00</td> </tr> <tr> <td>Evening</td> <td>20:00 - 24:00</td> </tr> </tbody> </table>

HTTP API

<table> <thead> <tr> <th>Method</th> <th>Path</th> <th>Description</th> </tr> </thead> <tbody> <tr> <td>GET</td> <td>/api/shop</td> <td>Latest collection result</td> </tr> <tr> <td>GET</td> <td>/api/goods?date=2026-06-01&period=16:00-20:00</td> <td>Query historical items (if date is omitted, today is used by default)</td> </tr> <tr> <td>GET</td> <td>/api/goods/records</td> <td>Query item occurrence statistics</td> </tr> <tr> <td>GET</td> <td>/health</td> <td>Health check</td> </tr> </tbody> </table>

Response examples

GET /api/shop

200 - success (data ready)

{
  "status": "success",
  "timestamp": "2026-06-01 16:03",
  "count": 8,
  "data": [
    {
      "name": "火系血脉秘药",
      "price": "500",
      "currency": "洛克贝",
      "limit": "3",
      "end_time": "2026-06-01 20:00"
    }
  ]
}

403 - closed (00:00-08:00)

{
  "status": "closed",
  "message": "当前未到远行商人营业时间",
  "timestamp": "2026-06-01 03:00:00",
  "data": []
}

403 - running (slot switched, new data not ready)

{
  "status": "running",
  "message": "前置引擎运行中,请稍后",
  "timestamp": "2026-06-01 12:01:00",
  "data": []
}

Current status

This is still a test version and is not recommended for production use. It will continue to be improved and iterated based on feedback and practical needs, with the goal of better stability and completeness.

The current dataset is still limited, and more data is being collected to improve model training.

For better stability, it is recommended to use this API together with data collection from the HaoYou KuaiBao page.

  • [ ] Improve the training dataset
  • [ ] Optimize the processing pipeline
  • [ ] Add automatic game updates