locate-pixelcolor-numba


Namelocate-pixelcolor-numba JSON
Version 0.11 PyPI version JSON
download
home_pagehttps://github.com/hansalemaos/locate_pixelcolor_numba
SummaryRGB search with numba - 2-3 x faster than numpy
upload_time2023-04-15 00:40:53
maintainer
docs_urlNone
authorJohannes Fischer
requires_python
licenseMIT
keywords numba aot compiled rgb search
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # RGB search with numba - 2-3 x faster than numpy 

### pip install locate-pixelcolor-numba


### Important!
This is a compiled .pyd file (Numba AOT), if you can't import it, run the following code to generate a new pyd file, and replace it with the old .pyd file.


```python
from numba_aot_compiler import compnumba #pip install numba-aot-compiler
import numpy as np
from numba import uint8, uint16


def search_colors(r, g, b, rgbs, divider):
    res = np.zeros(b.shape, dtype=np.uint16)
    res2 = np.zeros(b.shape, dtype=np.uint16)
    zaehler = 0
    for rgb in rgbs:
        rr, gg, bb = rgb
        for i in range(r.shape[0]):
            if r[i] == rr:
                if g[i] == gg:
                    if b[i] == bb:
                        dvquot, dvrem = divmod(i, divider)
                        res[zaehler] = dvquot
                        res2[zaehler] = dvrem
                        zaehler = zaehler + 1
    results = np.dstack((res[:zaehler], res2[:zaehler]))
    return results


compi2 = compnumba(
    fu=search_colors,
    funcname="search_colors",
    file="searchcolorsnumba",
    folder="locate_pixelcolor_numba",
    signature=(uint8[:], uint8[:], uint8[:], uint8[:, :], uint16),
    parallel=True,
    fastmath=True,
    nogil=True,
)
```

### How to use it

