Skip to content

立即开发

taotianran edited this page Nov 29, 2022 · 6 revisions

在开始贡献代码之前


现在让我们来看看如何开发一个模块:

源码目录结构

首先,我们需要理解FlyCV的代码组织方式。

benchmark                        // 性能测试
cmake                            // cmake配置文件夹
  ├── external                   // 依赖库cmake配置文件夹
  ├── platform                   // 平台相关cmake配置文件夹
  └── ......
docs
  └── assets                     // 资源文件夹
include
  ├── falconcv.h.in              // 面向用户的接口头文件
  ├── falconcv_namespace.h.in    // 命名空间记录头文件
  └── version.h.in               // 版本记录头文件
modules                          // 功能模块文件夹          
  ├── img_transform              // 一级模块A文件夹
  │      ├── color_convert       // 功能 ①
  │      ├── resize              // 功能 ②
  │      ├── warp_affine         // 功能 ③
  │      └── ......              // 其他功能
  ├── fusion_api                 // 一级模块B文件夹
  ├── img_calculation            // 一级模块C文件夹
  └── ......                     // 其他一级模块
scripts                          // 不同平台编译脚本
samples                          // 不同平台demo
tests                            // 单测文件夹
third_party                      // 依赖库文件夹
tools                            // 辅助开发工具文件夹
  └── add_module                 // 快速模块模板生成工具


How to add a new function

To make it easier for everyone to develop, We provide a tool to quickly generate templates.

You can use the script to add a new function. The script location is tools/add_module.

To use the script, You need to follow the steps below.

1. Install python dependencies

sudo pip3 install Jinja2

2. Add a new module

python3 tools/add_module.py modules/<parent_module>/<child_module> <ON|OFF>

parent_module: Corresponds to the folder in the modules directory.

child_module: Corresponds to the folder in the specific function directory.

ON|OFF: Specify whether to enable compilation by default for new modules.

for example:

python3 tools/add_module/add_module.py modules/img_transform/blur OFF

After executing the above command, view the changes with git status.

On branch my-work
Changes not staged for commit:
  (use "git add <file>..." to update what will be committed)
  (use "git restore <file>..." to discard changes in working directory)
	modified:   cmake/FCVBuildList.cmake
	modified:   include/flycv.h.in

Untracked files:
  (use "git add <file>..." to include in what will be committed)
	benchmark/modules/img_transform/blur_bench.cpp
	modules/img_transform/blur/
	tests/modules/img_transform/blur_test.cpp

Here is a brief introduction to these files:

  1. cmake/FalconCVBuildList.cmake : Automatically add compile option in the file.
option(WITH_FCV_BLUR "Build module blur" OFF)
  1. include/falconcv.h.in : The header file automatically added to the user-oriented file.
#cmakedefine WITH_FCV_BLUR

#ifdef WITH_FCV_BLUR
#include "modules/img_transform/blur/interface/blur.h"
#endif
  1. View the generated module directory structure.
modules/img_transform/blur
    ├── include
    │   └── blur_common.h
    ├── interface
    │   └── blur.h
    └── src
        ├── blur.cpp
        └── blur_common.cpp

interface: user-oriented header files directory
include:   internal header files directory
src:       implementation directory
  1. tests/modules/img_transform/blur_test.cpp : unit test file.

  2. benchmark/modules/img_transform/blur_bench.cpp : performance test file.

Then you can fully focus on writing functional code.


Compile

Please refer to the compilation documentation. We provide compilation methods for different platforms.


Unit Test

Like many open source libraries, we use GoogleTest as our unit test framework, learn about GoogleTest.

The tool generates a simple unit test template, here is an example.

class BlurTest : public ::testing::Test {
    void SetUp() override {
        // (optional) prepare test data for every case
    }
};

TEST_F(BlurTest, PositiveInput) {
    // add your test code here
}

Just modify this file to complete the test case.


Benchmark Test

we use benchmark as our performance test framework, learn about benchmark.

The tool generates a simple performance test template, here is an example.

class BlurBench : public benchmark::Fixture {
public:
    void SetUp(const ::benchmark::State& state) {
        set_thread_num(G_THREAD_NUM);

        // (optional) prepare test data for every case
    }
};

BENCHMARK_DEFINE_F(BlurBench, PlaceHolder)
        (benchmark::State& state) {
    // add your code here
    // don't forget to replace the PlaceHolder with a meaningful one
};

// don't forget to replace the PlaceHolder with a meaningful one
BENCHMARK_REGISTER_F(BlurBench, PlaceHolder)
        ->Unit(benchmark::kMicrosecond)
        ->Iterations(100)
        ->DenseRange(55, 255, 200);

Just modify this file to complete the performance test case.

Clone this wiki locally