# Find occurrences of a needle image in a haystack image using multiprocessing and template matching.
## pip install needlefinder
### Tested against Python 3.11 / Windows 10
```python
# For different needle sizes
from needlefinder import find_needle_in_haystack
INTER_NEAREST = 0
INTER_LINEAR = 1
INTER_CUBIC = 2
INTER_AREA = 3
INTER_LANCZOS4 = 4
INTER_LINEAR_EXACT = 5
INTER_NEAREST_EXACT = 6
INTER_MAX = 7
WARP_FILL_OUTLIERS = 8
WARP_INVERSE_MAP = 16
interpolation = INTER_AREA
haystack = r"C:\savedsch\1349.png" # accepts almost everything - np.arrays / PIL / base64 / bytes ...
needle = r"C:\savedsch\1313.png"
df = find_needle_in_haystack(
haystack,
needle,
with_image_data=True,
percentage_min=80,
percentage_max=120,
steps=3,
thresh=0.85,
interpolation=interpolation,
pad_input=False,
mode="constant",
constant_values=0,
needlename="arrow",
usecache=True,
processes=3,
chunks=1,
print_stdout=False,
print_stderr=True,
)
print(df)
Parameters:
- haystack (str): Path to the haystack image file.
- needle (str): Path to the needle image file.
- with_image_data (bool, optional): If True, include image data in the result DataFrame. Default is True.
- percentage_min (int, optional): Minimum scale percentage for resizing the needle image. Default is 50.
- percentage_max (int, optional): Maximum scale percentage for resizing the needle image. Default is 150.
- steps (int, optional): Scale percentage steps for resizing the needle image. Default is 1.
- thresh (float, optional): Threshold for matching. Values below this threshold are considered non-matches. Default is 0.9.
- interpolation (int, optional): Interpolation method for resizing. Default is 4 (cv2.INTER_LANCZOS4).
- pad_input (bool, optional): If True, pad the input image. Default is False.
- mode (str, optional): Padding mode. Default is 'constant'.
- constant_values (int, optional): Constant value for padding. Default is 0.
- needlename (str, optional): Name of the needle used for identification in the result DataFrame. Default is 'arrow'.
- usecache (bool, optional): If True, use caching during multiprocessing. Default is True.
- processes (int, optional): Number of processes to use for multiprocessing. Default is 5.
- chunks (int, optional): Chunk size for multiprocessing. Default is 1.
- print_stdout (bool, optional): If True, print stdout during multiprocessing. Default is False.
- print_stderr (bool, optional): If True, print stderr during multiprocessing. Default is True.
Returns:
- DataFrame: Result DataFrame containing information about matched occurrences.
Columns include 'aa_start_x', 'aa_start_y', 'aa_scale_factor', 'aa_width', 'aa_height',
'aa_match', 'aa_end_x', 'aa_end_y', 'aa_center_x', 'aa_center_y', 'aa_area', 'aa_needlename'.
If with_image_data is True, additional columns include 'aa_screenshot', 'aa_r', 'aa_g', 'aa_b', 'aa_old_index'.
# for multiple needles and multiple haystacks
needles = {
"n1": r"C:\screeeni\16.png",
"n2": r"C:\screeeni\123.png",
"n3": r"C:\screeeni\130.png",
}
haystacks =[
r"C:\haystacks\161.png",
r"C:\haystacks\523.png",
r"C:\haystacks\630.png",]
INTER_NEAREST = 0
INTER_LINEAR = 1
INTER_CUBIC = 2
INTER_AREA = 3
INTER_LANCZOS4 = 4
INTER_LINEAR_EXACT = 5
INTER_NEAREST_EXACT = 6
INTER_MAX = 7
WARP_FILL_OUTLIERS = 8
WARP_INVERSE_MAP = 16
interpolation = INTER_AREA
dfneedles = find_needles_in_multi_haystacks(
haystacks=haystacks,
needles=needles,
with_image_data=True,
thresh=0.9,
pad_input=False,
mode="constant",
constant_values=0,
usecache=True,
processes=5,
chunks=1,
print_stdout=False,
print_stderr=True,
)
Find occurrences of multiple needle images in multiple haystack images using template matching.
Parameters:
- haystacks (List[str]): List of haystack images.
- needles (Dict[str, str]): Dictionary where keys are needle names and values are the needle images.
- with_image_data (bool, optional): If True, include image data in the result DataFrame. Default is True.
- thresh (float, optional): Threshold for matching. Values below this threshold are considered non-matches. Default is 0.9.
- pad_input (bool, optional): If True, pad the input image. Default is False.
- mode (str, optional): Padding mode. Default is 'constant'.
- constant_values (int, optional): Constant value for padding. Default is 0.
- usecache (bool, optional): If True, use caching during multiprocessing. Default is True.
- processes (int, optional): Number of processes to use for multiprocessing. Default is 5.
- chunks (int, optional): Chunk size for multiprocessing. Default is 1.
- print_stdout (bool, optional): If True, print stdout during multiprocessing. Default is False.
- print_stderr (bool, optional): If True, print stderr during multiprocessing. Default is True.
Returns:
- DataFrame: Result DataFrame containing information about matched occurrences.
Columns include 'aa_start_x', 'aa_start_y', 'aa_scale_factor', 'aa_width', 'aa_height',
'aa_match', 'aa_end_x', 'aa_end_y', 'aa_center_x', 'aa_center_y', 'aa_area', 'aa_needlename',
'aa_img_index'.
If with_image_data is True, additional columns include 'aa_screenshot', 'aa_r', 'aa_g', 'aa_b'.
Raises:
- Exception: If an error occurs during multiprocessing or matching.
Notes:
- The 'aa_old_index' column is retained from individual matches.
```
Raw data
{
"_id": null,
"home_page": "https://github.com/hansalemaos/needlefinder",
"name": "needlefinder",
"maintainer": "",
"docs_url": null,
"requires_python": "",
"maintainer_email": "",
"keywords": "multiprocessing,template,matching,rgb",
"author": "Johannes Fischer",
"author_email": "aulasparticularesdealemaosp@gmail.com",
"download_url": "https://files.pythonhosted.org/packages/ce/d6/ac04ca8cc015ceb3de4ecf800948d96bffd51163c1ee794c4adc7a539635/needlefinder-0.11.tar.gz",
"platform": null,
"description": "\r\n# Find occurrences of a needle image in a haystack image using multiprocessing and template matching.\r\n\r\n## pip install needlefinder\r\n\r\n### Tested against Python 3.11 / Windows 10\r\n\r\n\r\n```python\r\n\r\n# For different needle sizes \r\n\r\nfrom needlefinder import find_needle_in_haystack\r\n\r\nINTER_NEAREST = 0\r\nINTER_LINEAR = 1\r\nINTER_CUBIC = 2\r\nINTER_AREA = 3\r\nINTER_LANCZOS4 = 4\r\nINTER_LINEAR_EXACT = 5\r\nINTER_NEAREST_EXACT = 6\r\nINTER_MAX = 7\r\nWARP_FILL_OUTLIERS = 8\r\nWARP_INVERSE_MAP = 16\r\ninterpolation = INTER_AREA\r\nhaystack = r\"C:\\savedsch\\1349.png\" # accepts almost everything - np.arrays / PIL / base64 / bytes ...\r\nneedle = r\"C:\\savedsch\\1313.png\"\r\ndf = find_needle_in_haystack(\r\n haystack,\r\n needle,\r\n with_image_data=True,\r\n percentage_min=80,\r\n percentage_max=120,\r\n steps=3,\r\n thresh=0.85,\r\n interpolation=interpolation,\r\n pad_input=False,\r\n mode=\"constant\",\r\n constant_values=0,\r\n needlename=\"arrow\",\r\n usecache=True,\r\n processes=3,\r\n chunks=1,\r\n print_stdout=False,\r\n print_stderr=True,\r\n)\r\nprint(df)\r\n\r\nParameters:\r\n- haystack (str): Path to the haystack image file.\r\n- needle (str): Path to the needle image file.\r\n- with_image_data (bool, optional): If True, include image data in the result DataFrame. Default is True.\r\n- percentage_min (int, optional): Minimum scale percentage for resizing the needle image. Default is 50.\r\n- percentage_max (int, optional): Maximum scale percentage for resizing the needle image. Default is 150.\r\n- steps (int, optional): Scale percentage steps for resizing the needle image. Default is 1.\r\n- thresh (float, optional): Threshold for matching. Values below this threshold are considered non-matches. Default is 0.9.\r\n- interpolation (int, optional): Interpolation method for resizing. Default is 4 (cv2.INTER_LANCZOS4).\r\n- pad_input (bool, optional): If True, pad the input image. Default is False.\r\n- mode (str, optional): Padding mode. Default is 'constant'.\r\n- constant_values (int, optional): Constant value for padding. Default is 0.\r\n- needlename (str, optional): Name of the needle used for identification in the result DataFrame. Default is 'arrow'.\r\n- usecache (bool, optional): If True, use caching during multiprocessing. Default is True.\r\n- processes (int, optional): Number of processes to use for multiprocessing. Default is 5.\r\n- chunks (int, optional): Chunk size for multiprocessing. Default is 1.\r\n- print_stdout (bool, optional): If True, print stdout during multiprocessing. Default is False.\r\n- print_stderr (bool, optional): If True, print stderr during multiprocessing. Default is True.\r\n\r\nReturns:\r\n- DataFrame: Result DataFrame containing information about matched occurrences.\r\n Columns include 'aa_start_x', 'aa_start_y', 'aa_scale_factor', 'aa_width', 'aa_height',\r\n 'aa_match', 'aa_end_x', 'aa_end_y', 'aa_center_x', 'aa_center_y', 'aa_area', 'aa_needlename'.\r\n If with_image_data is True, additional columns include 'aa_screenshot', 'aa_r', 'aa_g', 'aa_b', 'aa_old_index'.\r\n\r\n\r\n# for multiple needles and multiple haystacks \r\n\r\nneedles = {\r\n \"n1\": r\"C:\\screeeni\\16.png\",\r\n \"n2\": r\"C:\\screeeni\\123.png\",\r\n \"n3\": r\"C:\\screeeni\\130.png\",\r\n}\r\n\r\nhaystacks =[\r\nr\"C:\\haystacks\\161.png\",\r\nr\"C:\\haystacks\\523.png\",\r\nr\"C:\\haystacks\\630.png\",]\r\n\r\nINTER_NEAREST = 0\r\nINTER_LINEAR = 1\r\nINTER_CUBIC = 2\r\nINTER_AREA = 3\r\nINTER_LANCZOS4 = 4\r\nINTER_LINEAR_EXACT = 5\r\nINTER_NEAREST_EXACT = 6\r\nINTER_MAX = 7\r\nWARP_FILL_OUTLIERS = 8\r\nWARP_INVERSE_MAP = 16\r\ninterpolation = INTER_AREA\r\ndfneedles = find_needles_in_multi_haystacks(\r\n haystacks=haystacks,\r\n needles=needles,\r\n with_image_data=True,\r\n thresh=0.9,\r\n pad_input=False,\r\n mode=\"constant\",\r\n constant_values=0,\r\n usecache=True,\r\n processes=5,\r\n chunks=1,\r\n print_stdout=False,\r\n print_stderr=True,\r\n)\r\n\r\nFind occurrences of multiple needle images in multiple haystack images using template matching.\r\n\r\nParameters:\r\n- haystacks (List[str]): List of haystack images.\r\n- needles (Dict[str, str]): Dictionary where keys are needle names and values are the needle images.\r\n- with_image_data (bool, optional): If True, include image data in the result DataFrame. Default is True.\r\n- thresh (float, optional): Threshold for matching. Values below this threshold are considered non-matches. Default is 0.9.\r\n- pad_input (bool, optional): If True, pad the input image. Default is False.\r\n- mode (str, optional): Padding mode. Default is 'constant'.\r\n- constant_values (int, optional): Constant value for padding. Default is 0.\r\n- usecache (bool, optional): If True, use caching during multiprocessing. Default is True.\r\n- processes (int, optional): Number of processes to use for multiprocessing. Default is 5.\r\n- chunks (int, optional): Chunk size for multiprocessing. Default is 1.\r\n- print_stdout (bool, optional): If True, print stdout during multiprocessing. Default is False.\r\n- print_stderr (bool, optional): If True, print stderr during multiprocessing. Default is True.\r\n\r\nReturns:\r\n- DataFrame: Result DataFrame containing information about matched occurrences.\r\n Columns include 'aa_start_x', 'aa_start_y', 'aa_scale_factor', 'aa_width', 'aa_height',\r\n 'aa_match', 'aa_end_x', 'aa_end_y', 'aa_center_x', 'aa_center_y', 'aa_area', 'aa_needlename',\r\n 'aa_img_index'.\r\n If with_image_data is True, additional columns include 'aa_screenshot', 'aa_r', 'aa_g', 'aa_b'.\r\n\r\nRaises:\r\n- Exception: If an error occurs during multiprocessing or matching.\r\n\r\nNotes:\r\n- The 'aa_old_index' column is retained from individual matches.\r\n\r\n```\r\n",
"bugtrack_url": null,
"license": "MIT",
"summary": "Find occurrences of a needle image in a haystack image using multiprocessing and template matching.",
"version": "0.11",
"project_urls": {
"Homepage": "https://github.com/hansalemaos/needlefinder"
},
"split_keywords": [
"multiprocessing",
"template",
"matching",
"rgb"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "e85e9c53d764e1f3c6e9ddec2c3f7706df206fc6a2b492674c5d2300774d1228",
"md5": "e322ec0261f0937d89367b81ab420b7d",
"sha256": "eb2c1e883585b07505973b519e70964f7361a2d6ce335ae18cb06806143a83d4"
},
"downloads": -1,
"filename": "needlefinder-0.11-py3-none-any.whl",
"has_sig": false,
"md5_digest": "e322ec0261f0937d89367b81ab420b7d",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": null,
"size": 83269,
"upload_time": "2023-11-13T05:44:07",
"upload_time_iso_8601": "2023-11-13T05:44:07.023799Z",
"url": "https://files.pythonhosted.org/packages/e8/5e/9c53d764e1f3c6e9ddec2c3f7706df206fc6a2b492674c5d2300774d1228/needlefinder-0.11-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "ced6ac04ca8cc015ceb3de4ecf800948d96bffd51163c1ee794c4adc7a539635",
"md5": "7940a19e5e25d0c9ed29300f253b1a7f",
"sha256": "172bd82c6110b5a757624b24615a85114729c6cc4da46d07863e25411817df1e"
},
"downloads": -1,
"filename": "needlefinder-0.11.tar.gz",
"has_sig": false,
"md5_digest": "7940a19e5e25d0c9ed29300f253b1a7f",
"packagetype": "sdist",
"python_version": "source",
"requires_python": null,
"size": 83222,
"upload_time": "2023-11-13T05:44:08",
"upload_time_iso_8601": "2023-11-13T05:44:08.829188Z",
"url": "https://files.pythonhosted.org/packages/ce/d6/ac04ca8cc015ceb3de4ecf800948d96bffd51163c1ee794c4adc7a539635/needlefinder-0.11.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2023-11-13 05:44:08",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "hansalemaos",
"github_project": "needlefinder",
"travis_ci": false,
"coveralls": false,
"github_actions": false,
"requirements": [],
"lcname": "needlefinder"
}