```python
from locate_pixelcolor_numba import search_colors
import cv2
import time
import numpy as np
pic = cv2.imread(r"pexels-alex-andrews-2295744.jpg") # https://www.pexels.com/pt-br/foto/foto-da-raposa-sentada-no-chao-2295744/
colors = np.array([(66,  71,  69),(62,  67,  65),(144, 155, 153),(52,  57,  55),(127, 138, 136),(53,  58,  56),(51,  56,  54),(32,  27,  18),(24,  17,   8),],dtype=np.uint8)
search_colors(pic,colors)
Out[2]: 
array([[[   0, 4522],
        [   3, 4522],
        [   3, 4523],
        ...,
        [6622, 4522],
        [6622, 4523],
        [6622, 4524]]], dtype=uint16)
%timeit search_colors(pic,colors)
413 ms ± 1.22 ms per loop (mean ± std. dev. of 7 runs, 1 loop each)

# More benchmarks: https://github.com/hansalemaos/locate_pixelcolor_cpp

```

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/hansalemaos/locate_pixelcolor_numba",
    "name": "locate-pixelcolor-numba",
    "maintainer": "",
    "docs_url": null,
    "requires_python": "",
    "maintainer_email": "",
    "keywords": "numba,aot,compiled,rgb,search",
    "author": "Johannes Fischer",
    "author_email": "aulasparticularesdealemaosp@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/00/59/e1dfb51c225699388d671a4eac77cbe6f633a2dd5ac5e5e6d6f1a8789d60/locate_pixelcolor_numba-0.11.tar.gz",
    "platform": null,
    "description": "# RGB search with numba - 2-3 x faster than numpy \r\n\r\n### pip install locate-pixelcolor-numba\r\n\r\n\r\n### Important!\r\nThis is a compiled .pyd file (Numba AOT), if you can't import it, run the following code to generate a new pyd file, and replace it with the old .pyd file.\r\n\r\n\r\n```python\r\nfrom numba_aot_compiler import compnumba #pip install numba-aot-compiler\r\nimport numpy as np\r\nfrom numba import uint8, uint16\r\n\r\n\r\ndef search_colors(r, g, b, rgbs, divider):\r\n    res = np.zeros(b.shape, dtype=np.uint16)\r\n    res2 = np.zeros(b.shape, dtype=np.uint16)\r\n    zaehler = 0\r\n    for rgb in rgbs:\r\n        rr, gg, bb = rgb\r\n        for i in range(r.shape[0]):\r\n            if r[i] == rr:\r\n                if g[i] == gg:\r\n                    if b[i] == bb:\r\n                        dvquot, dvrem = divmod(i, divider)\r\n                        res[zaehler] = dvquot\r\n                        res2[zaehler] = dvrem\r\n                        zaehler = zaehler + 1\r\n    results = np.dstack((res[:zaehler], res2[:zaehler]))\r\n    return results\r\n\r\n\r\ncompi2 = compnumba(\r\n    fu=search_colors,\r\n    funcname=\"search_colors\",\r\n    file=\"searchcolorsnumba\",\r\n    folder=\"locate_pixelcolor_numba\",\r\n    signature=(uint8[:], uint8[:], uint8[:], uint8[:, :], uint16),\r\n    parallel=True,\r\n    fastmath=True,\r\n    nogil=True,\r\n)\r\n```\r\n\r\n### How to use it\r\n\r\n```python\r\nfrom locate_pixelcolor_numba import search_colors\r\nimport cv2\r\nimport time\r\nimport numpy as np\r\npic = cv2.imread(r\"pexels-alex-andrews-2295744.jpg\") # https://www.pexels.com/pt-br/foto/foto-da-raposa-sentada-no-chao-2295744/\r\ncolors = np.array([(66,  71,  69),(62,  67,  65),(144, 155, 153),(52,  57,  55),(127, 138, 136),(53,  58,  56),(51,  56,  54),(32,  27,  18),(24,  17,   8),],dtype=np.uint8)\r\nsearch_colors(pic,colors)\r\nOut[2]: \r\narray([[[   0, 4522],\r\n        [   3, 4522],\r\n        [   3, 4523],\r\n        ...,\r\n        [6622, 4522],\r\n        [6622, 4523],\r\n        [6622, 4524]]], dtype=uint16)\r\n%timeit search_colors(pic,colors)\r\n413 ms \u00c2\u00b1 1.22 ms per loop (mean \u00c2\u00b1 std. dev. of 7 runs, 1 loop each)\r\n\r\n# More benchmarks: https://github.com/hansalemaos/locate_pixelcolor_cpp\r\n\r\n```\r\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "RGB search with numba - 2-3 x faster than numpy",
    "version": "0.11",
    "split_keywords": [
        "numba",
        "aot",
        "compiled",
        "rgb",
        "search"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "d68b3ea90f7cded847ae5c284e649c6990f5520242c7b281856ab418843007d2",
                "md5": "b20328de20e10428f40736c3b9bfae81",
                "sha256": "c8943a7425073654ad77d459da76d09bed5cfbea2c9b9c29c3f2abf005091a5d"
            },
            "downloads": -1,
            "filename": "locate_pixelcolor_numba-0.11-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "b20328de20e10428f40736c3b9bfae81",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": null,
            "size": 23699,
            "upload_time": "2023-04-15T00:40:51",
            "upload_time_iso_8601": "2023-04-15T00:40:51.108885Z",
            "url": "https://files.pythonhosted.org/packages/d6/8b/3ea90f7cded847ae5c284e649c6990f5520242c7b281856ab418843007d2/locate_pixelcolor_numba-0.11-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "0059e1dfb51c225699388d671a4eac77cbe6f633a2dd5ac5e5e6d6f1a8789d60",
                "md5": "c32ba8c68d6d919885dd4161876bb5ee",
                "sha256": "a67a601cc616ad6c82aba1e4f6f543f9c68a5e88ffdaf7b7d0c1377cac9af12b"
            },
            "downloads": -1,
            "filename": "locate_pixelcolor_numba-0.11.tar.gz",
            "has_sig": false,
            "md5_digest": "c32ba8c68d6d919885dd4161876bb5ee",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": null,
            "size": 23625,
            "upload_time": "2023-04-15T00:40:53",
            "upload_time_iso_8601": "2023-04-15T00:40:53.271785Z",
            "url": "https://files.pythonhosted.org/packages/00/59/e1dfb51c225699388d671a4eac77cbe6f633a2dd5ac5e5e6d6f1a8789d60/locate_pixelcolor_numba-0.11.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-04-15 00:40:53",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "github_user": "hansalemaos",
    "github_project": "locate_pixelcolor_numba",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "requirements": [],
    "lcname": "locate-pixelcolor-numba"
}
        
Elapsed time: 0.08448s