{ "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 }