Skip to content

Collection of various algorithm codes from daily usage

License

Notifications You must be signed in to change notification settings

Bitfultea/TinyToys

Repository files navigation

TinyToys

Collection of various algorithm implementations from daily usage

Required Lib

  • sudo apt-get install liblapacke-dev
  • sudo apt-get install libopenblas-dev

Contain:

  • Helcon fit_line_contour implementation of OpenCV
  • Tensor lib for C++ from Open3D

Detail:

fit_line_contour

See fit_line_contour/main.cpp for usage. The implementation detail is following algorithm from 直线卡尺工具原理 and 仿Halcon卡尺工具. The core is to find the edge which the slope change most significantly in the ROI box.

merge_image

Merge a set of image onto one image based on selected method. Currently support sum and average

Tensor

Separate the Tensor data structure from the OPEN3D library and modify it to suit my daily usage. see documentation in Open3D Website.

For exmaple: In Numpy:

t = np.empty((4, 5), dtype=np.float32)
t[2] = np.empty((5,), dtype=np.float32)
t[0:4:2] = np.empty((2, 5), dtype=np.float32)
t[2, 0:4:2] = np.empty((2, 5), dtype=np.float32)

In C++

Tensor t({4, 5}, Dtype::Float32);
t.SetItem(TensorIndex(2), Tensor({5}, Dtype::Float32));
t.SetItem(TensorSlice(0, 4, 2), Tensor({2, 5}, Dtype::Float32));
t.SetItem({TensorIndex(2), TensorSlice(0, 4, 2)},
          Tensor({2, 5}, Dtype::Float32));

In Numpy:

t = np.empty((4, 5), dtype=np.float32)
t1 = t[2]
t2 = t[0:4:2]
t3 = t[1, 0:4:2]

In C++:

Tensor t({4, 5}, Dtype::Float32);
Tensor t1 = t.GetItem(TensorIndex(2));
Tensor t2 = t.GetItem(TensorSlice(0, 4, 2));
Tensor t3 = t.GetItem({TensorIndex(2), TensorSlice(0, 4, 2)});

There are some examples to use Tensor lib in the project

/// Create a 0-D tensor (scalar) with given value,
core::Tensor::Init<float>(0);

/// Create a 1-D tensor with initializer list,
core::Tensor::Init<float>({0, 1, 2});

/// Create a 2-D tensor with nested initializer list,
core::Tensor::Init<float>({{0, 1, 2}, {3, 4, 5}});


/// examples for creating tensors
core::Device device = core::Device("CPU:0");
core::Device gpu = core::Device("CUDA:0")
a = core::Tensor::Zeros({3}, core::Float32, device);
b = core::Tensor::Eye(3, core::Int32, gpu);
c = core::Tensor::Ones({3}, core::Int8, device);
d = core::Tensor::Ones({3}, core::Bool, gpu);

About

Collection of various algorithm codes from daily usage

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published