Locate RGB values in a picture! 40 x faster than PIL, 5 x faster than numpy
pip install locate-pixelcolor
from locate_pixelcolor import search_colors
# Let's use a 4525 x 6623 x 3 picture https://www.pexels.com/pt-br/foto/foto-da-raposa-sentada-no-chao-2295744/
import cv2
path = r"C:\Users\Gamer\Documents\Downloads\pexels-alex-andrews-2295744.jpg"
img = cv2.imread(path)
exa1 = search_colors(pic=img, colors=[(255, 255, 255)])
%timeit search_colors(pic=img, colors=[(255, 255, 255)])
96.8 ms ± 534 µs per loop (mean ± std. dev. of 7 runs, 10 loops each)
# You can search for up to 9 different colors at the same time:
search_colors(pic=img, colors=[(255, 255, 255), (0, 0, 0)])
%timeit search_colors(pic=img, colors=[(255, 255, 255),(0, 0, 0)])
132 ms ± 382 µs per loop (mean ± std. dev. of 7 runs, 10 loops each)
# Let's compare it with PIL
from PIL import Image
img = Image.open(path)
img = img.convert("RGB")
datas = img.getdata()
def get_coords_with_pil(col):
newData = []
for item in datas:
if item[0] == col[0] and item[1] == col[1] and item[2] == col[2]:
newData.append(item)
return newData
# %timeit get_coords_with_pil(col=(255, 255, 255))
# 3.34 s ± 51.4 ms per loop (mean ± std. dev. of 7 runs, 1 loop each)
Release files for locate-pixelcolor 0.10
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| locate_pixelcolor-0.10.tar.gz | 3.8 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| locate_pixelcolor-0.10-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 9.2 kB
Release files / locate_pixelcolor-0.10.tar.gz
| Download URL | locate_pixelcolor-0.10.tar.gz |
|---|---|
| Size | 3.8 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
9439a9e07a004e90bb0091d1b97ba900e15c0735fbcb1b65cf39dca393abaaf7
|
|
BLAKE2b-256 checksum How to use checksums |
d4a51c42851b74b30f8a81e2573bda560bb31d5e5ba3773ac8f25540994e019d
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.1 CPython/3.9.13
|
Release files / locate_pixelcolor-0.10-py3-none-any.whl
| Download URL | locate_pixelcolor-0.10-py3-none-any.whl |
|---|---|
| Size | 5.4 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
2fcf1faa97e86e93fd2e8ab93208a45ad2efb74517b0c267443533c8d1c51bc4
|
|
BLAKE2b-256 checksum How to use checksums |
a2eacacb1425d819c6cddff62ecf0d19cfa1b4e116f65f57609df985de4b61c8
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.1 CPython/3.9.13
|