# Checks if colors are in image / Detects multiple colors in images - Fast Cython algorithm
### pip install cythoncolortools
#### Tested against Windows 10 / Python 3.11 / Anaconda
### Important!
The module will be compiled when you import it for the first time.
Cython and a C/C++ compiler must be installed!
### How to use it in Python
```python
import numpy as np
import cv2
from cythoncolortools import search_colors, are_any_colors_in_picture
# 4525 x 6623 x 3 picture https://www.pexels.com/pt-br/foto/foto-da-raposa-sentada-no-chao-2295744/
picpath = r"C:\Users\hansc\Downloads\pexels-alex-andrews-2295744.jpg"
pic = cv2.imread(picpath)
colors0 = np.array([[255, 255, 255]], dtype=np.uint8)
resus0 = search_colors(pic=pic, colors=colors0)
colors1 = 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,
)
resus1 = search_colors(pic=pic, colors=colors1)
print(resus1)
# %timeit search_colors(pic=pic, colors=colors1, add_results=True, cpus=5)
# %timeit search_colors(pic=pic, colors=colors1, add_results=False, cpus=5)
# %timeit search_colors(pic=pic, colors=colors0, add_results=True, cpus=5)
# %timeit search_colors(pic=pic, colors=colors0, add_results=False, cpus=5)
# %timeit search_colors(pic=pic, colors=colors1, add_results=True, cpus=1)
# %timeit search_colors(pic=pic, colors=colors1, add_results=False, cpus=1)
# %timeit search_colors(pic=pic, colors=colors0, add_results=True, cpus=1)
# %timeit search_colors(pic=pic, colors=colors0, add_results=False, cpus=1)
print(search_colors(pic=pic, colors=colors1, add_results=True, cpus=5))
print(search_colors(pic=pic, colors=colors1, add_results=False, cpus=5))
print(search_colors(pic=pic, colors=colors0, add_results=True, cpus=5))
print(search_colors(pic=pic, colors=colors0, add_results=False, cpus=5))
print(search_colors(pic=pic, colors=colors1, add_results=True, cpus=1))
print(search_colors(pic=pic, colors=colors1, add_results=False, cpus=1))
print(search_colors(pic=pic, colors=colors0, add_results=True, cpus=1))
print(search_colors(pic=pic, colors=colors0, add_results=False, cpus=1))
print(are_any_colors_in_picture(pic, colors1, cpus=-1))
print(are_any_colors_in_picture(pic, colors0, cpus=-1))
print(are_any_colors_in_picture(pic, colors1, cpus=1))
print(are_any_colors_in_picture(pic, colors0, cpus=1))
print(are_any_colors_in_picture(pic, [[111, 111, 121]], cpus=-1))
print(are_any_colors_in_picture(pic, [[111, 111, 121]], cpus=1))
# 57 ms ± 2.9 ms per loop (mean ± std. dev. of 7 runs, 10 loops each)
# 47.9 ms ± 1.02 ms per loop (mean ± std. dev. of 7 runs, 10 loops each)
# 22 ms ± 43.6 µs per loop (mean ± std. dev. of 7 runs, 10 loops each)
# 18.8 ms ± 162 µs per loop (mean ± std. dev. of 7 runs, 100 loops each)
# 260 ms ± 8.03 ms per loop (mean ± std. dev. of 7 runs, 1 loop each)
# 256 ms ± 283 µs per loop (mean ± std. dev. of 7 runs, 1 loop each)
# 25.7 ms ± 47.2 µs per loop (mean ± std. dev. of 7 runs, 10 loops each)
# 25.8 ms ± 110 µs per loop (mean ± std. dev. of 7 runs, 10 loops each)
# [[ 38 0 136 138 127]
# [ 1 1 153 155 144]
# [ 40 1 153 155 144]
# ...
# [1973 5903 65 67 62]
# [1952 5904 65 67 62]
# [2868 6041 65 67 62]]
# [[4522 0 69 71 66]
# [ 1 1 153 155 144]
# [ 40 1 153 155 144]
# ...
# [4522 6622 8 17 24]
# [4523 6622 8 17 24]
# [4524 6622 8 17 24]]
# [[ 38 0]
# [4522 0]
# [ 1 1]
# ...
# [2844 6622]
# [2854 6622]
# [2865 6622]]
# [[2085 832 255 255 255]
# [1692 858 255 255 255]
# [1688 896 255 255 255]
# ...
# [3526 5491 255 255 255]
# [3527 5491 255 255 255]
# [2491 5525 255 255 255]]
# [[2085 832]
# [1692 858]
# [1688 896]
# ...
# [3526 5491]
# [3527 5491]
# [2491 5525]]
# [[4522 0 69 71 66]
# [4522 3 69 71 66]
# [4523 3 69 71 66]
# ...
# [4522 6622 8 17 24]
# [4523 6622 8 17 24]
# [4524 6622 8 17 24]]
# [[4522 0]
# [4522 3]
# [4523 3]
# ...
# [4522 6622]
# [4523 6622]
# [4524 6622]]
# [[2085 832 255 255 255]
# [1692 858 255 255 255]
# [1688 896 255 255 255]
# ...
# [3526 5491 255 255 255]
# [3527 5491 255 255 255]
# [2491 5525 255 255 255]]
# [[2085 832]
# [1692 858]
# [1688 896]
# ...
# [3526 5491]
# [3527 5491]
# [2491 5525]]
# True
# True
# True
# True
# False
# False
```
Raw data
{
"_id": null,
"home_page": "https://github.com/hansalemaos/cythoncolortools",
"name": "cythoncolortools",
"maintainer": "",
"docs_url": null,
"requires_python": "",
"maintainer_email": "",
"keywords": "colors",
"author": "Johannes Fischer",
"author_email": "aulasparticularesdealemaosp@gmail.com",
"download_url": "https://files.pythonhosted.org/packages/09/41/d38ed0c220a6983b26d0b457f2f9b059a834d6270f5a313c2e621eaea67c/cythoncolortools-0.11.tar.gz",
"platform": null,
"description": "\r\n# Checks if colors are in image / Detects multiple colors in images - Fast Cython algorithm\r\n\r\n### pip install cythoncolortools\r\n\r\n#### Tested against Windows 10 / Python 3.11 / Anaconda\r\n\r\n### Important!\r\nThe module will be compiled when you import it for the first time. \r\nCython and a C/C++ compiler must be installed!\r\n\r\n### How to use it in Python \r\n\r\n```python\r\nimport numpy as np\r\nimport cv2\r\nfrom cythoncolortools import search_colors, are_any_colors_in_picture\r\n\r\n# 4525 x 6623 x 3 picture https://www.pexels.com/pt-br/foto/foto-da-raposa-sentada-no-chao-2295744/\r\npicpath = r\"C:\\Users\\hansc\\Downloads\\pexels-alex-andrews-2295744.jpg\"\r\npic = cv2.imread(picpath)\r\ncolors0 = np.array([[255, 255, 255]], dtype=np.uint8)\r\nresus0 = search_colors(pic=pic, colors=colors0)\r\ncolors1 = np.array(\r\n [\r\n (66, 71, 69),\r\n (62, 67, 65),\r\n (144, 155, 153),\r\n (52, 57, 55),\r\n (127, 138, 136),\r\n (53, 58, 56),\r\n (51, 56, 54),\r\n (32, 27, 18),\r\n (24, 17, 8),\r\n ],\r\n dtype=np.uint8,\r\n)\r\nresus1 = search_colors(pic=pic, colors=colors1)\r\nprint(resus1)\r\n\r\n\r\n# %timeit search_colors(pic=pic, colors=colors1, add_results=True, cpus=5)\r\n# %timeit search_colors(pic=pic, colors=colors1, add_results=False, cpus=5)\r\n\r\n# %timeit search_colors(pic=pic, colors=colors0, add_results=True, cpus=5)\r\n# %timeit search_colors(pic=pic, colors=colors0, add_results=False, cpus=5)\r\n\r\n# %timeit search_colors(pic=pic, colors=colors1, add_results=True, cpus=1)\r\n# %timeit search_colors(pic=pic, colors=colors1, add_results=False, cpus=1)\r\n\r\n# %timeit search_colors(pic=pic, colors=colors0, add_results=True, cpus=1)\r\n# %timeit search_colors(pic=pic, colors=colors0, add_results=False, cpus=1)\r\nprint(search_colors(pic=pic, colors=colors1, add_results=True, cpus=5))\r\nprint(search_colors(pic=pic, colors=colors1, add_results=False, cpus=5))\r\nprint(search_colors(pic=pic, colors=colors0, add_results=True, cpus=5))\r\nprint(search_colors(pic=pic, colors=colors0, add_results=False, cpus=5))\r\nprint(search_colors(pic=pic, colors=colors1, add_results=True, cpus=1))\r\nprint(search_colors(pic=pic, colors=colors1, add_results=False, cpus=1))\r\nprint(search_colors(pic=pic, colors=colors0, add_results=True, cpus=1))\r\nprint(search_colors(pic=pic, colors=colors0, add_results=False, cpus=1))\r\n\r\n\r\nprint(are_any_colors_in_picture(pic, colors1, cpus=-1))\r\nprint(are_any_colors_in_picture(pic, colors0, cpus=-1))\r\nprint(are_any_colors_in_picture(pic, colors1, cpus=1))\r\nprint(are_any_colors_in_picture(pic, colors0, cpus=1))\r\n\r\nprint(are_any_colors_in_picture(pic, [[111, 111, 121]], cpus=-1))\r\nprint(are_any_colors_in_picture(pic, [[111, 111, 121]], cpus=1))\r\n\r\n# 57 ms \u00b1 2.9 ms per loop (mean \u00b1 std. dev. of 7 runs, 10 loops each)\r\n# 47.9 ms \u00b1 1.02 ms per loop (mean \u00b1 std. dev. of 7 runs, 10 loops each)\r\n# 22 ms \u00b1 43.6 \u00b5s per loop (mean \u00b1 std. dev. of 7 runs, 10 loops each)\r\n# 18.8 ms \u00b1 162 \u00b5s per loop (mean \u00b1 std. dev. of 7 runs, 100 loops each)\r\n# 260 ms \u00b1 8.03 ms per loop (mean \u00b1 std. dev. of 7 runs, 1 loop each)\r\n# 256 ms \u00b1 283 \u00b5s per loop (mean \u00b1 std. dev. of 7 runs, 1 loop each)\r\n# 25.7 ms \u00b1 47.2 \u00b5s per loop (mean \u00b1 std. dev. of 7 runs, 10 loops each)\r\n# 25.8 ms \u00b1 110 \u00b5s per loop (mean \u00b1 std. dev. of 7 runs, 10 loops each)\r\n\r\n# [[ 38 0 136 138 127]\r\n# [ 1 1 153 155 144]\r\n# [ 40 1 153 155 144]\r\n# ...\r\n# [1973 5903 65 67 62]\r\n# [1952 5904 65 67 62]\r\n# [2868 6041 65 67 62]]\r\n# [[4522 0 69 71 66]\r\n# [ 1 1 153 155 144]\r\n# [ 40 1 153 155 144]\r\n# ...\r\n# [4522 6622 8 17 24]\r\n# [4523 6622 8 17 24]\r\n# [4524 6622 8 17 24]]\r\n# [[ 38 0]\r\n# [4522 0]\r\n# [ 1 1]\r\n# ...\r\n# [2844 6622]\r\n# [2854 6622]\r\n# [2865 6622]]\r\n# [[2085 832 255 255 255]\r\n# [1692 858 255 255 255]\r\n# [1688 896 255 255 255]\r\n# ...\r\n# [3526 5491 255 255 255]\r\n# [3527 5491 255 255 255]\r\n# [2491 5525 255 255 255]]\r\n# [[2085 832]\r\n# [1692 858]\r\n# [1688 896]\r\n# ...\r\n# [3526 5491]\r\n# [3527 5491]\r\n# [2491 5525]]\r\n# [[4522 0 69 71 66]\r\n# [4522 3 69 71 66]\r\n# [4523 3 69 71 66]\r\n# ...\r\n# [4522 6622 8 17 24]\r\n# [4523 6622 8 17 24]\r\n# [4524 6622 8 17 24]]\r\n# [[4522 0]\r\n# [4522 3]\r\n# [4523 3]\r\n# ...\r\n# [4522 6622]\r\n# [4523 6622]\r\n# [4524 6622]]\r\n# [[2085 832 255 255 255]\r\n# [1692 858 255 255 255]\r\n# [1688 896 255 255 255]\r\n# ...\r\n# [3526 5491 255 255 255]\r\n# [3527 5491 255 255 255]\r\n# [2491 5525 255 255 255]]\r\n# [[2085 832]\r\n# [1692 858]\r\n# [1688 896]\r\n# ...\r\n# [3526 5491]\r\n# [3527 5491]\r\n# [2491 5525]]\r\n# True\r\n# True\r\n# True\r\n# True\r\n# False\r\n# False\r\n```\r\n",
"bugtrack_url": null,
"license": "MIT",
"summary": "Checks if colors are in image / Detects multiple colors in images - Fast Cython algorithm",
"version": "0.11",
"project_urls": {
"Homepage": "https://github.com/hansalemaos/cythoncolortools"
},
"split_keywords": [
"colors"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "ab74e98bee9eee579fe74bc9c946f67c01921044d9ad6eb13c5f3dac3ef7e5c8",
"md5": "0eb462e7660e97bfb9b6e557fc6f3d4f",
"sha256": "c52dca62e97f39aef52212f72138a3f081a9bb664ee0ff024bc4bd0076277e73"
},
"downloads": -1,
"filename": "cythoncolortools-0.11-py3-none-any.whl",
"has_sig": false,
"md5_digest": "0eb462e7660e97bfb9b6e557fc6f3d4f",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": null,
"size": 24330,
"upload_time": "2024-02-05T02:28:16",
"upload_time_iso_8601": "2024-02-05T02:28:16.540374Z",
"url": "https://files.pythonhosted.org/packages/ab/74/e98bee9eee579fe74bc9c946f67c01921044d9ad6eb13c5f3dac3ef7e5c8/cythoncolortools-0.11-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "0941d38ed0c220a6983b26d0b457f2f9b059a834d6270f5a313c2e621eaea67c",
"md5": "7b31ab36c99026cdfb24da6af79d70d2",
"sha256": "88998c8a13d1209951cadafe1f59719d91ee88059a37585d457cbfaded331b26"
},
"downloads": -1,
"filename": "cythoncolortools-0.11.tar.gz",
"has_sig": false,
"md5_digest": "7b31ab36c99026cdfb24da6af79d70d2",
"packagetype": "sdist",
"python_version": "source",
"requires_python": null,
"size": 24217,
"upload_time": "2024-02-05T02:28:18",
"upload_time_iso_8601": "2024-02-05T02:28:18.218238Z",
"url": "https://files.pythonhosted.org/packages/09/41/d38ed0c220a6983b26d0b457f2f9b059a834d6270f5a313c2e621eaea67c/cythoncolortools-0.11.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-02-05 02:28:18",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "hansalemaos",
"github_project": "cythoncolortools",
"travis_ci": false,
"coveralls": false,
"github_actions": false,
"requirements": [
{
"name": "cycompi",
"specs": []
},
{
"name": "numpy",
"specs": []
}
],
"lcname": "cythoncolortools"
}