# Detects colors in images up to 8 times as fast as NumPy
### pip install locate-pixelcolor-cupy
If you haven't installed cupy yet, I recommend you installing it using conda:
conda install -c conda-forge cupy
#### Tested against Windows 10 / Python 3.10 / Anaconda
### Usage
```python
import numpy as np
import cv2
from locate_pixelcolor_cupy import search_colors
# 4525 x 6623 x 3 picture https://www.pexels.com/pt-br/foto/foto-da-raposa-sentada-no-chao-2295744/
picx = r"C:\Users\hansc\Downloads\pexels-alex-andrews-2295744.jpg"
pic = cv2.imread(picx)
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)
####################################################################
%timeit resus0 = search_colors(pic=pic, colors=colors0)
78.2 ms ± 1.29 ms per loop (mean ± std. dev. of 7 runs, 1 loop each)
b,g,r = pic[...,0],pic[...,1],pic[...,2]
%timeit np.where(((b==255)&(g==255)&(r==255)))
150 ms ± 209 µs per loop (mean ± std. dev. of 7 runs, 10 loops each)
####################################################################
%timeit resus1 = search_colors(pic=pic, colors=colors1)
139 ms ± 9.78 ms per loop (mean ± std. dev. of 7 runs, 1 loop each)
%timeit np.where(((b==66)&(g==71)&(r==69))|((b==62)&(g==67)&(r==65))|((b==144)&(g==155)&(r==153))|((b==52)&(g==57)&(r==55))|((b==127)&(g==138)&(r==136))|((b==53)&(g==58)&(r==56))|((b==51)&(g==56)&(r==54))|((b==32)&(g==27)&(r==18))|((b==24)&(g==17)&(r==8)))
1 s ± 16.1 ms per loop (mean ± std. dev. of 7 runs, 1 loop each)
####################################################################
```
Raw data
{
"_id": null,
"home_page": "https://github.com/hansalemaos/locate_pixelcolor_cupy",
"name": "locate-pixelcolor-cupy",
"maintainer": "",
"docs_url": null,
"requires_python": "",
"maintainer_email": "",
"keywords": "Cupy,image,search,rgb",
"author": "Johannes Fischer",
"author_email": "aulasparticularesdealemaosp@gmail.com",
"download_url": "https://files.pythonhosted.org/packages/90/c0/5470fc1f2d91effbee67ef32769044967cc392faa2900890bb2c6213b1b2/locate_pixelcolor_cupy-0.11.tar.gz",
"platform": null,
"description": "# Detects colors in images up to 8 times as fast as NumPy \r\n\r\n### pip install locate-pixelcolor-cupy\r\nIf you haven't installed cupy yet, I recommend you installing it using conda:\r\nconda install -c conda-forge cupy\r\n\r\n#### Tested against Windows 10 / Python 3.10 / Anaconda\r\n\r\n\r\n\r\n### Usage\r\n\r\n```python\r\n\r\nimport numpy as np\r\nimport cv2\r\nfrom locate_pixelcolor_cupy import search_colors\r\n# 4525 x 6623 x 3 picture https://www.pexels.com/pt-br/foto/foto-da-raposa-sentada-no-chao-2295744/\r\npicx = r\"C:\\Users\\hansc\\Downloads\\pexels-alex-andrews-2295744.jpg\"\r\npic = cv2.imread(picx)\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\n####################################################################\r\n%timeit resus0 = search_colors(pic=pic, colors=colors0)\r\n78.2 ms \u00c2\u00b1 1.29 ms per loop (mean \u00c2\u00b1 std. dev. of 7 runs, 1 loop each)\r\n\r\nb,g,r = pic[...,0],pic[...,1],pic[...,2]\r\n%timeit np.where(((b==255)&(g==255)&(r==255)))\r\n150 ms \u00c2\u00b1 209 \u00c2\u00b5s per loop (mean \u00c2\u00b1 std. dev. of 7 runs, 10 loops each)\r\n####################################################################\r\n%timeit resus1 = search_colors(pic=pic, colors=colors1)\r\n139 ms \u00c2\u00b1 9.78 ms per loop (mean \u00c2\u00b1 std. dev. of 7 runs, 1 loop each)\r\n\r\n%timeit np.where(((b==66)&(g==71)&(r==69))|((b==62)&(g==67)&(r==65))|((b==144)&(g==155)&(r==153))|((b==52)&(g==57)&(r==55))|((b==127)&(g==138)&(r==136))|((b==53)&(g==58)&(r==56))|((b==51)&(g==56)&(r==54))|((b==32)&(g==27)&(r==18))|((b==24)&(g==17)&(r==8)))\r\n1 s \u00c2\u00b1 16.1 ms per loop (mean \u00c2\u00b1 std. dev. of 7 runs, 1 loop each)\r\n####################################################################\r\n```\r\n",
"bugtrack_url": null,
"license": "MIT",
"summary": "Detects colors in images up to 8 times as fast as NumPy",
"version": "0.11",
"split_keywords": [
"cupy",
"image",
"search",
"rgb"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "2aa4a2817cd735cdbfa00cc13a8c6bf3d8ef488ceba131d186ae3643e0095c8f",
"md5": "e3659f6aa9f669799d2fcab904daca40",
"sha256": "b6ae5d31a4293e8f0c85d8cd1c36bf542b3f2deb55d36c98cb46cb3337fbb4c7"
},
"downloads": -1,
"filename": "locate_pixelcolor_cupy-0.11-py3-none-any.whl",
"has_sig": false,
"md5_digest": "e3659f6aa9f669799d2fcab904daca40",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": null,
"size": 6146,
"upload_time": "2023-04-15T00:32:46",
"upload_time_iso_8601": "2023-04-15T00:32:46.231973Z",
"url": "https://files.pythonhosted.org/packages/2a/a4/a2817cd735cdbfa00cc13a8c6bf3d8ef488ceba131d186ae3643e0095c8f/locate_pixelcolor_cupy-0.11-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "90c05470fc1f2d91effbee67ef32769044967cc392faa2900890bb2c6213b1b2",
"md5": "0830d1573fd3ee7bc69a0fa0d8672142",
"sha256": "db32de62358cea58d57c446032dcf55a7709ef0628310ecdd0a22baec921dbcc"
},
"downloads": -1,
"filename": "locate_pixelcolor_cupy-0.11.tar.gz",
"has_sig": false,
"md5_digest": "0830d1573fd3ee7bc69a0fa0d8672142",
"packagetype": "sdist",
"python_version": "source",
"requires_python": null,
"size": 4671,
"upload_time": "2023-04-15T00:32:48",
"upload_time_iso_8601": "2023-04-15T00:32:48.758483Z",
"url": "https://files.pythonhosted.org/packages/90/c0/5470fc1f2d91effbee67ef32769044967cc392faa2900890bb2c6213b1b2/locate_pixelcolor_cupy-0.11.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2023-04-15 00:32:48",
"github": true,
"gitlab": false,
"bitbucket": false,
"github_user": "hansalemaos",
"github_project": "locate_pixelcolor_cupy",
"travis_ci": false,
"coveralls": false,
"github_actions": false,
"requirements": [
{
"name": "cupy",
"specs": []
},
{
"name": "numpy",
"specs": []
}
],
"lcname": "locate-pixelcolor-cupy"
}