Giter Site home page Giter Site logo

cv_algorithms's Introduction

cv_algorithms

image A Python package (Python3 ready!) that contains implementations of various OpenCV algorithms are are not available in OpenCV or OpenCV-contrib. This package is intended to be used with OpenCV 3.

Some performance-critical algorithms are written in optimized C code. The C code is accessed using cffi Currently implemented:

  • Morphological algorithms
  • Algorithms on contours
    • Masking extraction of convex polygon area from image without rotation
    • Scale around reference point or center
    • Fast computation of center by coordinate averaging
    • Center-invariant rescaling of upright bounding rectangle by x/ factors
    • Filter by min/max area
    • Sort by area
    • Create binary contour mask
    • Grassfire transform
  • Colorspace metrics & utilities:
    • Convert image to any colorspace supported by OpenCV
    • Extract any channel from any colorspace directly
    • Euclidean RGB distance
  • Other structural algorithms
    • Which neighboring pixels are set in a binary image?
  • Algorithms on text rendering
    • Center text at coordinates
    • Auto-scale text to fix into box
  • Other algorithms
    • Remove n percent of image borders
    • Popcount (number of one bits) for 8, 16, 32 and 64 bit numpy arrays
    • Resize an image, maintaining the aspect ratio

As OpenCV's Python bindings (cv2) represents images as numpy arrays, most algorithms generically work with numpy1 arrays.

Installation

Install the stable version:

pip install cv_algorithms

How to install the bleeding-edge version from GitHub

pip install git+https://github.com/ulikoehler/cv_algorithms.git

How to build yourself - we use Poetry:

poetry build

Potentially, you need to install OpenCV if not already present. I recommend first trying to install without that, since modern Python versions will take care of that automatically.

Usage

Difference of Gaussian transform documentation & example Grassfire transform documentation & example Thinning documentation & example

Here's a simple usage showcase:

import cv_algorithms
# img must be a binary, single-channel (grayscale) image.
thinned = cv_algorithms.guo_hall(img)

Contributions

Contributions of any shape or form are welcome. Please submit a pull request or file an issue on GitHub.

Copyright (c) 2016-2022 Uli Köhler <[email protected]>

cv_algorithms's People

Contributors

rahulsinghpatel avatar ulikoehler avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

cv_algorithms's Issues

pip install failed

pip install git+https://github.com/ulikoehler/cv_algorithms.git

