{"id":26229590,"url":"https://github.com/hansalemaos/locate_pixelcolor_cpppragma","last_synced_at":"2026-04-21T22:01:34.401Z","repository":{"id":152933765,"uuid":"627639325","full_name":"hansalemaos/locate_pixelcolor_cpppragma","owner":"hansalemaos","description":"Detect colors in images - 20 x faster than Numpy / 430 x faster than PIL","archived":false,"fork":false,"pushed_at":"2023-05-30T19:06:36.000Z","size":37,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-12-31T12:44:25.815Z","etag":null,"topics":["cpp","detect","dll","parallel","python","rgb"],"latest_commit_sha":null,"homepage":"https://pypi.org/project/locate-pixelcolor-cpppragma/","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/hansalemaos.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null}},"created_at":"2023-04-13T22:19:57.000Z","updated_at":"2023-05-30T19:08:50.000Z","dependencies_parsed_at":"2023-07-07T08:01:52.170Z","dependency_job_id":null,"html_url":"https://github.com/hansalemaos/locate_pixelcolor_cpppragma","commit_stats":{"total_commits":3,"total_committers":1,"mean_commits":3.0,"dds":0.0,"last_synced_commit":"59ca8909770cfa14b3624a6c9bd6f5c82e1d734e"},"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/hansalemaos/locate_pixelcolor_cpppragma","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hansalemaos%2Flocate_pixelcolor_cpppragma","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hansalemaos%2Flocate_pixelcolor_cpppragma/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hansalemaos%2Flocate_pixelcolor_cpppragma/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hansalemaos%2Flocate_pixelcolor_cpppragma/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/hansalemaos","download_url":"https://codeload.github.com/hansalemaos/locate_pixelcolor_cpppragma/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hansalemaos%2Flocate_pixelcolor_cpppragma/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":32112030,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-21T11:25:29.218Z","status":"ssl_error","status_checked_at":"2026-04-21T11:25:28.499Z","response_time":128,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.5:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["cpp","detect","dll","parallel","python","rgb"],"created_at":"2025-03-12T22:16:54.274Z","updated_at":"2026-04-21T22:01:34.382Z","avatar_url":"https://github.com/hansalemaos.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Detect colors in images - 20 x faster than Numpy / 430 x faster than PIL\r\n\r\n### pip install locate-pixelcolor-cpppragma\r\n\r\n#### Tested against Windows 10 / Python 3.10 / Anaconda\r\n\r\n### Important!\r\nThe module imports a function from a compiled .dll (C++). \r\nIf you get any import errors, install:  https://download.visualstudio.microsoft.com/download/pr/8b92f460-7e03-4c75-a139-e264a770758d/26C2C72FBA6438F5E29AF8EBC4826A1E424581B3C446F8C735361F1DB7BEFF72/VC_redist.x64.exe\r\n\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 locate_pixelcolor_cpppragma 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, cpus=5)\r\ncolors1=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)\r\nresus1 =  search_colors(pic=pic, colors=colors1, cpus=4)\r\n\r\n####################################################################\r\n%timeit resus0 = search_colors(pic=pic, colors=colors0, cpus=5)\r\n23.4 ms ± 40.6 µs per loop (mean ± std. dev. of 7 runs, 10 loops each) # 10.9 ms after last update\r\n\r\nb,g,r = pic[...,0],pic[...,1],pic[...,2]\r\n%timeit np.where(((b==255)\u0026(g==255)\u0026(r==255)))\r\n150 ms ± 209 µs per loop (mean ± std. dev. of 7 runs, 10 loops each)\r\n####################################################################\r\n%timeit resus1 =  search_colors(pic=pic, colors=colors1, cpus=4)\r\n46.6 ms ± 988 µs per loop (mean ± std. dev. of 7 runs, 10 loops each) # 43.6 after last update\r\n\r\n%timeit np.where(((b==66)\u0026(g==71)\u0026(r==69))|((b==62)\u0026(g==67)\u0026(r==65))|((b==144)\u0026(g==155)\u0026(r==153))|((b==52)\u0026(g==57)\u0026(r==55))|((b==127)\u0026(g==138)\u0026(r==136))|((b==53)\u0026(g==58)\u0026(r==56))|((b==51)\u0026(g==56)\u0026(r==54))|((b==32)\u0026(g==27)\u0026(r==18))|((b==24)\u0026(g==17)\u0026(r==8)))\r\n1 s ± 16.1 ms per loop (mean ± std. dev. of 7 runs, 1 loop each)\r\n####################################################################\r\n```\r\n\r\n\r\n### The C++ Code \r\n\r\n```cpp\r\n#include \u003comp.h\u003e\r\n#include \u003catomic\u003e  \r\nstd::atomic\u003cint\u003e value(0);\r\nint create_id() {\r\n    return value++;\r\n    }\r\n\r\n\r\nextern \"C\" __declspec(dllexport) void colorsearch(unsigned char *pic, unsigned char *colors, int width, int totallengthpic, int totallengthcolor, int *outputx, int *outputy, int *lastresult)\r\n{\r\n    value = 0;\r\n    int counter = 0;\r\n\r\n#pragma omp parallel reduction(+ : counter)\r\n    {\r\n\r\n\r\n        for (int i = 0; i \u003c= totallengthcolor; i += 3)\r\n        {\r\n            int r = colors[i];\r\n            int g = colors[i + 1];\r\n            int b = colors[i + 2];\r\n#pragma omp for schedule(static)            \r\n            for (int j = 0; j \u003c= totallengthpic; j += 3)\r\n            {\r\n                if ((r == pic[j]) \u0026\u0026 (g == pic[j + 1]) \u0026\u0026 (b == pic[j + 2]))\r\n                {\r\n\r\n#pragma omp critical\r\n                    {\r\n                        int dividend = j / 3;\r\n                        int quotient = dividend / width;\r\n                        int remainder = dividend % width;\r\n                        int upcounter = create_id();\r\n                        outputx[upcounter] = quotient;\r\n                        outputy[upcounter] = remainder;\r\n                        lastresult[0] = upcounter;\r\n                    }\r\n                }\r\n            }\r\n        }\r\n    }\r\n}\r\n\r\n\r\nextern \"C\" __declspec(dllexport) void colorsearch2(unsigned char *pic, unsigned char *colors, int width, int totallengthpic, int totallengthcolor, int *outputx, int *outputy, int *lastresult)\r\n{\r\n    value=0;\r\n    int counter = 0;\r\n\r\n#pragma omp parallel reduction(+ \\\r\n                               : counter)\r\n    {\r\n\r\n#pragma omp for schedule(static)\r\n        for (int i = 0; i \u003c= totallengthcolor; i += 3)\r\n        {\r\n        int r = colors[i];\r\n        int g = colors[i + 1];\r\n        int b = colors[i + 2];\r\n            for (int j = 0; j \u003c= totallengthpic; j += 3)\r\n            {\r\n                 if ((r == pic[j]) \u0026\u0026 (g == pic[j + 1]) \u0026\u0026 (b == pic[j + 2]))\r\n                {\r\n\r\n#pragma omp critical\r\n                    {\r\n                        int dividend = j / 3;\r\n                        int quotient = dividend / width;\r\n                        int remainder = dividend % width;\r\n                        int upcounter = create_id();\r\n                        outputx[upcounter] = quotient;\r\n                        outputy[upcounter] = remainder;\r\n                        lastresult[0] = upcounter;\r\n                    }\r\n                }\r\n            }\r\n        }\r\n    }\r\n}\r\n// Compile:\r\n// cl.exe /std:c++20 /fp:fast /EHsc /MT /Og /Oi /Ot /Oy /Ob3 /GF /Gy /MD /openmp /LD clooppra.cpp /Fe:clooppra.dll\r\n// or\r\n// cl.exe /std:c++20 /fp:fast /EHsc /O2 /MD /openmp /LD clooppra.cpp /Fe:clooppra.dll","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhansalemaos%2Flocate_pixelcolor_cpppragma","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fhansalemaos%2Flocate_pixelcolor_cpppragma","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhansalemaos%2Flocate_pixelcolor_cpppragma/lists"}