fastimgconcat


Namefastimgconcat JSON
Version 0.10 PyPI version JSON
download
home_pagehttps://github.com/hansalemaos/fastimgconcat
SummaryConcatenates a list of pictures (numpy arrays) without allocating new memory
upload_time2023-05-10 03:18:59
maintainer
docs_urlNone
authorJohannes Fischer
requires_python
licenseMIT
keywords concatenate numpy
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # Concatenates a list of pictures (numpy arrays) without allocating new memory

## pip install fastimgconcat

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


```python
from fastimgconcat import temparrays,fastconcat_horizontal,fastconcat_vertical
import numpy as np
import random
import cv2

# This code demonstrates the usage of the fastconcat_vertical()
# function to concatenate pictures (numpy arrays)
# vertically in a
# faster and more efficient way. 
# The fastconcat_vertical() function takes a list of numpy arrays and concatenates
# them vertically without allocating new memory. It is recommended to use this 
# function when you are #concatenating several pictures multiple times, and 
# the shape of the output array never (or rarely) # changes, e.g. streaming
# screenshots of 2 monitors.

# Initialize the height, width and RGB values for the numpy arrays.
height = 200
width = 500
rgbValues0 = np.zeros((height, width, 3), dtype=np.uint8)
rgbValues0[:] = [255, 0, 0]
rgbValues1 = np.zeros((height, width, 3), dtype=np.uint8)
rgbValues1[:] = [0, 0, 255]

# In the for loop, the fastconcat_vertical() 
# function is used to concatenate the numpy arrays vertically.
# If you want to concatenate them horizontally, 
# use fastconcat_horizontal() instead.

checkarraysize = True
for r in range(1000):
    fastconcat_vertical(
        [
            random.choice([rgbValues0, rgbValues1]),
            random.choice([rgbValues0, rgbValues1]),
        ],
        checkarraysize=checkarraysize,
    )
    checkarraysize = False  # If you check the array size each time, it is about 10% slower.

    # The values in temparrays.vertical / temparrays.horizontal 
    # will be changed the next iteration. Therefore,
    # it is recommended to process the output data right
    # after each iteration. If you still need the arrays,
    # copy them (e.g. temparrays.horizontal.copy()), but keep in mind that copying is expensive.

    # This code displays the concatenated image in the cv2 window "test".
    # If the 'q' key is pressed, the program breaks out of the loop and closes the window.
    cv2.imshow("test", temparrays.vertical)
    if cv2.waitKey(1) & 0xFF == ord("q"):
        break
cv2.destroyAllWindows()


```

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/hansalemaos/fastimgconcat",
    "name": "fastimgconcat",
    "maintainer": "",
    "docs_url": null,
    "requires_python": "",
    "maintainer_email": "",
    "keywords": "concatenate,numpy",
    "author": "Johannes Fischer",
    "author_email": "aulasparticularesdealemaosp@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/e3/7e/a7a4b730426a404a1dba97921805438c4d00fc7957b90f259b3a9a7ead8b/fastimgconcat-0.10.tar.gz",
    "platform": null,
    "description": "# Concatenates a list of pictures (numpy arrays) without allocating new memory\r\n\r\n## pip install fastimgconcat\r\n\r\n#### Tested against Windows 10 / Python 3.10 / Anaconda\r\n\r\n\r\n```python\r\nfrom fastimgconcat import temparrays,fastconcat_horizontal,fastconcat_vertical\r\nimport numpy as np\r\nimport random\r\nimport cv2\r\n\r\n# This code demonstrates the usage of the fastconcat_vertical()\r\n# function to concatenate pictures (numpy arrays)\r\n# vertically in a\r\n# faster and more efficient way. \r\n# The fastconcat_vertical() function takes a list of numpy arrays and concatenates\r\n# them vertically without allocating new memory. It is recommended to use this \r\n# function when you are #concatenating several pictures multiple times, and \r\n# the shape of the output array never (or rarely) # changes, e.g. streaming\r\n# screenshots of 2 monitors.\r\n\r\n# Initialize the height, width and RGB values for the numpy arrays.\r\nheight = 200\r\nwidth = 500\r\nrgbValues0 = np.zeros((height, width, 3), dtype=np.uint8)\r\nrgbValues0[:] = [255, 0, 0]\r\nrgbValues1 = np.zeros((height, width, 3), dtype=np.uint8)\r\nrgbValues1[:] = [0, 0, 255]\r\n\r\n# In the for loop, the fastconcat_vertical() \r\n# function is used to concatenate the numpy arrays vertically.\r\n# If you want to concatenate them horizontally, \r\n# use fastconcat_horizontal() instead.\r\n\r\ncheckarraysize = True\r\nfor r in range(1000):\r\n    fastconcat_vertical(\r\n        [\r\n            random.choice([rgbValues0, rgbValues1]),\r\n            random.choice([rgbValues0, rgbValues1]),\r\n        ],\r\n        checkarraysize=checkarraysize,\r\n    )\r\n    checkarraysize = False  # If you check the array size each time, it is about 10% slower.\r\n\r\n    # The values in temparrays.vertical / temparrays.horizontal \r\n    # will be changed the next iteration. Therefore,\r\n    # it is recommended to process the output data right\r\n    # after each iteration. If you still need the arrays,\r\n    # copy them (e.g. temparrays.horizontal.copy()), but keep in mind that copying is expensive.\r\n\r\n    # This code displays the concatenated image in the cv2 window \"test\".\r\n    # If the 'q' key is pressed, the program breaks out of the loop and closes the window.\r\n    cv2.imshow(\"test\", temparrays.vertical)\r\n    if cv2.waitKey(1) & 0xFF == ord(\"q\"):\r\n        break\r\ncv2.destroyAllWindows()\r\n\r\n\r\n```\r\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "Concatenates a list of pictures (numpy arrays) without allocating new memory",
    "version": "0.10",
    "project_urls": {
        "Homepage": "https://github.com/hansalemaos/fastimgconcat"
    },
    "split_keywords": [
        "concatenate",
        "numpy"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "5f792393248de40f9ee753602f9f80a49405af74a6fd23c4d0680375d09e2f96",
                "md5": "1fbd9a931e931f712c604ccf75677799",
                "sha256": "481b0d4c2b02a922e4ba98965333b226b76e301fdce6c08e70fb06d5a2c34cd3"
            },
            "downloads": -1,
            "filename": "fastimgconcat-0.10-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "1fbd9a931e931f712c604ccf75677799",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": null,
            "size": 21809,
            "upload_time": "2023-05-10T03:18:56",
            "upload_time_iso_8601": "2023-05-10T03:18:56.600708Z",
            "url": "https://files.pythonhosted.org/packages/5f/79/2393248de40f9ee753602f9f80a49405af74a6fd23c4d0680375d09e2f96/fastimgconcat-0.10-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "e37ea7a4b730426a404a1dba97921805438c4d00fc7957b90f259b3a9a7ead8b",
                "md5": "285aef919ec3621af3c4b8a32ed44213",
                "sha256": "dfba06a8313d97f0f433da5a4d8d927de7bba2cbb187d717f864b6d05a572d12"
            },
            "downloads": -1,
            "filename": "fastimgconcat-0.10.tar.gz",
            "has_sig": false,
            "md5_digest": "285aef919ec3621af3c4b8a32ed44213",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": null,
            "size": 21493,
            "upload_time": "2023-05-10T03:18:59",
            "upload_time_iso_8601": "2023-05-10T03:18:59.123232Z",
            "url": "https://files.pythonhosted.org/packages/e3/7e/a7a4b730426a404a1dba97921805438c4d00fc7957b90f259b3a9a7ead8b/fastimgconcat-0.10.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-05-10 03:18:59",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "hansalemaos",
    "github_project": "fastimgconcat",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "requirements": [],
    "lcname": "fastimgconcat"
}
        
Elapsed time: 0.07908s