getpartofimg


Namegetpartofimg JSON
Version 0.10 PyPI version JSON
download
home_pagehttps://github.com/hansalemaos/getpartofimg
SummaryExtracts a part of the image specified by width and height from the given image file path using OpenCV.
upload_time2023-07-17 15:45:06
maintainer
docs_urlNone
authorJohannes Fischer
requires_python
licenseMIT
keywords cv2 cut opencv
VCS
bugtrack_url
requirements a_cv2_easy_resize a_cv_imwrite_imread_plus numpy opencv_python
Travis-CI No Travis.
coveralls test coverage No coveralls.
            
# Extracts a part of the image specified by width and height from the given image file path using OpenCV.

## pip install getpartofimg 

#### Tested against Windows 10 / Python 3.10 / Anaconda 

Parameters:
-----------
image : Any
	The file path of the image from which a part will be extracted.

width : int
	The desired width of the extracted part.

height : int
	The desired height of the extracted part.

allow_resize : bool, optional (default=True)
	If True, allows resizing of the input image when the specified width or height is greater
	than the original image's dimensions.

Returns:
--------
numpy.ndarray
	The extracted part of the image as a NumPy array.

Raises:
-------
ValueError
	If the 'allow_resize' parameter is set to False and the specified width or height is greater than
	the original image's dimensions, a ValueError is raised with a message indicating that the image is too small.

Notes:
------
The function uses the 'cv2.imread_plus' function ( https://github.com/hansalemaos/a_cv_imwrite_imread_plus )
to read the image from the given file path. It then calculates
the possible ranges for extracting the desired part based on the image's dimensions and the specified width
and height. If the 'allow_resize' parameter is True, the function resizes the image using 'cv2.easy_resize_image'
( https://github.com/hansalemaos/a_cv2_easy_resize )
with the 'cv2.INTER_AREA' interpolation method to fit the desired part. Otherwise, it raises a ValueError.

Random starting coordinates within the allowable range are generated to extract the part of the image specified
by the given width and height.



```python
# Example usage:
import cv2
from getpartofimg import get_part_of_image
im = get_part_of_image(image=r"https://raw.githubusercontent.com/hansalemaos/screenshots/main/pic5.png", width=600, height=500, allow_resize=True)
cv2.imwrite('c:\\testimage.png', im)


```

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/hansalemaos/getpartofimg",
    "name": "getpartofimg",
    "maintainer": "",
    "docs_url": null,
    "requires_python": "",
    "maintainer_email": "",
    "keywords": "cv2,cut,opencv",
    "author": "Johannes Fischer",
    "author_email": "aulasparticularesdealemaosp@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/30/da/c0bb7334099a407c85b0befd644496a045418ec7d41114bfc43cfecf212b/getpartofimg-0.10.tar.gz",
    "platform": null,
    "description": "\r\n# Extracts a part of the image specified by width and height from the given image file path using OpenCV.\r\n\r\n## pip install getpartofimg \r\n\r\n#### Tested against Windows 10 / Python 3.10 / Anaconda \r\n\r\nParameters:\r\n-----------\r\nimage : Any\r\n\tThe file path of the image from which a part will be extracted.\r\n\r\nwidth : int\r\n\tThe desired width of the extracted part.\r\n\r\nheight : int\r\n\tThe desired height of the extracted part.\r\n\r\nallow_resize : bool, optional (default=True)\r\n\tIf True, allows resizing of the input image when the specified width or height is greater\r\n\tthan the original image's dimensions.\r\n\r\nReturns:\r\n--------\r\nnumpy.ndarray\r\n\tThe extracted part of the image as a NumPy array.\r\n\r\nRaises:\r\n-------\r\nValueError\r\n\tIf the 'allow_resize' parameter is set to False and the specified width or height is greater than\r\n\tthe original image's dimensions, a ValueError is raised with a message indicating that the image is too small.\r\n\r\nNotes:\r\n------\r\nThe function uses the 'cv2.imread_plus' function ( https://github.com/hansalemaos/a_cv_imwrite_imread_plus )\r\nto read the image from the given file path. It then calculates\r\nthe possible ranges for extracting the desired part based on the image's dimensions and the specified width\r\nand height. If the 'allow_resize' parameter is True, the function resizes the image using 'cv2.easy_resize_image'\r\n( https://github.com/hansalemaos/a_cv2_easy_resize )\r\nwith the 'cv2.INTER_AREA' interpolation method to fit the desired part. Otherwise, it raises a ValueError.\r\n\r\nRandom starting coordinates within the allowable range are generated to extract the part of the image specified\r\nby the given width and height.\r\n\r\n\r\n\r\n```python\r\n# Example usage:\r\nimport cv2\r\nfrom getpartofimg import get_part_of_image\r\nim = get_part_of_image(image=r\"https://raw.githubusercontent.com/hansalemaos/screenshots/main/pic5.png\", width=600, height=500, allow_resize=True)\r\ncv2.imwrite('c:\\\\testimage.png', im)\r\n\r\n\r\n```\r\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "Extracts a part of the image specified by width and height from the given image file path using OpenCV.",
    "version": "0.10",
    "project_urls": {
        "Homepage": "https://github.com/hansalemaos/getpartofimg"
    },
    "split_keywords": [
        "cv2",
        "cut",
        "opencv"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "9df814536520c673d6cbddd81badd3af3670d5573b5cd00e68cbb5e7cefe04c2",
                "md5": "81dc90db669bc5f57697da70d794868d",
                "sha256": "4d5c32f6d1c5b78274cd4a3efa8a9daf63d1bd40a9ed2692d37b17e56f8e21e3"
            },
            "downloads": -1,
            "filename": "getpartofimg-0.10-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "81dc90db669bc5f57697da70d794868d",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": null,
            "size": 50942,
            "upload_time": "2023-07-17T15:45:03",
            "upload_time_iso_8601": "2023-07-17T15:45:03.948638Z",
            "url": "https://files.pythonhosted.org/packages/9d/f8/14536520c673d6cbddd81badd3af3670d5573b5cd00e68cbb5e7cefe04c2/getpartofimg-0.10-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "30dac0bb7334099a407c85b0befd644496a045418ec7d41114bfc43cfecf212b",
                "md5": "2c319165afa569294c41b670d61b206a",
                "sha256": "fdf6e590b0bd67994b478d3c58e843c485da3674eb32e1759eda847ab83113b5"
            },
            "downloads": -1,
            "filename": "getpartofimg-0.10.tar.gz",
            "has_sig": false,
            "md5_digest": "2c319165afa569294c41b670d61b206a",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": null,
            "size": 49654,
            "upload_time": "2023-07-17T15:45:06",
            "upload_time_iso_8601": "2023-07-17T15:45:06.003079Z",
            "url": "https://files.pythonhosted.org/packages/30/da/c0bb7334099a407c85b0befd644496a045418ec7d41114bfc43cfecf212b/getpartofimg-0.10.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-07-17 15:45:06",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "hansalemaos",
    "github_project": "getpartofimg",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "requirements": [
        {
            "name": "a_cv2_easy_resize",
            "specs": []
        },
        {
            "name": "a_cv_imwrite_imread_plus",
            "specs": []
        },
        {
            "name": "numpy",
            "specs": []
        },
        {
            "name": "opencv_python",
            "specs": []
        }
    ],
    "lcname": "getpartofimg"
}
        
Elapsed time: 0.09365s