(py36) george@george-OMEN-by-HP-Laptop ~/KasparNet $ pip install git+https://github.com/ulikoehler/cv_algorithms.git
Collecting git+https://github.com/ulikoehler/cv_algorithms.git
Cloning https://github.com/ulikoehler/cv_algorithms.git to /tmp/pip-req-build-n4uiz7sw
Requirement already satisfied: cffi>=0.7 in /home/george/anaconda3/envs/py36/lib/python3.6/site-packages (from cv-algorithms==1.0.0) (1.11.4)
Requirement already satisfied: pycparser in /home/george/anaconda3/envs/py36/lib/python3.6/site-packages (from cffi>=0.7->cv-algorithms==1.0.0) (2.18)
Building wheels for collected packages: cv-algorithms
Running setup.py bdist_wheel for cv-algorithms ... error
Complete output from command /home/george/anaconda3/envs/py36/bin/python -u -c "import setuptools, tokenize;file='/tmp/pip-req-build-n4uiz7sw/setup.py';f=getattr(tokenize, 'open', open)(file);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, file, 'exec'))" bdist_wheel -d /tmp/pip-wheel-ekl475_a --python-tag cp36:
running bdist_wheel
running build
running build_py
creating build
creating build/lib.linux-x86_64-3.6
creating build/lib.linux-x86_64-3.6/test
copying test/init.py -> build/lib.linux-x86_64-3.6/test
copying test/TestContours.py -> build/lib.linux-x86_64-3.6/test
copying test/TestUtils.py -> build/lib.linux-x86_64-3.6/test
copying test/TestThinning.py -> build/lib.linux-x86_64-3.6/test
copying test/TestNeighbours.py -> build/lib.linux-x86_64-3.6/test
copying test/TestDistance.py -> build/lib.linux-x86_64-3.6/test
copying test/TestColorspace.py -> build/lib.linux-x86_64-3.6/test
copying test/TestGrassfire.py -> build/lib.linux-x86_64-3.6/test
copying test/TestPopcount.py -> build/lib.linux-x86_64-3.6/test
creating build/lib.linux-x86_64-3.6/cv_algorithms
copying cv_algorithms/init.py -> build/lib.linux-x86_64-3.6/cv_algorithms
copying cv_algorithms/grassfire.py -> build/lib.linux-x86_64-3.6/cv_algorithms
copying cv_algorithms/text.py -> build/lib.linux-x86_64-3.6/cv_algorithms
copying cv_algorithms/_ffi.py -> build/lib.linux-x86_64-3.6/cv_algorithms
copying cv_algorithms/contours.py -> build/lib.linux-x86_64-3.6/cv_algorithms
copying cv_algorithms/popcount.py -> build/lib.linux-x86_64-3.6/cv_algorithms
copying cv_algorithms/colorspace.py -> build/lib.linux-x86_64-3.6/cv_algorithms
copying cv_algorithms/distance.py -> build/lib.linux-x86_64-3.6/cv_algorithms
copying cv_algorithms/morphology.py -> build/lib.linux-x86_64-3.6/cv_algorithms
copying cv_algorithms/classification.py -> build/lib.linux-x86_64-3.6/cv_algorithms
copying cv_algorithms/thinning.py -> build/lib.linux-x86_64-3.6/cv_algorithms
copying cv_algorithms/_checks.py -> build/lib.linux-x86_64-3.6/cv_algorithms
copying cv_algorithms/neighbours.py -> build/lib.linux-x86_64-3.6/cv_algorithms
copying cv_algorithms/utils.py -> build/lib.linux-x86_64-3.6/cv_algorithms
running build_ext
building 'cv_algorithms._cv_algorithms' extension
creating build/temp.linux-x86_64-3.6
creating build/temp.linux-x86_64-3.6/src
gcc -pthread -B /home/george/anaconda3/envs/py36/compiler_compat -Wl,--sysroot=/ -Wsign-compare -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -fPIC -I/home/george/anaconda3/envs/py36/include/python3.6m -c src/thinning.cpp -o build/temp.linux-x86_64-3.6/src/thinning.o -g -O2 -march=native
cc1plus: warning: command line option ‘-Wstrict-prototypes’ is valid for C/ObjC but not for C++
gcc -pthread -B /home/george/anaconda3/envs/py36/compiler_compat -Wl,--sysroot=/ -Wsign-compare -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -fPIC -I/home/george/anaconda3/envs/py36/include/python3.6m -c src/distance.cpp -o build/temp.linux-x86_64-3.6/src/distance.o -g -O2 -march=native
cc1plus: warning: command line option ‘-Wstrict-prototypes’ is valid for C/ObjC but not for C++
src/distance.cpp: In function ‘int pairwise_diff(const double*, const double*, double*, size_t, size_t)’:
src/distance.cpp:18:46: error: call of overloaded ‘abs(double)’ is ambiguous
result[ax*awidth + bx] = abs(a[ax] - b[bx]);
^
In file included from /usr/include/c++/6/cstdlib:75:0,
from /usr/include/c++/6/stdlib.h:36,
from src/distance.cpp:1:
/usr/include/stdlib.h:774:12: note: candidate: int abs(int)
extern int abs (int __x) __THROW attribute ((const)) __wur;
^~~
In file included from /usr/include/c++/6/stdlib.h:36:0,
from src/distance.cpp:1:
/usr/include/c++/6/cstdlib:185:3: note: candidate: __int128 std::abs(__int128)
abs(__GLIBCXX_TYPE_INT_N_0 __x) { return __x >= 0 ? __x : -__x; }
^~~
/usr/include/c++/6/cstdlib:180:3: note: candidate: long long int std::abs(long long int)
abs(long long __x) { return __builtin_llabs (__x); }
^~~
/usr/include/c++/6/cstdlib:172:3: note: candidate: long int std::abs(long int)
abs(long __i) { return __builtin_labs(__i); }
^~~
error: command 'gcc' failed with exit status 1


