hikrobotcamlib


Namehikrobotcamlib JSON
Version 1.1.0 PyPI version JSON
download
home_pagehttps://gitlab.com/advian-oss/python-hikrobotcamlib/
SummaryPackage HIK Robotics camera drivers and some helpers
upload_time2023-11-09 13:50:09
maintainer
docs_urlNone
authorEero af Heurlin
requires_python>=3.8,<4.0
licenseMIT
keywords
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            ==============
hikrobotcamlib
==============

Package HIK Robotics camera drivers and a Pythonic wrappers to the data. You still need to install the SDK to get the
drivers/libraries.

This supports a subset of the platforms HIKRobotics' supports:

  - Linux: glibc (*not* MUSL, ie not Alpine) x86_64, aarch64 and armhf (probably, only tested on aarch64)
  - MacOS (idk if the dynlibs from vendor are both for Apple silicon and x86_64 but at least x86_64 works)

I've tried to make nice wrappers that should mostly handle things cleanly but this uses ctypes and calls external libraries
that are not real Python bindings (via cddl). One wrong move and everything crashes hard.

Usage
-----

The wrappers are documented and type-hinted, enjoy. TLDR:

.. code-block:: python3

    from typing import Optional
    import time

    from hikrobotcamlib Camera, DeviceList, Frame, DeviceTransport

    def frame_callback(frame: Frame, cam: Camera) -> None:
        """Handle frames from camera"""
        # TODO: Do something with the frame

    cam: Optional[Camera] = None
    for devinfo in DeviceList(DeviceTransport.GIGE | DeviceTransport.USB):
        cam = Camera(devinfo)
        break

    if not cam:
        raise RuntimeError("No camera")

    cam.open()
    cam.frame_callback = frame_callback
    cam.trigger_enable(False)
    cam.set_framerate(10.0)
    cam.start()
    time.sleep(2.5)
    cam.stop()
    cam.close()

Docker
------

For more controlled deployments and to get rid of "works on my computer" -syndrome, we always
make sure our software works under docker.

It's also a quick way to get started with a standard development environment.

SSH agent forwarding
^^^^^^^^^^^^^^^^^^^^

We need buildkit_::

    export DOCKER_BUILDKIT=1

.. _buildkit: https://docs.docker.com/develop/develop-images/build_enhancements/

And also the exact way for forwarding agent to running instance is different on OSX::

    export DOCKER_SSHAGENT="-v /run/host-services/ssh-auth.sock:/run/host-services/ssh-auth.sock -e SSH_AUTH_SOCK=/run/host-services/ssh-auth.sock"

and Linux::

    export DOCKER_SSHAGENT="-v $SSH_AUTH_SOCK:$SSH_AUTH_SOCK -e SSH_AUTH_SOCK"

Creating a development container
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

Build image, create container and start it::

    docker build --ssh default --target devel_shell -t hikrobotcamlib:devel_shell .
    docker create --name hikrobotcamlib_devel -v `pwd`":/app" -it `echo $DOCKER_SSHAGENT` hikrobotcamlib:devel_shell
    docker start -i hikrobotcamlib_devel

pre-commit considerations
^^^^^^^^^^^^^^^^^^^^^^^^^

If working in Docker instead of native env you need to run the pre-commit checks in docker too::

    docker exec -i hikrobotcamlib_devel /bin/bash -c "pre-commit install"
    docker exec -i hikrobotcamlib_devel /bin/bash -c "pre-commit run --all-files"

You need to have the container running, see above. Or alternatively use the docker run syntax but using
the running container is faster::

    docker run --rm -it -v `pwd`":/app" hikrobotcamlib:devel_shell -c "pre-commit run --all-files"

Test suite
^^^^^^^^^^

You can use the devel shell to run py.test when doing development, for CI use
the "tox" target in the Dockerfile::

    docker build --ssh default --target tox -t hikrobotcamlib:tox .
    docker run --rm -it -v `pwd`":/app" `echo $DOCKER_SSHAGENT` hikrobotcamlib:tox

Production docker
^^^^^^^^^^^^^^^^^

TODO: Remove this section if this is a library and not an application

There's a "production" target as well for running the application, remember to change that
architecture tag to arm64 if building on ARM::

    docker build --ssh default --target production -t hikrobotcamlib:amd64-latest .
    docker run --rm --network host -it --name hikrobotcamlib hikrobotcamlib:amd64-latest

Development
-----------

