Spaces:
Sleeping
Sleeping
File size: 5,360 Bytes
ea770b5 0ec72e8 ea770b5 0ec72e8 ea770b5 0ec72e8 ea770b5 0ec72e8 ea770b5 0ec72e8 ea770b5 0ec72e8 ea770b5 0ec72e8 ea770b5 0ec72e8 ea770b5 0ec72e8 ea770b5 0ec72e8 ea770b5 0ec72e8 ea770b5 0ec72e8 ea770b5 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 |
{
"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
}
|