Failed building wheel for cv-algorithms
Running setup.py clean for cv-algorithms
Failed to build cv-algorithms
Installing collected packages: cv-algorithms
Running setup.py install for cv-algorithms ... error
Complete output from command /home/george/anaconda3/envs/py36/bin/python -u -c "import setuptools, tokenize;file='/tmp/pip-req-build-n4uiz7sw/setup.py';f=getattr(tokenize, 'open', open)(file);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, file, 'exec'))" install --record /tmp/pip-record-i4nvkxyk/install-record.txt --single-version-externally-managed --compile:
running install
running build
running build_py
creating build
creating build/lib.linux-x86_64-3.6
creating build/lib.linux-x86_64-3.6/test
copying test/init.py -> build/lib.linux-x86_64-3.6/test
copying test/TestContours.py -> build/lib.linux-x86_64-3.6/test
copying test/TestUtils.py -> build/lib.linux-x86_64-3.6/test
copying test/TestThinning.py -> build/lib.linux-x86_64-3.6/test
copying test/TestNeighbours.py -> build/lib.linux-x86_64-3.6/test
copying test/TestDistance.py -> build/lib.linux-x86_64-3.6/test
copying test/TestColorspace.py -> build/lib.linux-x86_64-3.6/test
copying test/TestGrassfire.py -> build/lib.linux-x86_64-3.6/test
copying test/TestPopcount.py -> build/lib.linux-x86_64-3.6/test
creating build/lib.linux-x86_64-3.6/cv_algorithms
copying cv_algorithms/init.py -> build/lib.linux-x86_64-3.6/cv_algorithms
copying cv_algorithms/grassfire.py -> build/lib.linux-x86_64-3.6/cv_algorithms
copying cv_algorithms/text.py -> build/lib.linux-x86_64-3.6/cv_algorithms
copying cv_algorithms/_ffi.py -> build/lib.linux-x86_64-3.6/cv_algorithms
copying cv_algorithms/contours.py -> build/lib.linux-x86_64-3.6/cv_algorithms
copying cv_algorithms/popcount.py -> build/lib.linux-x86_64-3.6/cv_algorithms
copying cv_algorithms/colorspace.py -> build/lib.linux-x86_64-3.6/cv_algorithms
copying cv_algorithms/distance.py -> build/lib.linux-x86_64-3.6/cv_algorithms
copying cv_algorithms/morphology.py -> build/lib.linux-x86_64-3.6/cv_algorithms
copying cv_algorithms/classification.py -> build/lib.linux-x86_64-3.6/cv_algorithms
copying cv_algorithms/thinning.py -> build/lib.linux-x86_64-3.6/cv_algorithms
copying cv_algorithms/_checks.py -> build/lib.linux-x86_64-3.6/cv_algorithms
copying cv_algorithms/neighbours.py -> build/lib.linux-x86_64-3.6/cv_algorithms
copying cv_algorithms/utils.py -> build/lib.linux-x86_64-3.6/cv_algorithms
running build_ext
building 'cv_algorithms._cv_algorithms' extension
creating build/temp.linux-x86_64-3.6
creating build/temp.linux-x86_64-3.6/src
gcc -pthread -B /home/george/anaconda3/envs/py36/compiler_compat -Wl,--sysroot=/ -Wsign-compare -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -fPIC -I/home/george/anaconda3/envs/py36/include/python3.6m -c src/thinning.cpp -o build/temp.linux-x86_64-3.6/src/thinning.o -g -O2 -march=native
cc1plus: warning: command line option ‘-Wstrict-prototypes’ is valid for C/ObjC but not for C++
gcc -pthread -B /home/george/anaconda3/envs/py36/compiler_compat -Wl,--sysroot=/ -Wsign-compare -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -fPIC -I/home/george/anaconda3/envs/py36/include/python3.6m -c src/distance.cpp -o build/temp.linux-x86_64-3.6/src/distance.o -g -O2 -march=native
cc1plus: warning: command line option ‘-Wstrict-prototypes’ is valid for C/ObjC but not for C++
src/distance.cpp: In function ‘int pairwise_diff(const double*, const double*, double*, size_t, size_t)’:
src/distance.cpp:18:46: error: call of overloaded ‘abs(double)’ is ambiguous
result[ax*awidth + bx] = abs(a[ax] - b[bx]);
^
In file included from /usr/include/c++/6/cstdlib:75:0,
from /usr/include/c++/6/stdlib.h:36,
from src/distance.cpp:1:
/usr/include/stdlib.h:774:12: note: candidate: int abs(int)
extern int abs (int __x) __THROW attribute ((const)) __wur;
^~~
In file included from /usr/include/c++/6/stdlib.h:36:0,
from src/distance.cpp:1:
/usr/include/c++/6/cstdlib:185:3: note: candidate: __int128 std::abs(__int128)
abs(__GLIBCXX_TYPE_INT_N_0 __x) { return __x >= 0 ? __x : -__x; }
^~~
/usr/include/c++/6/cstdlib:180:3: note: candidate: long long int std::abs(long long int)
abs(long long __x) { return __builtin_llabs (__x); }
^~~
/usr/include/c++/6/cstdlib:172:3: note: candidate: long int std::abs(long int)
abs(long __i) { return __builtin_labs(__i); }
^~~
error: command 'gcc' failed with exit status 1

