Skip to content

Commit

Permalink
Add lanms-nova
Browse files Browse the repository at this point in the history
  • Loading branch information
AndranikSargsyan committed Aug 30, 2021
0 parents commit 155989e
Show file tree
Hide file tree
Showing 32 changed files with 17,658 additions and 0 deletions.
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
__pycache__
build
lanms_nova.egg-info
.idea
venv
dist
674 changes: 674 additions & 0 deletions LICENSE

Large diffs are not rendered by default.

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

# Include cpp source files and Makefile
include src/lanmslib.cpp
include src/lanmslib.h
include src/Makefile


include src/include/clipper/clipper.h
include src/include/clipper/clipper.cpp
include src/include/pybind11/stl_bind.h
include src/include/pybind11/embed.h
include src/include/pybind11/attr.h
include src/include/pybind11/class_support.h
include src/include/pybind11/pytypes.h
include src/include/pybind11/complex.h
include src/include/pybind11/operators.h
include src/include/pybind11/eval.h
include src/include/pybind11/pybind11.h
include src/include/pybind11/descr.h
include src/include/pybind11/eigen.h
include src/include/pybind11/buffer_info.h
include src/include/pybind11/chrono.h
include src/include/pybind11/options.h
include src/include/pybind11/common.h
include src/include/pybind11/cast.h
include src/include/pybind11/numpy.h
include src/include/pybind11/typeid.h
include src/include/pybind11/functional.h
include src/include/pybind11/stl.h
31 changes: 31 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# Locality-Aware Non-Maximum Suppression (LANMS)

This is a python binding for LANMS as described by Zhout et al.
in their paper "EAST: An Efficient and Accurate Scene Text Detector", CVPR 2017. The C++ code is taken from the
implementation available on: https://github.com/argman/EAST

### Installation

`pip install lanms-nova`

### Usage example
```python
import numpy as np
import lanms

boxes = np.array([
[137.0, 113.6, 162.3, 113.3, 162.4, 122.2, 137.2, 122.6, 0.75],
[137.2, 113.8, 163.2, 114.6, 163.0, 122.6, 137.0, 121.9, 0.97],
[136.8, 113.4, 163.2, 114.5, 162.9, 122.7, 136.5, 121.6, 0.15],
[136.6, 112.9, 163.3, 114.5, 162.8, 122.9, 136.1, 121.3, 0.95],
[136.4, 112.6, 163.4, 114.5, 162.8, 123.0, 135.8, 121.2, 0.96],
[131.4, 89.2, 137.8, 89.0, 138.2, 98.5, 131.8, 98.7, 0.98],
[131.6, 89.2, 137.8, 89.1, 138.1, 98.6, 131.8, 98.8, 0.32],
[131.5, 89.2, 137.9, 89.1, 138.0, 98.6, 131.6, 98.7, 0.99],
[131.5, 89.2, 138.0, 89.1, 138.1, 98.5, 131.6, 98.5, 0.87],
[131.5, 89.3, 137.8, 89.0, 138.2, 98.4, 132.0, 98.7, 0.97]
], dtype=np.float32)

boxes = lanms.merge_quadrangle_n9(boxes, nms_thresh=0.5)
print(boxes)
```
15 changes: 15 additions & 0 deletions lanms/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import numpy as np

from .lanmslib import merge_quadrangle_n9 as nms_impl


def merge_quadrangle_n9(polys: np.ndarray, nms_thresh: float = 0.3, precision: int = 10000) -> np.ndarray:
if len(polys) == 0:
return np.array([], dtype='float32')

p = polys.copy()
p[:, :8] *= precision
ret = np.array(nms_impl(p, nms_thresh), dtype='float32')
ret[:, :8] /= precision

return ret
2 changes: 2 additions & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[metadata]
description-file=README.md
32 changes: 32 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import os
from setuptools import setup, Extension


setup(
name="lanms-nova",
version="1.0.1",
author="Andranik Sargsyan",
author_email="[email protected]",
description="lanms-nova is a python binding for LANMS - Locality-Aware Non-Max Suppression",
install_requires=["numpy"],
long_description_content_type="text/markdown",
long_description=open("README.md").read(),
packages=["lanms"],
include_package_data=True,
ext_modules=[
Extension(
name="lanms.lanmslib",
sources=[
os.path.join("src", "lanmslib.cpp"),
os.path.join("src", "include", "clipper", "clipper.cpp")
],
include_dirs=[os.path.join("src", "include")],
language="c++",
undef_macros=["NDEBUG"],
),
],
zip_safe=False,
license="GPL",
keywords=["NMS", "LANMS"],
url="https://github.com/AndranikSargsyan/lanms-nova",
)
13 changes: 13 additions & 0 deletions src/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
CXXFLAGS = -I include -std=c++11 -O3 $(shell python3.8-config --cflags)
LDFLAGS = $(shell python3.8-config --ldflags)

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

LIB_SO = build/lanmslib.so

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

clean:
rm -rf $(LIB_SO)
Loading

0 comments on commit 155989e

Please sign in to comment.