TrafficEye Largest Road User Reader
Use this skill when the user wants the largest detected vehicle from an image, along with its make and model classification and every detected license plate belonging to that same road user.
What This Skill Does
- 1. Accepts a local image path.
- Uploads the image to the TrafficEye recognition API.
- Sends a recognition request that asks for detection, OCR, and MMR with box preference by default.
- Parses the API response, including responses wrapped as
{ "status": ..., "data": ... }. - Picks the largest detected road user by
box.position area. - Returns a wrapper object containing
roadUser, box, plates, area, and source, preserving the full selected road-user payload.
Expected Input
- - A local image file path.
- If the user supplied an attachment instead of a path, first resolve it to a local file path and then run the helper.
Default Runtime Assumptions
- - The API endpoint defaults to
https://trafficeye.ai/recognition. - The default request payload is
{"tasks":["DETECTION","OCR","MMR"],"requestedDetectionTypes":["BOX","PLATE"],"mmrPreference":"BOX"}. - The default API-key transport matches the TrafficEye public API example: header mode with header name
apikey. - Auth and request fields remain configurable in case your deployment differs.
Environment Variables
- -
TRAFFICEYE_API_KEY: required unless passed explicitly to the helper. - INLINECODE11 : optional, defaults to
https://trafficeye.ai/recognition. - INLINECODE13 : one of
header, bearer, form, query. Default: header. - INLINECODE19 : key name for
header, form, or query mode. Default: apikey. - INLINECODE24 : multipart field for the image. Default:
file. - INLINECODE26 : multipart field for the JSON request. Default:
request. - INLINECODE28 : JSON string to include as the request field. By default this is
{"tasks":["DETECTION","OCR","MMR"],"requestedDetectionTypes":["BOX","PLATE"],"mmrPreference":"BOX"}. - INLINECODE30 : optional timeout in seconds. Default:
30.
Only TRAFFICEYE_API_KEY is required for the default live API flow. The other variables are optional overrides.
How To Run
Setup your API key:
CODEBLOCK0
Use the road-user helper:
CODEBLOCK1
For structured output:
CODEBLOCK2
If the deployment expects Bearer auth:
CODEBLOCK3
If the deployment needs an explicit request payload:
CODEBLOCK4
Equivalent to the documented public API example:
CODEBLOCK5
Agent Workflow
- 1. Verify that the image path exists.
- Run
python3 recognize_road_user.py <image-path> --format json. - Present the full selected road-user payload to the user, especially
box, mmr, and the complete plates array. - If the selected road user has no plates, explain that the largest vehicle was found but no plates were attached to that road user.
- If authentication fails, ask the user which auth mode their deployment expects and retry with the matching environment variables.
Offline Validation
You can validate the selection logic without calling the API:
CODEBLOCK6
Output Shape
The helper prints JSON with this top-level structure:
CODEBLOCK7
- -
roadUser is the original selected road-user payload from TrafficEye. - INLINECODE38 repeats
roadUser.box for convenience. - INLINECODE40 repeats
roadUser.plates for convenience and may be empty. - INLINECODE42 is the computed rectangle area used for winner selection.
- INLINECODE43 identifies where the selected road user came from in the API response.
Notes
- - The helper intentionally chooses the largest boxed vehicle by geometric area, not by detection confidence.
- The response parser first checks
data.combinations[].roadUsers[], then combinations[].roadUsers[], then roadUsers[], and finally nested road-user payloads discovered recursively. - The default request and auth header mirror the public example at
https://www.trafficeye.ai/api. - The selected result now includes the original road-user payload from the API so
mmr, box, all plates, and their scores are preserved.
TrafficEye 最大道路使用者读取器
当用户想要从图像中获取检测到的最大车辆及其品牌型号分类,以及属于该道路使用者的每个检测到的车牌时,使用此技能。
该技能的功能
- 1. 接受本地图像路径。
- 将图像上传到 TrafficEye 识别 API。
- 发送识别请求,默认请求检测、OCR 和 MMR,并偏好框选。
- 解析 API 响应,包括包装为 { status: ..., data: ... } 的响应。
- 通过 box.position 区域选择最大的检测到的道路使用者。
- 返回包含 roadUser、box、plates、area 和 source 的包装对象,保留完整的选定道路使用者负载。
预期输入
- - 本地图像文件路径。
- 如果用户提供了附件而不是路径,首先将其解析为本地文件路径,然后运行辅助程序。
默认运行时假设
- - API 端点默认为 https://trafficeye.ai/recognition。
- 默认请求负载为 {tasks:[DETECTION,OCR,MMR],requestedDetectionTypes:[BOX,PLATE],mmrPreference:BOX}。
- 默认 API 密钥传输方式与 TrafficEye 公共 API 示例一致:标头模式,标头名称为 apikey。
- 认证和请求字段保持可配置,以适应不同的部署环境。
环境变量
- - TRAFFICEYEAPIKEY:必需,除非显式传递给辅助程序。
- TRAFFICEYEAPIURL:可选,默认为 https://trafficeye.ai/recognition。
- TRAFFICEYEAPIKEYMODE:可选值为 header、bearer、form、query。默认值:header。
- TRAFFICEYEAPIKEYNAME:header、form 或 query 模式下的密钥名称。默认值:apikey。
- TRAFFICEYEFILEFIELD:图像的多部分字段。默认值:file。
- TRAFFICEYEREQUESTFIELD:JSON 请求的多部分字段。默认值:request。
- TRAFFICEYEREQUESTJSON:作为请求字段包含的 JSON 字符串。默认值为 {tasks:[DETECTION,OCR,MMR],requestedDetectionTypes:[BOX,PLATE],mmrPreference:BOX}。
- TRAFFICEYETIMEOUTS:可选超时时间(秒)。默认值:30。
默认实时 API 流程仅需要 TRAFFICEYEAPIKEY。其他变量为可选覆盖项。
运行方法
设置您的 API 密钥:
bash
export TRAFFICEYEAPIKEY=YOURREALKEY
使用道路使用者辅助程序:
bash
python3 recognizeroaduser.py /absolute/path/to/image.jpg
获取结构化输出:
bash
python3 recognizeroaduser.py /absolute/path/to/image.jpg --format json
如果部署环境期望 Bearer 认证:
bash
TRAFFICEYEAPIKEYMODE=bearer python3 recognizeroad_user.py /absolute/path/to/image.jpg
如果部署环境需要显式请求负载:
bash
TRAFFICEYEREQUESTJSON={tasks:[DETECTION,OCR,MMR],requestedDetectionTypes:[BOX,PLATE],mmrPreference:BOX} python3 recognizeroaduser.py /absolute/path/to/image.jpg --format json
等同于文档化的公共 API 示例:
bash
curl -X POST \
-H Content-Type: multipart/form-data \
-H apikey: YOURAPIKEY_HERE \
-F file=@image.jpg \
-F request={tasks:[DETECTION,OCR,MMR],requestedDetectionTypes:[BOX,PLATE],mmrPreference:BOX} \
https://trafficeye.ai/recognition
代理工作流程
- 1. 验证图像路径是否存在。
- 运行 python3 recognizeroaduser.py --format json。
- 向用户展示完整的选定道路使用者负载,特别是 box、mmr 和完整的 plates 数组。
- 如果选定的道路使用者没有车牌,解释已找到最大车辆但该道路使用者未关联任何车牌。
- 如果认证失败,询问用户其部署环境期望的认证模式,并使用匹配的环境变量重试。
离线验证
您可以在不调用 API 的情况下验证选择逻辑:
bash
python3 recognizeroaduser.py --response-json-file examples/sample_response.json --format json
输出结构
辅助程序打印具有以下顶层结构的 JSON:
json
{
roadUser: {box: {}, plates: [], mmr: {}},
box: {},
plates: [],
area: 0,
source: {
combinationIndex: 0,
roadUserIndex: 0,
path: combinations[0].roadUsers[0]
}
}
- - roadUser 是来自 TrafficEye 的原始选定道路使用者负载。
- box 为方便起见重复 roadUser.box。
- plates 为方便起见重复 roadUser.plates,可能为空。
- area 是用于胜者选择的计算矩形面积。
- source 标识选定的道路使用者在 API 响应中的来源。
注意事项
- - 辅助程序有意通过几何面积选择最大的框选车辆,而非检测置信度。
- 响应解析器首先检查 data.combinations[].roadUsers[],然后检查 combinations[].roadUsers[],接着检查 roadUsers[],最后递归发现嵌套的道路使用者负载。
- 默认请求和认证标头与 https://www.trafficeye.ai/api 的公共示例一致。
- 选定的结果现在包含来自 API 的原始道路使用者负载,因此 mmr、box、所有 plates 及其分数均得以保留。