----------------------------------------

Command "/home/george/anaconda3/envs/py36/bin/python -u -c "import setuptools, tokenize;file='/tmp/pip-req-build-n4uiz7sw/setup.py';f=getattr(tokenize, 'open', open)(file);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, file, 'exec'))" install --record /tmp/pip-record-i4nvkxyk/install-record.txt --single-version-externally-managed --compile" failed with error code 1 in /tmp/pip-req-build-n4uiz7sw/
(py36) george@george-OMEN-by-HP-Laptop ~/KasparNet $

Install fails on Windows

ERROR: Command errored out with exit status 1:

command: 'c:\users\userb\anaconda3\envs\tabletrainnet_env\python.exe' -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'C:\Users\USERb1\AppData\Local\Temp\pip-install-juo3afv7\cv-algorithms_c69eb1f14e86421ba8e084ddba8405c2\setup.py'"'"'; file='"'"'C:\Users\USERB1\AppData\Local\Temp\pip-install-juo3afv7\cv-algorithms_c69eb1f14e86421ba8e084ddba8405c2\setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(file);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, file, '"'"'exec'"'"'))' bdist_wheel -d 'C:\Users\USREB1\AppData\Local\Temp\pip-wheel-qghofp8x'
cwd: C:\Users\USERB
1\AppData\Local\Temp\pip-install-juo3afv7\cv-algorithms_c69eb1f14e86421ba8e084ddba8405c2\

LINK : warning LNK4044: unrecognized option '/g'; ignored
LINK : error LNK2001: unresolved external symbol PyInit__cv_algorithms
build\temp.win-amd64-3.6\Release\src_cv_algorithms.cp36-win_amd64.lib : fatal error LNK1120: 1 unresolved externals
error: command 'C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\BIN\x86_amd64\link.exe' failed with exit status 1120

ERROR: Failed building wheel for cv-algorithms

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.