{ "cells": [ { "cell_type": "code", "execution_count": null, "id": "c133eb2c", "metadata": {}, "outputs": [], "source": [ "name_to_id = {\n", " \"NA\": 'NA',\n", " \"Bullseye\": 10,\n", " \"One\": 11,\n", " \"Two\": 12,\n", " \"Three\": 13,\n", " \"Four\": 14,\n", " \"Five\": 15,\n", " \"Six\": 16,\n", " \"Seven\": 17,\n", " \"Eight\": 18,\n", " \"Nine\": 19,\n", " \"A\": 20,\n", " \"B\": 21,\n", " \"C\": 22,\n", " \"D\": 23,\n", " \"E\": 24,\n", " \"F\": 25,\n", " \"G\": 26,\n", " \"H\": 27,\n", " \"S\": 28,\n", " \"T\": 29,\n", " \"U\": 30,\n", " \"V\": 31,\n", " \"W\": 32,\n", " \"X\": 33,\n", " \"Y\": 34,\n", " \"Z\": 35,\n", " \"Up\": 36,\n", " \"Down\": 37,\n", " \"Right\": 38,\n", " \"Left\": 39,\n", " \"Up Arrow\": 36,\n", " \"Down Arrow\": 37,\n", " \"Right Arrow\": 38,\n", " \"Left Arrow\": 39,\n", " \"Stop\": 40\n", "}" ] }, { "cell_type": "code", "execution_count": null, "id": "a89ceef6", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "优先近距离物体:\n", "200\n", "{'detection': {'annotated_image_path': 'results/annotated_image_Up-36_1757948296.jpg', 'bbox_coordinates': {'x1': 545.3320312499999, 'x2': 560.7070312499999, 'y1': 15.254882812499998, 'y2': 33.75292968749999}, 'confidence': 0.01422882080078125, 'label': 'Up', 'original_image_path': 'results\\\\3483d55f-887a-4364-8d0b-6910faa6a585_36.png'}, 'image_id': '36', 'obstacle_id': 'unknown'}\n" ] } ], "source": [ "# 选项1: 优先检测较近的物体(默认行为,面积较大的物体)\n", "import requests\n", "\n", "SERVER_URL = \"http://localhost:5000\"\n", "image_file = \"Screenshot 2025-09-15 225930.png\"\n", "\n", "with open(image_file, 'rb') as f:\n", " files = {'file': f}\n", " data = {'prefer_close_objects': 'true'} # 优先近距离物体\n", " response = requests.post(f\"{SERVER_URL}/image\", files=files, data=data)\n", "\n", "print(\"优先近距离物体:\")\n", "print(response.status_code)\n", "print(response.json())" ] }, { "cell_type": "code", "execution_count": 16, "id": "21f15172", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "优先远距离物体:\n", "200\n", "{'detection': {'annotated_image_path': 'results/annotated_image_Up-36_1757948327.jpg', 'bbox_coordinates': {'x1': 545.3320312499999, 'x2': 560.7070312499999, 'y1': 15.254882812499998, 'y2': 33.75292968749999}, 'confidence': 0.01422882080078125, 'label': 'Up', 'original_image_path': 'results\\\\e7dcd5cf-db24-4821-9fe6-5e16412ba51c_36.png'}, 'image_id': '36', 'obstacle_id': 'unknown'}\n" ] } ], "source": [ "# 选项2: 优先检测较远的物体(面积较小的物体)\n", "import requests\n", "\n", "SERVER_URL = \"http://localhost:5000\"\n", "image_file = \"b.png\"\n", "\n", "with open(image_file, 'rb') as f:\n", " files = {'file': f}\n", " data = {'prefer_close_objects': 'false'} # 优先远距离物体\n", " response = requests.post(f\"{SERVER_URL}/image\", files=files, data=data)\n", "\n", "print(\"优先远距离物体:\")\n", "print(response.status_code)\n", "print(response.json())" ] }, { "cell_type": "code", "execution_count": 15, "id": "6b29a73a", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "默认行为(优先近距离物体):\n", "200\n", "{'detection': {'annotated_image_path': 'results/annotated_image_Up-36_1757948317.jpg', 'bbox_coordinates': {'x1': 545.3320312499999, 'x2': 560.7070312499999, 'y1': 15.254882812499998, 'y2': 33.75292968749999}, 'confidence': 0.01422882080078125, 'label': 'Up', 'original_image_path': 'results\\\\d0387124-696d-4233-90db-fe511ed62828_36.png'}, 'image_id': '36', 'obstacle_id': 'unknown'}\n" ] } ], "source": [ "# 选项3: 不指定参数(使用默认行为,等同于 prefer_close_objects=true)\n", "import requests\n", "\n", "SERVER_URL = \"http://localhost:5000\"\n", "image_file = \"b.png\"\n", "\n", "with open(image_file, 'rb') as f:\n", " files = {'file': f}\n", " # 不添加 data 参数,使用默认行为(优先近距离物体)\n", " response = requests.post(f\"{SERVER_URL}/image\", files=files)\n", "\n", "print(\"默认行为(优先近距离物体):\")\n", "print(response.status_code)\n", "print(response.json())" ] } ], "metadata": { "kernelspec": { "display_name": "chatbot", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.8.16" } }, "nbformat": 4, "nbformat_minor": 5 }