mmocr
mmocr copied to clipboard
bounding box sort clockwise function is incorrect
Describe the bug
from mmocr.utils.box_util import sort_points poly = [[1668,1748],[1704,1749],[1742,1898],[1705,1898]] sorted_pts = order_points(np.array(poly)) print(sorted_pts)
the MMOCR function sort_points claims to sort arbitory points in clockwise order.
BUT the above code produce sorted points as [1704, 1749] [1668, 1748] [1705, 1898] [1742, 1898]
which is completely incorrect. The expected order should be:
[1668,1748] [1704,1749] [1742,1898] [1705,1898]
Reproduction
- What command or script did you run?
from mmocr.utils.box_util import sort_points poly = [[1668,1748],[1704,1749],[1742,1898],[1705,1898]] sorted_pts = order_points(np.array(poly)) print(sorted_pts)
The MMOCR version used is 0.6.0.
Environment
- Please run
python mmocr/utils/collect_env.py
to collect necessary environment information and paste it here.
sys.platform: linux Python: 3.9.12 (main, Apr 5 2022, 06:56:58) [GCC 7.5.0] CUDA available: False GCC: gcc (Ubuntu 7.5.0-3ubuntu1~18.04) 7.5.0 PyTorch: 1.9.0+cu111 PyTorch compiling details: PyTorch built with:
- GCC 7.3
- C++ Version: 201402
- Intel(R) oneAPI Math Kernel Library Version 2021.4-Product Build 20210904 for Intel(R) 64 architecture applications
- Intel(R) MKL-DNN v2.1.2 (Git Hash 98be7e8afa711dc9b66c8ff3504129cb82013cdb)
- OpenMP 201511 (a.k.a. OpenMP 4.5)
- NNPACK is enabled
- CPU capability usage: AVX2
- Build settings: BLAS_INFO=mkl, BUILD_TYPE=Release, CUDA_VERSION=11.1, CUDNN_VERSION=8.0.5, CXX_COMPILER=/opt/rh/devtoolset-7/root/usr/bin/c++, CXX_FLAGS= -Wno-deprecated -fvisibility-inlines-hidden -DUSE_PTHREADPOOL -fopenmp -DNDEBUG -DUSE_KINETO -DUSE_FBGEMM -DUSE_QNNPACK -DUSE_PYTORCH_QNNPACK -DUSE_XNNPACK -DSYMBOLICATE_MOBILE_DEBUG_HANDLE -O2 -fPIC -Wno-narrowing -Wall -Wextra -Werror=return-type -Wno-missing-field-initializers -Wno-type-limits -Wno-array-bounds -Wno-unknown-pragmas -Wno-sign-compare -Wno-unused-parameter -Wno-unused-variable -Wno-unused-function -Wno-unused-result -Wno-unused-local-typedefs -Wno-strict-overflow -Wno-strict-aliasing -Wno-error=deprecated-declarations -Wno-stringop-overflow -Wno-psabi -Wno-error=pedantic -Wno-error=redundant-decls -Wno-error=old-style-cast -fdiagnostics-color=always -faligned-new -Wno-unused-but-set-variable -Wno-maybe-uninitialized -fno-math-errno -fno-trapping-math -Werror=format -Wno-stringop-overflow, LAPACK_INFO=mkl, PERF_WITH_AVX=1, PERF_WITH_AVX2=1, PERF_WITH_AVX512=1, TORCH_VERSION=1.9.0, USE_CUDA=ON, USE_CUDNN=ON, USE_EXCEPTION_PTR=1, USE_GFLAGS=OFF, USE_GLOG=OFF, USE_MKL=ON, USE_MKLDNN=ON, USE_MPI=OFF, USE_NCCL=ON, USE_NNPACK=ON, USE_OPENMP=ON,
TorchVision: 0.10.0+cu111 OpenCV: 4.5.4 MMCV: 1.5.3 MMCV Compiler: GCC 7.3 MMCV CUDA Compiler: 11.1 MMOCR: 0.6.0+
Bug fix
I have created a PR for it regarding the fix.
@xinke-wang Hi,
I have done a PR fix at https://github.com/open-mmlab/mmocr/pull/1146,
let me know what you think, cheers.
Thanks! Since this PR works like a patch for a special case, I'd like to start from this discussion and invite more input from our community to see if we can finally achieve an optimum solution.
The ordering depends on the coordinate system that you are working on. We finally applied the fix at https://github.com/open-mmlab/mmocr/pull/1205, which is based on the Cartesian coordinate system. Simply reversing the points should address your issue. Let us know if there is any other problem.