{"id":26053311,"url":"https://github.com/mohamedsamirx/yolo_obb_cpp","last_synced_at":"2026-07-03T14:02:46.189Z","repository":{"id":280725429,"uuid":"942960270","full_name":"mohamedsamirx/YOLO_OBB_CPP","owner":"mohamedsamirx","description":"YOLO V8 and V11 Inference Using CPP and ONNX Runtime ","archived":false,"fork":false,"pushed_at":"2025-03-05T01:52:49.000Z","size":19,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-03-05T02:33:15.724Z","etag":null,"topics":["cpp","obb","object-detection","onnx","ultralytics","yolo","yolov11","yolov8"],"latest_commit_sha":null,"homepage":"","language":"C++","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"agpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/mohamedsamirx.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2025-03-05T00:38:31.000Z","updated_at":"2025-03-05T01:54:14.000Z","dependencies_parsed_at":"2025-03-05T02:33:18.473Z","dependency_job_id":null,"html_url":"https://github.com/mohamedsamirx/YOLO_OBB_CPP","commit_stats":null,"previous_names":["mohamedsamirx/yolo-obb-cpp","mohamedsamirx/yolo_obb_cpp"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mohamedsamirx%2FYOLO_OBB_CPP","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mohamedsamirx%2FYOLO_OBB_CPP/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mohamedsamirx%2FYOLO_OBB_CPP/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mohamedsamirx%2FYOLO_OBB_CPP/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mohamedsamirx","download_url":"https://codeload.github.com/mohamedsamirx/YOLO_OBB_CPP/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":242515390,"owners_count":20142007,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["cpp","obb","object-detection","onnx","ultralytics","yolo","yolov11","yolov8"],"created_at":"2025-03-08T07:27:55.042Z","updated_at":"2026-07-03T14:02:46.144Z","avatar_url":"https://github.com/mohamedsamirx.png","language":"C++","funding_links":[],"categories":[],"sub_categories":[],"readme":"# YOLO V8, V11 Oriented Bounding Boxes (OBB) Format ONNX CPP\n\n![License: AGPL v3](https://img.shields.io/badge/License-AGPL%20v3-blue.svg)\n![C++](https://img.shields.io/badge/language-C++-blue.svg)\n![ONNX Runtime](https://img.shields.io/badge/ONNX_Runtime-v1.19.2-brightgreen.svg)\n![OpenCV](https://img.shields.io/badge/OpenCV-4.5.5-brightgreen.svg)\n![CMake](https://img.shields.io/badge/CMake-3.22.1-blue.svg)\n\n## Overview  \nThis project is a single C++ header high-performance application designed for real-time object detection using the YOLOv8 and YOLOv11 models in Oriented Bounding Box (OBB) format. Leveraging the power of [ONNX Runtime](https://github.com/microsoft/onnxruntime) and [OpenCV](https://opencv.org/), it provides seamless integration with YOLOv8 and YOLOv11 implementations for image, video, and live camera inference. Whether you're developing for research, production, or hobbyist projects, this application offers flexibility and efficiency while supporting accurate oriented object detection.\n\n\n\n\n## Output\n\n\u003cdiv align=\"center\"\u003e\n  \u003cimg src=\"data/OBB_test_1_output.jpg\" alt=\"Image Output\" width=\"500\"\u003e\n  \n  \u003cimg src=\"data/OBB_test_2_output.jpg\" alt=\"Image Output\" width=\"500\"\u003e\n\u003c/div\u003e\n\n\n\n\n### Integration in your c++ projects\n\n## Detection Example\n\n```cpp\n\n// Include necessary headers\n#include \u003copencv2/opencv.hpp\u003e\n#include \u003ciostream\u003e\n#include \u003cstring\u003e\n#include \"YOLO11-OBB.hpp\" \n\nint main(){\n\n    // Configuration parameters\n    const std::string labelsPath = \"../models/Dota.names\";       // Path to class labels\n    const std::string modelPath  = \"../models/yolo11n-obb.onnx\";     // Path to YOLO model\n    const std::string imagePath  = \"../data/OBB_test_1_output.jpg\";           // Path to input image\n    bool isGPU = true;                                           // Set to false for CPU processing\n\n    // Initialize the detector\n    YOLO11OBBDetector detector(modelPath, labelsPath, isGPU);\n\n    // Load an image\n    cv::Mat image = cv::imread(imagePath);\n\n    // Perform object detection to get bboxs\n    std::vector\u003cDetection\u003e detections = detector.detect(image);\n\n    // Draw bounding boxes on the image\n    detector.drawBoundingBoxMask(image, detections);\n\n    // Display the annotated image\n    cv::imshow(\"OBB Detections\", image);\n    cv::waitKey(0); // Wait indefinitely until a key is pressed\n\n    return 0;\n}\n\n\n```\n\n\u003e **Note:** For more usage, check the source files: [camera_inference.cpp](src/camera_inference.cpp), [image_inference.cpp](src/image_inference.cpp), [video_inference.cpp](src/video_inference.cpp).\n\n## Features\n\n- **ONNX Runtime Integration**: Leverages ONNX Runtime for optimized inference on both CPU and GPU, ensuring high performance.\n  - **Dynamic Shapes Handling**: Adapts automatically to varying input sizes for improved versatility.\n  - **Graph Optimization**: Enhances performance using model optimization with `ORT_ENABLE_ALL`.\n  - **Execution Providers**: Configures sessions for CPU or GPU (e.g., `CUDAExecutionProvider` for GPU support).\n  - **Input/Output Shape Management**: Manages dynamic input tensor shapes per model specifications.\n  - **Optimized Memory Allocation**: Utilizes `Ort::MemoryInfo` for efficient memory management during tensor creation.\n  - **Batch Processing**: Supports processing multiple images, currently focused on single-image input.\n  - **Output Tensor Extraction**: Extracts output tensors dynamically for flexible result handling.\n\n- **OpenCV Integration**: Uses OpenCV for image processing and rendering bounding boxes and labels.\n\n- **Real-Time Inference**: Capable of processing images, videos, and live camera feeds instantly.\n\n- **Easy-to-Use Scripts**: Includes shell scripts for straightforward building and running of different inference modes.\n\n\n\n## Requirements\n\nBefore building the project, ensure that the following dependencies are installed on your system:\n\n- **C++ Compiler**: Compatible with C++14 standard (e.g., `g++`, `clang++`, or MSVC).\n- **CMake**: Version 3.0.0 or higher.\n- **OpenCV**: Version 4.5.5 or higher.\n- **ONNX Runtime**: Tested with version 1.16.3 and 1.19.2, backward compatibility [Installed and linked automatically during the build].\n\n## Installation\n\n### Clone Repository\n\nFirst, clone the repository to your local machine:\n\n```bash \ngit clone https://github.com/mohamedsamirx/YOLO_OBB_CPP.git\ncd YOLO_OBB_CPP\n```\n\n\n### Configure\n\n1. make sure you have opencv c++ installed\n2. set the ONNX Runtime version you need e.g. ONNXRUNTIME_VERSION=\"1.16.3\" in [build.sh](build.sh) to download ONNX Runtime headers also set GPU.\n\n4. Optional: control the debugging and timing using [Config.hpp](tools/Config.hpp)\n\n\n\n### Build the Project\n\nExecute the build script to compile the project using CMake:\n\n```bash\n./build.sh\n```\n\nThis script will download onnxruntime headers, create a build directory, configure the project, and compile the source code. Upon successful completion, the executable files (camera_inference, image_inference, video_inference) will be available in the build directory.\n\n### Usage\n\nAfter building the project, you can perform object detection on images, videos, or live camera feeds using the provided shell scripts.\n\n#### Run Image Inference\n\nTo perform object detection on a single image:\n\n```bash\n./run_image.sh \n```\n\nThis command will process The image and display the output image with detected bounding boxes and labels.\n\n#### Run Video Inference\n\nTo perform object detection on a video file:\n\n```bash\n./run_video.sh \n```\n\n#### Run Camera Inference\n\nTo perform real-time object detection using a usb cam:\n\n```bash\n./run_camera.sh \n```\n\nThis command will activate your usb and display the video feed with real-time object detection.\n\n\n**Class Names:**\n- Dota.names: Contains the list of class labels used by the models.\n\n### License\nThis project is licensed under the GNU Affero General Public License v3.0 (AGPL-3.0). See the [LICENSE](LICENSE) file for details.\n\n### Acknowledgment\n\n- [https://github.com/Geekgineer/YOLOs-CPP/tree/main](https://github.com/Geekgineer/YOLOs-CPP/tree/main)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmohamedsamirx%2Fyolo_obb_cpp","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmohamedsamirx%2Fyolo_obb_cpp","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmohamedsamirx%2Fyolo_obb_cpp/lists"}