File size: 2,345 Bytes
8a09486
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "613aff1a",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Saved visualized image\n"
     ]
    }
   ],
   "source": [
    "import cv2\n",
    "import matplotlib.pyplot as plt\n",
    "\n",
    "def visualize_bbox(img_path, solution):\n",
    "    \"\"\"\n",
    "    img_path: 图片路径\n",
    "    solution: [x1, y1, x2, y2],bounding box 坐标\n",
    "    \"\"\"\n",
    "    # 读取图片\n",
    "    img = cv2.imread(img_path)\n",
    "    if img is None:\n",
    "        raise FileNotFoundError(f\"Image not found: {img_path}\")\n",
    "\n",
    "    # 转为RGB显示\n",
    "    img_rgb = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)\n",
    "\n",
    "    # 画框\n",
    "    x1, y1, x2, y2 = solution\n",
    "    img_rgb = cv2.rectangle(img_rgb, (x1, y1), (x2, y2), color=(255,0,0), thickness=3)\n",
    "\n",
    "    # 显示\n",
    "    # plt.figure(figsize=(10, 8))\n",
    "    # plt.imshow(img_rgb)\n",
    "    # plt.title(\"Bounding Box Visualization\")\n",
    "    # plt.axis('off')\n",
    "    # plt.show()\n",
    "    cv2.imwrite('.debug.png', img_rgb)\n",
    "    print(f\"Saved visualized image\")\n",
    "    \n",
    "if __name__ == \"__main__\":\n",
    "    \n",
    "    data_dict = {\"solution\": [\n",
    "            168,\n",
    "            179,\n",
    "            189,\n",
    "            237\n",
    "        ],\n",
    "        \"img_path\": \"/root/private_data/data/MeViS/train/JPEGImages/fb82725ec988/00007.jpg\",\n",
    "    }\n",
    "    solution = data_dict['solution']\n",
    "    img_path = data_dict['img_path']\n",
    "    visualize_bbox(img_path, solution)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "6cb68496",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "video-r1",
   "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.11.13"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}