{"id":18422153,"url":"https://github.com/lucasjinreal/thor","last_synced_at":"2025-04-07T10:23:36.543Z","repository":{"id":41514104,"uuid":"165018426","full_name":"lucasjinreal/thor","owner":"lucasjinreal","description":"thor: C++ helper library, for deep learning purpose","archived":false,"fork":false,"pushed_at":"2022-07-15T14:20:33.000Z","size":3885,"stargazers_count":275,"open_issues_count":8,"forks_count":62,"subscribers_count":8,"default_branch":"master","last_synced_at":"2025-03-31T08:12:08.162Z","etag":null,"topics":["computer-vision","deeplearning","object-detection","tracking"],"latest_commit_sha":null,"homepage":null,"language":"C++","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/lucasjinreal.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}},"created_at":"2019-01-10T08:12:01.000Z","updated_at":"2025-03-22T19:04:36.000Z","dependencies_parsed_at":"2022-08-21T11:40:26.808Z","dependency_job_id":null,"html_url":"https://github.com/lucasjinreal/thor","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lucasjinreal%2Fthor","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lucasjinreal%2Fthor/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lucasjinreal%2Fthor/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lucasjinreal%2Fthor/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/lucasjinreal","download_url":"https://codeload.github.com/lucasjinreal/thor/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247632692,"owners_count":20970202,"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":["computer-vision","deeplearning","object-detection","tracking"],"created_at":"2024-11-06T04:28:20.842Z","updated_at":"2025-04-07T10:23:36.521Z","avatar_url":"https://github.com/lucasjinreal.png","language":"C++","funding_links":[],"categories":[],"sub_categories":[],"readme":"# thor [![Travis Status](https://travis-ci.org/davisking/dlib.svg?branch=master)](https://travis-ci.org/davisking/dlib)\n\n\u003cp align=\"center\"\u003e\n\u003cimg src=\"https://s2.ax1x.com/2019/06/06/VdV0i9.png\" /\u003e\n\u003c/p\u003e\n**thor** is a C++ helper library which provide huge utilities, algorithms, and visualization functions for deep learning. We recommend install thor from github source since we update thor new APIs a lot. But *thor* will always compatible with older versions, it safe and reliable integrate into your projects and providing useful utilities.\n\nGlad to know this repo was recommended by 爱可可老师! The link is https://weibo.com/1402400261/I8p1gnIkK .\n\n\u003e  note: Now thor built against protobuf by default (due to we use proto to visualize boxes in C++ for cross-platform), so in your project, you gonna need add following in your CMakeLists.txt:\n\n```cmake\nfind_package(Protobuf REQUIRED)\ntarget_link_library(your_executable ${PROTOBUF_LIBRARY} thor)\n```\n\n\n## Roadmap\n\n**thor** is still need progress and enlarge it's functionality. Current roadmap are:\n\n- [x] support instance segmentation visualization;\n- [ ] upload thor to ubuntu package manager;\n\n\n\n## Quick Install\n\nSimple version:\n\n```\n./build_simple.sh\n```\n\nYou need install `libprotobuf-dev` and `protobuf-compiler` first on Ubuntu or linux system. If you got any problems about not found **libcurl** or **protobuf header files**, be sure installed libs inside `build_simple.sh`.\n\nIf you want to build thor on **JetsonNano**, you need manually uncomment CMakeLists.txt link path to your aarch64 system path (normal PC is x86).\n\n![image-20201107222319190](https://i.loli.net/2020/11/07/o1LyGD8l3EHabkK.png)\n\n![image-20201107222409982](https://i.loli.net/2020/11/07/UGmwID86ZaKlV5n.png)\n\nIf you setup correctly, thor can be successfully installed on **JetsonNano** as well.\n\n\n\n\n## Install\n\n**If you are a newbie of C++ or Ubuntu, recommend you using simple mode**.\n\na). If you only need thor independent modules without OpenCV or Eigen or Protobuf or Curl, you can simply run:\n\n```\n./build_simple.sh\n```\n\n*this will build a standalone `thor.so` without link any other libs, but if you call any function that needs opencv or protobuf will leads to an error.*\n\nb). If you need full capacity which thor does, including `vis`, `geometry`, `datum` modules, you can run:\n\n```\n./build_full.sh\n```\n\n*this will build a full version of thor with link to opencv, protobuf, curl, freetype. so if you call any related function, you gonna need link to that lib first in your cmake file.*\n\n**note**: Our `logging` module using same micro define as glog, so it will conflicts if you importing them both. If your project doesn't need glog and you are using thor, you can simply deprecate glog and using thor only.\n\n\n\n## Updates\n\n- **2050.01.01**: to be continue..\n\n- **2021.01.11**: New thor built with **C++14** by default. `det.pro` added `x, y, w, h` as attributes.\n\n- **2020.08.17**: thor now supports visualize lane:\n\n    ```c++\n    auto resImg = thor::vis::VisualizeLanes(image, res, nullptr, 12, 1.0);\n    ```\n\n    ![](https://i.loli.net/2020/08/21/byrAOkCFNoWItP4.png)\n\n    \n\n- **2020.04.15**: **thor now build with curl and protobuf** by default. If you got any question about protobuf link problem, pls fire an issue, I will help u fix that, normally thor should built successfully without any errors, as long as you install default libs:\n\n    ```\n    sudo apt install libprotobuf-dev\n    sudo apt install protobuf-compiler\n    sudo apt install libcurl4-openssl-dev\n    ```\n\n    We add protobuf as default built for the introduce of protos which we will using for default data structures:\n\n    ```c++\n    Detection2D det1;\n    Box box;\n    box.set_x1(23);\n    box.set_y1(89);\n    box.set_x2(99);\n    box.set_y2(156);\n    det1.set_allocated_box(\u0026box);\n    det1.set_cls_id(9);\n    det1.set_prob(0.9);\n    \n    InstanceSegmentation seg1;\n    seg1.set_allocated_detection(\u0026det1);\n    // float32\n    seg1.add_mask(2.3);\n    seg1.add_mask(2.3);\n    seg1.add_mask(2.3);\n    seg1.add_mask(2.3);\n    \n    LOG(INFO) \u003c\u003c seg1.DebugString();\n    ```\n\n    this will easy transport to other languages:\n\n    ```\n    detection {\n      box {\n        x1: 23\n        y1: 89\n        x2: 99\n        y2: 156\n      }\n      cls_id: 9\n      prob: 0.9\n    }\n    mask: 2.3\n    mask: 2.3\n    mask: 2.3\n    mask: 2.3\n    ```\n\n- **2019.12.26**: We add a `functions` in thor to enable some tiny functions:\n\n    ```c++\n    #include \"thor/functions.h\"\n    \n    double values[] = {-0.9381,  0.8967};\n    double probs[2];\n    thor::functions::softmax_1d(values, probs, 2);\n    LOG(INFO) \u003c\u003c probs[0] \u003c\u003c \" \" \u003c\u003c probs[1];\n    ```\n\n    Also we update a bug in `HWC2CHW`, now it works well now.\n\n- **2019.11.16**: We demonstrate how to using `thor::vis` to draw detections in your algorithm:\n\n    ![](https://s2.ax1x.com/2019/11/15/Mdig8e.png)\n\n    ```c++\n    #include \"thor/dl.h\"\n    #include \"thor/os.h\"\n    #include \"thor/structures.h\"\n    #include \"thor/vis.h\"\n    \n    using namespace std;\n    using namespace cv;\n    using namespace thor::vis;\n    using namespace thor::dl;\n    \n    int main() {\n        vector\u003cthor::Box\u003e all_detections;\n      for (int i = 0; i \u003c num_det; i++) {\n        // Show results over confidence threshold\n        if (scores[i] \u003e= 0.33f) {\n          float x1 = boxes[i * 4 + 0] * scale_x;\n          float y1 = boxes[i * 4 + 1] * scale_y;\n          float x2 = boxes[i * 4 + 2] * scale_x;\n          float y2 = boxes[i * 4 + 3] * scale_y;\n          thor::Box one_box{x1, y1, x2, y2, thor::BoxFormat::XYXY};\n          one_box.score = scores[i];\n          one_box.idx = classes[i] + 1;\n          all_detections.emplace_back(one_box);\n        }\n      }\n    \n    // draw\n    auto res_image = thor::vis::VisualizeDetectionStyleDetectron2(\n              image, all_detections, COCO_CLASSES);\n    }\n    ```\n\n    Above is a simple example using `thor::vis::VisualizeDetectionStyleDetectron2` draw bounding boxes using detectron2 style.  From our experiences, these steps time cost is about **0.0001**s, so it's doesn't matter if you generate your box format to `thor::Box` format first and then call our drawing method.\n\n- **2019.09.24**: I just notice thor has been recommended by 爱可可老师 through weibo, here is link: https://weibo.com/1402400261/I8p1gnIkK , check it out!!! If you like this project, pls give a star!!\n\n- **2019.08.29**: A new header-only args parser lib has been added into thor. Original implementation from [here](https://github.com/Taywee/args). We did some changes than original, roughly usage can be used like this:\n\n    ````c++\n    #include \"thor/args.h\"\n    using namespace thor;\n    int main() {\n      args::ArgumentParser parser(\"YoloV3 TensorRT\", \"args parse from thor\");\n      args::HelpFlag help(parser, \"HELP\", \"Show this help menu.\", {\"help\"});\n      args::ValueFlag\u003cstd::string\u003e data(parser, \"data\", \"data.\", {'d'}, \"\");\n      args::ValueFlag\u003cstd::string\u003e proto_txt(parser, \"proto_txt\", \"proto_txt.\", {'p'}, \"\");\n      args::ValueFlag\u003cstd::string\u003e model(parser, \"model\", \"caffe model.\", {'m'}, \"\");\n      args::ValueFlag\u003cstd::string\u003e engine(parser, \"engine\", \"trt engine file.\", {\"engine\"}, \"\");\n        \n        try\n        {\n            parser.ParseCLI(argc, argv);\n        }\n        catch (const args::Completion\u0026 e)\n        {\n            std::cout \u003c\u003c e.what();\n            return 0;\n        }\n        catch (const args::Help\u0026)\n        {\n            std::cout \u003c\u003c parser;\n            return 0;\n        }\n        catch (const args::ParseError\u0026 e)\n        {\n            std::cerr \u003c\u003c e.what() \u003c\u003c std::endl;\n            std::cerr \u003c\u003c parser;\n            return 1;\n        }\n    }\n    ````\n\n    You will see:\n\n    ```\n    ./examples/trt_yolov3 {OPTIONS}\n    \n        YoloV3 TensorRT\n    \n      OPTIONS:\n    \n          --help                            Show this help menu.\n          -d[data]                          data.\n          -p[proto_txt]                     proto_txt.\n          -m[model]                         caffe model.\n          --engine=[engine]                 trt engine file.\n        args parse from thor\n    ```\n\n    This is useful when you do not want gflags and glog lib, since those 2 has been integrated into thor!!\n\n- **2019.08.07**: O(∩_∩)O~~!!! A lightweighted logging lib has been integrated into thor!!!!! Now, you can using `LOG(INFO)` without glog:\n\n    ```c++\n    #include \"thor/logging.h\"\n    \n    using namespace thor;\n    \n    int main() {\n    \tLOG(INFO) \u003c\u003c \"this is a log.\";\n    }\n    ```\n\n    We'll see:\n\n    ```\n    I 8/7 11:24:46.484 ...thor_simple.cpp main:28]  this is a log\n    ```\n\n    \n\n- **2019.08.06**: We add precompile define to turn on or off dependencies, such as opencv or protobuf, those dependencies were turned off by default. If you need full version of thor, simple build with `build_full.sh` ;\n\n- **2019.06.16**: Update CMakeLists.txt fix eigen include issue, now users install will not got eigen include not found problem, simply remember to install `libeigen3-dev` first.\n\n- **2019.06.15**: Adding HumanPose drawing in thor!!! Here is what it looks like:\n\n    \u003cp align=\"center\"\u003e\n        \u003cimg src=\"https://upload-images.jianshu.io/upload_images/617746-f083cb7d20c91f2d.gif\"/\u003e\n    \u003c/p\u003e\n\n    this can be down by simply apply this:\n\n    ```c++\n    #include \"thor/vis.h\"\n    using namespace thor::vis;\n    int main() {\n        // suppose you have detected poses\n        std::vector\u003cthor::HumanPose\u003e poses = ..;\n        renderHumanPose(poses, image);\n    }\n    ```\n\n\n- **2019.05.23**: We just add a `datum` module into thor and providing a series of `str_utils` which can be very useful for normal C++ development. **Do you want judge a point is on a line segment or not? Do you want describe a rotate box and calculate it's area easily?**, thor `datum` is here to help:\n\n    ```c++\n    // datum\n    #include \"thor/datum.h\"\n    \n    using namespace thor::datum;\n    using namespace thor::generic;\n    \n    Vector2d p1(36, 36);\n    Vector2d p2(78, 78);\n    \n    Vector2d p(23, 23);\n    LineSegment2d l(p1, p2);\n    \n    //call LineSegment2d.IsPointIn() check a point is one segment or not\n    cout \u003c\u003c l.IsPointIn(p) \u003c\u003c endl;\n    // out: false, since 23 is out of line\n    p = Vector2d(46, 46);\n    cout \u003c\u003c l.IsPointIn(p) \u003c\u003c endl;\n    // out: true, since 46 is on line.\n    \n    AABox2d abox1(Vector2d(2, 4), 224, 345);\n    cout \u003c\u003c abox1.DebugString() \u003c\u003c endl;\n    cout \u003c\u003c \"area: \" \u003c\u003c abox1.area() \u003c\u003c endl;\n    ```\n\n    that's it! Using `thor::datum` you can do many math and geometry much more easily!!  **More excitedly, `thor::datum` data structure is compatible with apollo**!!\n\n- **2019.05.19**:  There would be a huge updates on **thor** in recent days. We are trying to integrate all math library in Apollo into thor. So that it can do lots of math calculations.  If you got any undefined inference error just open an issue about that. Currently if you want using thor, you gonna need **link protobuf** in your c++ project.   \n\n- **2019.05.01**: Add some geometry utils such as conversion between quaternion and euler angels for robots and autocar:\n    ```c++\n    Eigen::Matrix3d Quaternion2RotationMatrix(const double x, const double y, const double z, const double w);\n    Eigen::Quaterniond EulerAngle2Quaternion(const double yaw, const double pitch, const double roll);                             \n    ```\n    **note**: this is only available when you have Eigen installed.\n\n- **2019.01.15**: Tracking projects using **thor**:\n    \u003cp align=\"center\"\u003e\n    \u003cimg src=\"https://s2.ax1x.com/2019/05/16/EbUj2t.gif\" /\u003e\n    \u003c/p\u003e\n\n- **2018.09.15**: Object detection projects using **thor**:\n    \u003cp align=\"center\"\u003e\n    \u003cimg src=\"https://s1.ax1x.com/2018/12/07/F1xG7D.gif\" /\u003e\n    \u003c/p\u003e\n\n\n\n\n\n\n## Usage\n\n**thor** has a very clean and easy-to-use API, it consist of many parts. All parts can be listed as follow:\n\n- *vis*: For computer vision, draw boxes or segmentation results on image, should worked with opencv;\n- *files*;\n- *random*;\n- *color*;\n- *logging*;\n- *slam*;\n\nYou only need add this line to CMakeLists.txt when you have thor installed in your system path.\n\n```cmake\ntarget_link_libraries(main -lthor)\n```\n\nto build with Makefile, using:\n\n```shell\ng++ -o a a.cpp `pkg-config thor --cflags --libs`\n```\nIn case you want integrate but with trouble, find me via wechat: `jintianiloveu`\n\n\n## Features\nWe list module **thor** currently finished here:\n\n- [x] os\n- [x] color\n- [x] random\n- [x] log\n- [x] string utils\n- [x] geometry (quaternion and euler angle conversion)\n\n\n## Copyright\n\n**thor** was build by *Lucas Jin* with ❤️. Under MIT license.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flucasjinreal%2Fthor","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Flucasjinreal%2Fthor","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flucasjinreal%2Fthor/lists"}