TODO: Remove the repo init from this document after you have done it.

TLDR:

- Create and activate a Python 3.11 virtualenv (assuming virtualenvwrapper)::

    mkvirtualenv -p `which python3.11` my_virtualenv

- change to a branch::

    git checkout -b my_branch

- install Poetry: https://python-poetry.org/docs/#installation
- Install project deps and pre-commit hooks::

    poetry install
    pre-commit install
    pre-commit run --all-files

- Ready to go.

Remember to activate your virtualenv whenever working on the repo, this is needed
because pylint and mypy pre-commit hooks use the "system" python for now (because reasons).


            

Raw data

            {
    "_id": null,
    "home_page": "https://gitlab.com/advian-oss/python-hikrobotcamlib/",
    "name": "hikrobotcamlib",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.8,<4.0",
    "maintainer_email": "",
    "keywords": "",
    "author": "Eero af Heurlin",
    "author_email": "eero.afheurlin@iki.fi",
    "download_url": "https://files.pythonhosted.org/packages/5f/f8/542615947da9db382cc7060ecc4f581836f8aee2b23cb87d0c0eb0b4c8cd/hikrobotcamlib-1.1.0.tar.gz",
    "platform": null,
    "description": "==============\nhikrobotcamlib\n==============\n\nPackage HIK Robotics camera drivers and a Pythonic wrappers to the data. You still need to install the SDK to get the\ndrivers/libraries.\n\nThis supports a subset of the platforms HIKRobotics' supports:\n\n  - Linux: glibc (*not* MUSL, ie not Alpine) x86_64, aarch64 and armhf (probably, only tested on aarch64)\n  - MacOS (idk if the dynlibs from vendor are both for Apple silicon and x86_64 but at least x86_64 works)\n\nI've tried to make nice wrappers that should mostly handle things cleanly but this uses ctypes and calls external libraries\nthat are not real Python bindings (via cddl). One wrong move and everything crashes hard.\n\nUsage\n-----\n\nThe wrappers are documented and type-hinted, enjoy. TLDR:\n\n.. code-block:: python3\n\n    from typing import Optional\n    import time\n\n    from hikrobotcamlib Camera, DeviceList, Frame, DeviceTransport\n\n    def frame_callback(frame: Frame, cam: Camera) -> None:\n        \"\"\"Handle frames from camera\"\"\"\n        # TODO: Do something with the frame\n\n    cam: Optional[Camera] = None\n    for devinfo in DeviceList(DeviceTransport.GIGE | DeviceTransport.USB):\n        cam = Camera(devinfo)\n        break\n\n    if not cam:\n        raise RuntimeError(\"No camera\")\n\n    cam.open()\n    cam.frame_callback = frame_callback\n    cam.trigger_enable(False)\n    cam.set_framerate(10.0)\n    cam.start()\n    time.sleep(2.5)\n    cam.stop()\n    cam.close()\n\nDocker\n------\n\nFor more controlled deployments and to get rid of \"works on my computer\" -syndrome, we always\nmake sure our software works under docker.\n\nIt's also a quick way to get started with a standard development environment.\n\nSSH agent forwarding\n^^^^^^^^^^^^^^^^^^^^\n\nWe need buildkit_::\n\n    export DOCKER_BUILDKIT=1\n\n.. _buildkit: https://docs.docker.com/develop/develop-images/build_enhancements/\n\nAnd also the exact way for forwarding agent to running instance is different on OSX::\n\n    export DOCKER_SSHAGENT=\"-v /run/host-services/ssh-auth.sock:/run/host-services/ssh-auth.sock -e SSH_AUTH_SOCK=/run/host-services/ssh-auth.sock\"\n\nand Linux::\n\n    export DOCKER_SSHAGENT=\"-v $SSH_AUTH_SOCK:$SSH_AUTH_SOCK -e SSH_AUTH_SOCK\"\n\nCreating a development container\n^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n\nBuild image, create container and start it::\n\n    docker build --ssh default --target devel_shell -t hikrobotcamlib:devel_shell .\n    docker create --name hikrobotcamlib_devel -v `pwd`\":/app\" -it `echo $DOCKER_SSHAGENT` hikrobotcamlib:devel_shell\n    docker start -i hikrobotcamlib_devel\n\npre-commit considerations\n^^^^^^^^^^^^^^^^^^^^^^^^^\n\nIf working in Docker instead of native env you need to run the pre-commit checks in docker too::\n\n    docker exec -i hikrobotcamlib_devel /bin/bash -c \"pre-commit install\"\n    docker exec -i hikrobotcamlib_devel /bin/bash -c \"pre-commit run --all-files\"\n\nYou need to have the container running, see above. Or alternatively use the docker run syntax but using\nthe running container is faster::\n\n    docker run --rm -it -v `pwd`\":/app\" hikrobotcamlib:devel_shell -c \"pre-commit run --all-files\"\n\nTest suite\n^^^^^^^^^^\n\nYou can use the devel shell to run py.test when doing development, for CI use\nthe \"tox\" target in the Dockerfile::\n\n    docker build --ssh default --target tox -t hikrobotcamlib:tox .\n    docker run --rm -it -v `pwd`\":/app\" `echo $DOCKER_SSHAGENT` hikrobotcamlib:tox\n\nProduction docker\n^^^^^^^^^^^^^^^^^\n\nTODO: Remove this section if this is a library and not an application\n\nThere's a \"production\" target as well for running the application, remember to change that\narchitecture tag to arm64 if building on ARM::\n\n    docker build --ssh default --target production -t hikrobotcamlib:amd64-latest .\n    docker run --rm --network host -it --name hikrobotcamlib hikrobotcamlib:amd64-latest\n\nDevelopment\n-----------\n\nTODO: Remove the repo init from this document after you have done it.\n\nTLDR:\n\n- Create and activate a Python 3.11 virtualenv (assuming virtualenvwrapper)::\n\n    mkvirtualenv -p `which python3.11` my_virtualenv\n\n- change to a branch::\n\n    git checkout -b my_branch\n\n- install Poetry: https://python-poetry.org/docs/#installation\n- Install project deps and pre-commit hooks::\n\n    poetry install\n    pre-commit install\n    pre-commit run --all-files\n\n- Ready to go.\n\nRemember to activate your virtualenv whenever working on the repo, this is needed\nbecause pylint and mypy pre-commit hooks use the \"system\" python for now (because reasons).\n\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "Package HIK Robotics camera drivers and some helpers",
    "version": "1.1.0",
    "project_urls": {
        "Homepage": "https://gitlab.com/advian-oss/python-hikrobotcamlib/",
        "Repository": "https://gitlab.com/advian-oss/python-hikrobotcamlib/"
    },
    "split_keywords": [],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "c046162a4f160dfbf195b8b50d57de551f3f40a0a4e67a456513b512160ee435",
                "md5": "6e8398704cb3e9922176c48a333fd83b",
                "sha256": "a769e503b1a0a4c71a260304198fa25a475d0c14076be51ca46ffd188f3b05f3"
            },
            "downloads": -1,
            "filename": "hikrobotcamlib-1.1.0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "6e8398704cb3e9922176c48a333fd83b",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.8,<4.0",
            "size": 31810,
            "upload_time": "2023-11-09T13:50:07",
            "upload_time_iso_8601": "2023-11-09T13:50:07.091973Z",
            "url": "https://files.pythonhosted.org/packages/c0/46/162a4f160dfbf195b8b50d57de551f3f40a0a4e67a456513b512160ee435/hikrobotcamlib-1.1.0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "5ff8542615947da9db382cc7060ecc4f581836f8aee2b23cb87d0c0eb0b4c8cd",
                "md5": "53a290af564ff58ffa3d7c3c4174038d",
                "sha256": "b147c8dd0716cb1ce8615054a75c6d3d7945d159918981dc5536968ad629d224"
            },
            "downloads": -1,
            "filename": "hikrobotcamlib-1.1.0.tar.gz",
            "has_sig": false,
            "md5_digest": "53a290af564ff58ffa3d7c3c4174038d",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.8,<4.0",
            "size": 29577,
            "upload_time": "2023-11-09T13:50:09",
            "upload_time_iso_8601": "2023-11-09T13:50:09.735025Z",
            "url": "https://files.pythonhosted.org/packages/5f/f8/542615947da9db382cc7060ecc4f581836f8aee2b23cb87d0c0eb0b4c8cd/hikrobotcamlib-1.1.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-11-09 13:50:09",
    "github": false,
    "gitlab": true,
    "bitbucket": false,
    "codeberg": false,
    "gitlab_user": "advian-oss",
    "gitlab_project": "python-hikrobotcamlib",
    "lcname": "hikrobotcamlib"
}
        
Elapsed time: 0.47967s