Skip to content

Commit

Permalink
moved to github.com
Browse files Browse the repository at this point in the history
  • Loading branch information
marko-ristin-parquery committed Aug 3, 2018
0 parents commit 324147f
Show file tree
Hide file tree
Showing 31 changed files with 17,692 additions and 0 deletions.
7 changes: 7 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
lanms/adaptor.so
__pycache__
build
lanms.egg-info
.idea
venv3
dist
674 changes: 674 additions & 0 deletions LICENSE

Large diffs are not rendered by default.

34 changes: 34 additions & 0 deletions MANIFEST.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# Include the license file
include LICENSE

# Include the library file
include lanms/adaptor.so

# Include cpp source files and Makefile
include adaptor.cpp
include lanms.h
include Makefile


include include/clipper/clipper.hpp
include include/clipper/clipper.cpp
include include/pybind11/stl_bind.h
include include/pybind11/embed.h
include include/pybind11/attr.h
include include/pybind11/class_support.h
include include/pybind11/pytypes.h
include include/pybind11/complex.h
include include/pybind11/operators.h
include include/pybind11/eval.h
include include/pybind11/pybind11.h
include include/pybind11/descr.h
include include/pybind11/eigen.h
include include/pybind11/buffer_info.h
include include/pybind11/chrono.h
include include/pybind11/options.h
include include/pybind11/common.h
include include/pybind11/cast.h
include include/pybind11/numpy.h
include include/pybind11/typeid.h
include include/pybind11/functional.h
include include/pybind11/stl.h
13 changes: 13 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
CXXFLAGS = -I include -std=c++11 -O3 $(shell python3-config --cflags)
LDFLAGS = $(shell python3-config --ldflags)

DEPS = lanms.h $(shell find include -xtype f)
CXX_SOURCES = adaptor.cpp include/clipper/clipper.cpp

LIB_SO = lanms/adaptor.so

$(LIB_SO): $(CXX_SOURCES) $(DEPS)
$(CXX) -o $@ $(CXXFLAGS) $(LDFLAGS) $(CXX_SOURCES) --shared -fPIC

clean:
rm -rf $(LIB_SO)
29 changes: 29 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
Locality-Aware Non-Maximum Suppression (LANMS)
==============================================

We provide a python package for the compiled version of the LANMS as described by Zhout et al.
in their paper "EAST: An Efficient and Accurate Scene Text Detector", CVPR 2017. The code is from the TensorFlow
implementation available on: https://github.com/argman/EAST

We only packaged the code. For any questions or suggestions, please refer to: https://github.com/argman/EAST

Installation
============

* Create a virtual environment:

.. code-block:: bash
python3 -m venv venv3
* Activate it:

.. code-block:: bash
source venv3/bin/activate
* Install lanms with pip:

.. code-block:: bash
pip3 install lanms
61 changes: 61 additions & 0 deletions adaptor.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
#include "pybind11/pybind11.h"
#include "pybind11/numpy.h"
#include "pybind11/stl.h"
#include "pybind11/stl_bind.h"

#include "lanms.h"

namespace py = pybind11;


namespace lanms_adaptor {

std::vector<std::vector<float>> polys2floats(const std::vector<lanms::Polygon> &polys) {
std::vector<std::vector<float>> ret;
for (size_t i = 0; i < polys.size(); i ++) {
auto &p = polys[i];
auto &poly = p.poly;
ret.emplace_back(std::vector<float>{
float(poly[0].X), float(poly[0].Y),
float(poly[1].X), float(poly[1].Y),
float(poly[2].X), float(poly[2].Y),
float(poly[3].X), float(poly[3].Y),
float(p.score),
});
}

return ret;
}


/**
*
* \param quad_n9 an n-by-9 numpy array, where first 8 numbers denote the
* quadrangle, and the last one is the score
* \param iou_threshold two quadrangles with iou score above this threshold
* will be merged
*
* \return an n-by-9 numpy array, the merged quadrangles
*/
std::vector<std::vector<float>> merge_quadrangle_n9(
py::array_t<float, py::array::c_style | py::array::forcecast> quad_n9,
float iou_threshold) {
auto pbuf = quad_n9.request();
if (pbuf.ndim != 2 || pbuf.shape[1] != 9)
throw std::runtime_error("quadrangles must have a shape of (n, 9)");
auto n = pbuf.shape[0];
auto ptr = static_cast<float *>(pbuf.ptr);
return polys2floats(lanms::merge_quadrangle_n9(ptr, n, iou_threshold));
}

}

PYBIND11_PLUGIN(adaptor) {
py::module m("adaptor", "NMS");

m.def("merge_quadrangle_n9", &lanms_adaptor::merge_quadrangle_n9,
"merge quadrangels");

return m.ptr();
}

Loading

0 comments on commit 324147f

Please sign in to comment.