https://github.com/hansalemaos/locate_pixelcolor_cpp
Locate RGB values in a picture! Up to 10x faster than NumPy, 100x faster than PIL.
Science Score: 13.0%
This score indicates how likely this project is to be science-related based on various indicators:
-
○CITATION.cff file
-
✓codemeta.json file
Found codemeta.json file -
○.zenodo.json file
-
○DOI references
-
○Academic publication links
-
○Committers with academic emails
-
○Institutional organization owner
-
○JOSS paper metadata
-
○Scientific vocabulary similarity
Low similarity (6.2%) to scientific vocabulary
Keywords
Repository
Locate RGB values in a picture! Up to 10x faster than NumPy, 100x faster than PIL.
Basic Info
- Host: GitHub
- Owner: hansalemaos
- License: mit
- Language: Python
- Default Branch: main
- Homepage: https://pypi.org/project/locate-pixelcolor-cpp
- Size: 4.88 KB
Statistics
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
- Releases: 0
Topics
Metadata Files
README.MD
Locate RGB values in a picture! Up to 10x faster than NumPy, 100x faster than PIL.
How to install
pip install locate-pixelcolor-cpp
Please install this C++ compiler:
MSVC ..... C++ x64/x86 build tools from: https://visualstudio.microsoft.com/thank-you-downloading-visual-studio/?sku=Community&channel=Release&version=VS2022&source=VSLandingPage&passive=false&cid=2030
Localize the following files (Version number might vary) and copy their path: vcvarsall_bat = r"C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Auxiliary\Build\vcvarsall.bat"
cl_exe = r"C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.34.31933\bin\Hostx86\x64\cl.exe"
link_exe = r"C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.34.31933\bin\Hostx86\x64\link.exe"
Compile the code
python
from locate_pixelcolor_cpp import compile_localize_picture_color_with_cpp
compile_localize_picture_color_with_cpp(
vcvarsall_bat=r"C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Auxiliary\Build\vcvarsall.bat",
cl_exe=r"C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.34.31933\bin\Hostx86\x64\cl.exe",
link_exe=r"C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.34.31933\bin\Hostx86\x64\link.exe",
)
Benchmark
```python
Let's use a 4525 x 6623 x 3 picture https://www.pexels.com/pt-br/foto/foto-da-raposa-sentada-no-chao-2295744/
from locatepixelcolorcpp import searchcolors # The function can only be imported when the compilation was successful ( compilelocalizepicturecolorwithcpp ) import cv2 path=r"C:\Users\Gamer\Documents\Downloads\pexels-alex-andrews-2295744.jpg" im = cv2.imread(path)
colors=[(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),]
%timeit search_colors(im, colors=colors)
127 ms ± 3.61 ms per loop (mean ± std. dev. of 7 runs, 10 loops each)
from locatepixelcolor import searchcolors as search_colors2
first version with numexpr
https://github.com/hansalemaos/locate_pixelcolor
%timeit search_colors2(im,colors)
400 ms ± 18.9 ms per loop (mean ± std. dev. of 7 runs, 1 loop each)
import numpy as np b,g,r = im[...,0],im[...,1],im[...,2]
%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)
from PIL import Image img = Image.open(path) img = img.convert("RGB") datas = img.getdata()
def pi(): newData = [] for item in datas: if (item[0] == 66 and item[1] == 71 and item[2] == 69) or (item[0] == 62 and item[1] == 67 and item[2] == 65) or (item[0] == 144 and item[1] == 155 and item[2] == 153) or (item[0] == 52 and item[1] == 57 and item[2] == 55) or (item[0] == 127 and item[1] == 138 and item[2] == 136) or (item[0] == 53 and item[1] == 58 and item[2] == 56) or (item[0] == 51 and item[1] == 56 and item[2] == 54) or (item[0] == 32 and item[1] == 27 and item[2] == 18) or (item[0] == 24 and item[1] == 17 and item[2] == 8): newData.append(item) return newData %timeit pi()
10.6 s ± 51.6 ms per loop (mean ± std. dev. of 7 runs, 1 loop each)
One color
from locatepixelcolorcpp import search_colors import cv2 path=r"C:\Users\Gamer\Documents\Downloads\pexels-alex-andrews-2295744.jpg" im = cv2.imread(path)
%timeit search_colors(im, colors=[(255,255,255)])
75.3 ms ± 247 µs per loop (mean ± std. dev. of 7 runs, 10 loops each)
first version with numexpr
https://github.com/hansalemaos/locate_pixelcolor
from locatepixelcolor import searchcolors import cv2 path=r"C:\Users\Gamer\Documents\Downloads\pexels-alex-andrews-2295744.jpg" im = cv2.imread(path)
%timeit search_colors(im, colors=[(255,255,255)])
98 ms ± 422 µs per loop (mean ± std. dev. of 7 runs, 10 loops each)
b,g,r = im[...,0],im[...,1],im[...,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)
from PIL import Image img = Image.open(path) img = img.convert("RGB") datas = img.getdata() def getcoordswithpil(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 getcoordswithpil(col=(255,255,255)) 3.41 s ± 14.6 ms per loop (mean ± std. dev. of 7 runs, 1 loop each)
```
Owner
- Name: Hans Alemão
- Login: hansalemaos
- Kind: user
- Location: Sao Paulo
- Website: https://www.youtube.com/channel/UC3DeX0cPlJaLSD254T7fpdA
- Repositories: 860
- Profile: https://github.com/hansalemaos
A native German teacher living in Brazil who likes C++ accelerated Python
GitHub Events
Total
Last Year
Committers
Last synced: over 1 year ago
Top Committers
| Name | Commits | |
|---|---|---|
| Hans Alemão | a****p@g****m | 1 |
| hansalemaos | 7****s | 1 |
Issues and Pull Requests
Last synced: 6 months ago
All Time
- Total issues: 0
- Total pull requests: 0
- Average time to close issues: N/A
- Average time to close pull requests: N/A
- Total issue authors: 0
- Total pull request authors: 0
- Average comments per issue: 0
- Average comments per pull request: 0
- Merged pull requests: 0
- Bot issues: 0
- Bot pull requests: 0
Past Year
- Issues: 0
- Pull requests: 0
- Average time to close issues: N/A
- Average time to close pull requests: N/A
- Issue authors: 0
- Pull request authors: 0
- Average comments per issue: 0
- Average comments per pull request: 0
- Merged pull requests: 0
- Bot issues: 0
- Bot pull requests: 0
Top Authors
Issue Authors
Pull Request Authors
Top Labels
Issue Labels
Pull Request Labels
Packages
- Total packages: 1
-
Total downloads:
- pypi 11 last-month
- Total dependent packages: 0
- Total dependent repositories: 0
- Total versions: 1
- Total maintainers: 1
pypi.org: locate-pixelcolor-cpp
Locate RGB values in a picture! Up to 10x faster than NumPy, 100x faster than PIL.
- Homepage: https://github.com/hansalemaos/locate_pixelcolor_cpp
- Documentation: https://locate-pixelcolor-cpp.readthedocs.io/
- License: MIT
-
Latest release: 0.10
published about 3 years ago
Rankings
Maintainers (1)
Dependencies
- flexible_partial *
- numpy *
- opencv_python *
- touchtouch *