Skip to main content

RGBA color search with Cython

Project description

RGBA color search with Cython

pip install cythonrgbasearch

Tested against Windows / Python 3.11 / Anaconda

Cython (and a C/C++ compiler) must be installed

from cythonrgbasearch import find_rgba_colors, find_rgb_colors
import cv2
import numpy as np

data = cv2.imread(r"C:\Users\hansc\Downloads\pexels-alex-andrews-2295744.jpg")
# 4525 x 6623 x 3 picture https://www.pexels.com/pt-br/foto/foto-da-raposa-sentada-no-chao-2295744/
data = np.ascontiguousarray(np.dstack([data, np.full(data.shape[:2], 0, dtype=np.uint8)]))
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)
colors1 = np.array([list((x.tolist())) + [0] for x in colors1], dtype=np.uint8)
ocol = np.array([[255, 255, 255, 0]], dtype=np.uint8)
r1 = find_rgba_colors(pic=data, colors=colors1, dummy_alpha=0)
r2 = find_rgba_colors(pic=data, colors=ocol, dummy_alpha=0)
r3 = find_rgb_colors(pic=data, colors=colors1)
r4 = find_rgb_colors(pic=data, colors=ocol)

# r1
# Out[4]:
# rec.array([(136, 138, 127, 0,    0,   38), ( 69,  71,  66, 0,    0, 4522),
#            ( 65,  67,  62, 0,    0, 4523), ...,
#            (  8,  17,  24, 0, 4524, 6620), (  8,  17,  24, 0, 4524, 6621),
#            (  8,  17,  24, 0, 4524, 6622)],
#           dtype=[('r', 'u1'), ('g', 'u1'), ('b', 'u1'), ('a', 'u1'), ('x', '<i8'), ('y', '<i8')])
# r2
# Out[5]:
# rec.array([(255, 255, 255, 0,  568, 5021), (255, 255, 255, 0,  586, 3064),
#            (255, 255, 255, 0,  612, 2812), ...,
#            (255, 255, 255, 0, 3752,  805), (255, 255, 255, 0, 3752,  806),
#            (255, 255, 255, 0, 3775, 1291)],
#           dtype=[('r', 'u1'), ('g', 'u1'), ('b', 'u1'), ('a', 'u1'), ('x', '<i8'), ('y', '<i8')])
# r3
# Out[6]:
# rec.array([(136, 138, 127,    0,   38), ( 69,  71,  66,    0, 4522),
#            ( 65,  67,  62,    0, 4523), ..., (  8,  17,  24, 4524, 6620),
#            (  8,  17,  24, 4524, 6621), (  8,  17,  24, 4524, 6622)],
#           dtype=[('r', 'u1'), ('g', 'u1'), ('b', 'u1'), ('x', '<i8'), ('y', '<i8')])
# r4
# Out[7]:
# rec.array([(255, 255, 255,  568, 5021), (255, 255, 255,  586, 3064),
#            (255, 255, 255,  612, 2812), ..., (255, 255, 255, 3752,  805),
#            (255, 255, 255, 3752,  806), (255, 255, 255, 3775, 1291)],
#           dtype=[('r', 'u1'), ('g', 'u1'), ('b', 'u1'), ('x', '<i8'), ('y', '<i8')])

Project details


Release history Release notifications | RSS feed

This version

0.10

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

cythonrgbasearch-0.10.tar.gz (22.4 kB view details)

Uploaded Source

Built Distribution

cythonrgbasearch-0.10-py3-none-any.whl (22.5 kB view details)

Uploaded Python 3

File details

Details for the file cythonrgbasearch-0.10.tar.gz.

File metadata

  • Download URL: cythonrgbasearch-0.10.tar.gz
  • Upload date:
  • Size: 22.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.5

File hashes

Hashes for cythonrgbasearch-0.10.tar.gz
Algorithm Hash digest
SHA256 6d42f4901d720763417bf31287834a938d00a77d5e856abf0b329c636cdb9b32
MD5 105636c5340903f693e2df5644713cc8
BLAKE2b-256 4caa43a49810f3c0ff5c66284c58684c0dfd32f627c9d6916a3325e5c2f30a07

See more details on using hashes here.

File details

Details for the file cythonrgbasearch-0.10-py3-none-any.whl.

File metadata

File hashes

Hashes for cythonrgbasearch-0.10-py3-none-any.whl
Algorithm Hash digest
SHA256 ec345cd5d500d17a6df8cea4cedb89028b46152b114a8bbd779d9dac4c0bf374
MD5 aef6b6d2f7b781fbebaeded7de7050ee
BLAKE2b-256 013e3d8c700ab9de17eee32c4b80d541bc271d23362265f893108e0a0bf1e308

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page