{"id":24114863,"url":"https://github.com/ml13571/opencv_lite","last_synced_at":"2026-05-08T06:08:36.239Z","repository":{"id":263823533,"uuid":"891487083","full_name":"ml13571/opencv_lite","owner":"ml13571","description":"Integrated MNN into OpenCV and Use OpenCV API to run ONNX model by ONNXRuntime","archived":false,"fork":false,"pushed_at":"2024-11-20T12:55:45.000Z","size":47021,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-01-11T05:35:35.032Z","etag":null,"topics":["ai","machine-learning","open-source","opencv"],"latest_commit_sha":null,"homepage":"https://jackiewang13571.wixsite.com/jackie-wang","language":"C++","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ml13571.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":"SECURITY.md","support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-11-20T12:27:25.000Z","updated_at":"2024-11-20T12:55:48.000Z","dependencies_parsed_at":"2024-11-20T14:03:19.481Z","dependency_job_id":null,"html_url":"https://github.com/ml13571/opencv_lite","commit_stats":null,"previous_names":["jackiewangcv/opencv_lite","ml13571/opencv_lite"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ml13571%2Fopencv_lite","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ml13571%2Fopencv_lite/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ml13571%2Fopencv_lite/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ml13571%2Fopencv_lite/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ml13571","download_url":"https://codeload.github.com/ml13571/opencv_lite/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":241144126,"owners_count":19917298,"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":["ai","machine-learning","open-source","opencv"],"created_at":"2025-01-11T05:35:49.309Z","updated_at":"2026-05-08T06:08:31.219Z","avatar_url":"https://github.com/ml13571.png","language":"C++","funding_links":[],"categories":[],"sub_categories":[],"readme":"# OpenCV-lite \n\nOpenCV-lite is a lightweight version of OpenCV, tailored for DNN model deployment scenarios. The main modifications include:\n- Removing some less commonly used modules: `features2d`, `flann`, `gapi`, `ml`, `objdetect`, `stitching`, and `video`.\n- Retaining the dnn module `API` but directly utilizing `MNN`, `ONNXRuntime`, `TFLite`, and `TensorRT` for corresponding model inference.\n\n## \n\n1. The API of opencv is easy to use, but the compatibility with ONNX model is poor.  \n2. ONNXRuntime is very compatible with ONNX, but the API is hard to use and changes all the time.\n\n\u003e The compatibility with ONNX model is poor.\n\nIt's a headache, user always encounter such error:\n```angular2html\n[ERROR:0@0.357] global onnx_importer.cpp:xxxx cv::dnn::xxxx::ONNXImporter::handleNode ...\n```\nIn view of the fact that OpenCV DNN does not fully support dynamic shape input and has low coverage for ONNX. That means user may either in `readNet()`, or in `net.forward()`, always get an error.\nIt is expected that after the release of OpenCV 5.0, things will improve.\n\n**If you have a model that needs to be inferred and deployed in a C++ environment, and you encounter errors above, maybe you can try this library.**\n\nIn this project, I removed all dnn implementation codes, only kept the dnn's API. \nAnd connected to the C++ API of ONNXRuntime.\n\n### The ONNX op test coverage:\n| Project                                                             | ONNX op coverage (%)                             |\n|---------------------------------------------------------------------|--------------------------------------------------|\n| [OpenCV DNN](https://github.com/opencv/opencv/tree/4.x/modules/dnn) | 30.22%**                                         |\n| OpenCV-ORT                                                          | **91.69%***                                      |\n| [ONNXRuntime](https://github.com/microsoft/onnxruntime)     | [**92.22%**](http://onnx.ai/backend-scoreboard/) |\n\n**: Statistical methods:\n\n([All_test](https://github.com/opencv/opencv/blob/4.x/modules/dnn/test/test_onnx_conformance.cpp#L33) - [all_denylist](https://github.com/opencv/opencv/blob/4.x/modules/dnn/test/test_onnx_conformance_layer_filter_opencv_all_denylist.inl.hpp) - [parser_denylist](https://github.com/opencv/opencv/blob/4.x/modules/dnn/test/test_onnx_conformance_layer_parser_denylist.inl.hpp))/[All_test](https://github.com/opencv/opencv/blob/4.x/modules/dnn/test/test_onnx_conformance.cpp#L33)\n= (867 - 56 - 549)/867 = 30.2%\n\n*: the unsupported test case can be found [here](https://github.com/zihaomu/opencv_ort/blob/main/modules/dnn/test/test_onnx_conformance_denylist.inl.hpp).\n\n## TODO List\n1. Fix some bugs in imgproc.\n2. Add Github Action.\n3. video demo.\n4. Add ORT-CUDA support, and compatible with `net.setPreferableBackend(DNN_BACKEND_CUDA)` API.\n\n# How to install?\n\n### Step1: Download ONNXRuntime binary package and unzip.\nPlease choose it by your platform.\nhttps://github.com/microsoft/onnxruntime/releases\n\nI have tested it with ONNXRuntime version: 1.14.1, and it works well.\n\n### Step2: Set enviroment path\nThe keywork of `ORT_SDK` will be used in the OpenCV compiler.\n```bash\nexport ORT_SDK=/opt/onnxruntime-osx-arm64-1.14.1 # Fix the ORT_SDK path.\n```\n### Step3: Compile OpenCV_ORT from source code.\nThe compilation process is same from original OpenCV project.\nAnd only difference is that we need to set the one PATH:**`ORT`**, so that `cmake` can find `ONNXRuntime lib file` and `ONNXRuntime head file` correctly.\n\n```bash\ngit clone https://github.com/zihaomu/opencv_ort.git\ncd opencv_ort\nmkdir build \u0026 cd build\ncmake -D ORT_SDK=/opt/onnxruntime-osx-arm64-1.14.1 .. # Fix the ORT_SDK path.\n```\n\n# How to use it?\nThe code is the totally same as original OpenCV DNN.\n```C++\n#include \u003ciostream\u003e\n#include \u003cvector\u003e\n#include \u003copencv2/dnn.hpp\u003e\n#include \u003copencv2/imgproc.hpp\u003e\n#include \u003copencv2/highgui.hpp\u003e\n#include\u003calgorithm\u003e\n\nusing namespace std;\nusing namespace cv;\nusing namespace cv::dnn;\n\nint main()\n{\n    // load input\n    Mat image = imread(\"PATH_TO_image\");\n    Scalar meanValue(0.485, 0.456, 0.406);\n    Scalar stdValue(0.229, 0.224, 0.225);\n\n    Mat blob = blobFromImage(image, 1.0/255.0, Size(224, 224), meanValue, true);\n    blob /= stdValue;\n    \n    Net net = readNetFromONNX(\"PATH_TO_MODEL/resnet50-v1-12.onnx\");\n\n    std::vector\u003cMat\u003e out;\n    net.setInput(blob);\n    net.forward(out);\n    \n    double min=0, max=0;\n    Point minLoc, maxLoc;\n    minMaxLoc(out[0], \u0026min, \u0026max, \u0026minLoc, \u0026maxLoc);\n    cout\u003c\u003c\"class num = \"\u003c\u003cmaxLoc.x\u003c\u003cstd::endl;\n}\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fml13571%2Fopencv_lite","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fml13571%2Fopencv_lite","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fml13571%2Fopencv_lite/lists"}