Skip to main content

A simple Python package used by me and a friend at the university in the course 'Advanced Image, Video and Motion Analysis'

Project description

ZAOWR Package


This is a ZAOWR (Zaawansowana Analiza Obrazu, Wideo i Ruchu, eng. Advanced Image, Video, and Motion Analysis) Python package used by me and a friend at the university.

PyPI link to the package



Installing the package using pip

  1. PyPI MAIN
    • Linux
      python3 -m pip install --upgrade zaowr-polsl-kisiel
      

    • Windows
      py -m pip install --upgrade zaowr-polsl-kisiel
      

  2. TestPyPI
    • Linux
      python3 -m pip install --index-url https://test.pypi.org/simple/ --upgrade zaowr-polsl-kisiel
      

    • Windows
      py -m pip install --index-url https://test.pypi.org/simple/ --upgrade zaowr-polsl-kisiel
      


Removing the package using pip


python3 -m pip uninstall zaowr-polsl-kisiel


Creating virtual environment and installing the package


[!NOTE]

Complete instructions on managing Python virtual environments

can be found here.


  1. Create project directory and open it (directory where you will create your files and where the venv will be created)
    testDir=/home/user/test
    
    mkdir -p $testDir
    
    cd $testDir
    

  2. Create venv
    python -m venv ENV_NAME
    

  3. [!NOTE]

    ENV_NAME is the name of your venv, so you can change it however you like


  4. Activate the venv (while in the project directory)
    source ENV_NAME/bin/activate
    

    or

    . ENV_NAME/bin/activate
    

  5. Install the package from PyPI
    python3 -m pip install --upgrade zaowr-polsl-kisiel
    

  6. (ADDITIONAL COMMAND) If you want to deactivate the currently active venv
    deactivate
    

  7. (ADDITIONAL COMMAND) To reactivate the venv, navigate to the path where you created the venv and source it again (command shown above in section number 3)


Automate building and uploading with Makefile - DEV Tutorial

In the project directory run make. This command will run the Makefile, which performs actions listed below:

  • remove old version of the package,
  • ask which version we want to update (major, minor, patch) and increment it automatically, push the changes to GitHub with new tag,
  • build a new version,
  • upload the package to PyPI,
  • upload the package to TestPyPI.

  1. Test the Makefile
    make --dry-run
    

  2. Run the Makefile
    make
    


Building package - DEV Tutorial based on official DOCS

  1. Install pip
    python3 -m pip install --upgrade pip
    

  2. Prepare files and directories
    directory_used_for_package/
    ├── LICENSE
    ├── pyproject.toml
    ├── README.md
    ├── src/
    │   └── name_of_the_package/
    │       ├── __init__.py
    │       └── example.py
    └── tests/
    

  3. Choose build backend (I chose setuptools)
    python3 -m pip install --upgrade setuptools
    

  4. Prepare pyproject.toml file (this package's configuration as an example)
    [build-system]
    requires = ["setuptools>=61.0"]
    build-backend = "setuptools.build_meta"
    
    [project]
    name = "zaowr_polsl_kisiel"
    dynamic = ["version", "dependencies"]
    authors = [
      { name="Maksymilian Kisiel" },
    ]
    description = "A simple Python package used by me and a friend at the university in the course 'Advanced Image, Video and Motion Analysis'"
    readme = "README.md"
    requires-python = ">=3.8"
    classifiers = [
        "Programming Language :: Python :: 3",
        "License :: OSI Approved :: MIT License",
        "Operating System :: OS Independent",
    ]
    keywords = ["polsl", "zaowr", "2024", "IGT", "ZAOWR"]
    
    [tool.setuptools.dynamic]
    version = {attr = "zaowr_polsl_kisiel.__version__"}  # any module attribute compatible with ast.literal_eval
    dependencies = {file = ["requirements.txt"]}
    
    [project.urls]
    Homepage = "https://github.com/revalew/zaowr-py-package"
    Issues = "https://github.com/revalew/zaowr-py-package/issues"
    

  5. [!NOTE]

    requirements.txt file listed as "dependencies" was created using pip freeze > requirements.txt command

    which was executed in active python venv prepared for this uni course.

    Check my tutorial on managing venvs here.


  6. Prepare README.md file (customize this as you’d like)

  7. Prepare LICENSE file (MIT license shown below, more licenses can be found here)
    Copyright (c) 2018 The Python Packaging Authority
    
    Permission is hereby granted, free of charge, to any person obtaining a copy
    of this software and associated documentation files (the "Software"), to deal
    in the Software without restriction, including without limitation the rights
    to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
    copies of the Software, and to permit persons to whom the Software is
    furnished to do so, subject to the following conditions:
    
    The above copyright notice and this permission notice shall be included in all
    copies or substantial portions of the Software.
    
    THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
    IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
    FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
    AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
    LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
    OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
    SOFTWARE.
    

  8. Instal the build tool (if you encounter errors see official tutorial)
    python3 -m pip install --upgrade build
    

  9. Navigate to the folder where the pyproject.toml file is located

  10. Generate distribution archives
    python3 -m build
    

  11. Verify that the build was successful

    In the package there should now be dist/ directory. The tar.gz file is a source distribution whereas the .whl file is a built distribution. Newer pip versions preferentially install built distributions, but will fall back to source distributions if needed. You should always upload a source distribution and provide built distributions for the platforms your project is compatible with.


    dist/
    ├── zaowr_polsl_kisiel-0.0.0-py3-none-any.whl
    └── zaowr_polsl_kisiel-0.0.0.tar.gz
    

  12. Register the account in TestPyPI or PyPI (just follow the given instructions)

  13. Generate API token for TestPyPI or PyPI (just follow the given instructions, I added the credentials to $HOME/.pypirc using [pypi] and [testpypi] headers)

  14. Instal twine to upload the package
    python3 -m pip install --upgrade twine
    

  15. Upload the package
    • If you didn't add the credentials to $HOME/.pypirc, you will be prompted for username and password. Use __token__ for username and pypi-* (your API token) for password

    • PyPI
      python3 -m twine upload dist/*
      

    • TestPyPI
      python3 -m twine upload --repository testpypi dist/*
      

  16. After the upload succeeded, the package should be vievable on PyPI or TestPyPI

  17. Installing the package
    • PyPI
      python3 -m pip install --upgrade zaowr-polsl-kisiel
      

    • TestPyPI
      python3 -m pip install --upgrade --index-url https://test.pypi.org/simple/ --no-deps zaowr-polsl-kisiel
      

  18. [!NOTE]

    Here we additionally use --no-deps flag.

    Since TestPyPI doesn’t have the same packages as the live PyPI, it’s possible that attempting to install dependencies may fail or install something unexpected.


  19. Test the installation
    • Activate the venv (while in the project directory) - Skip this step if you are not using a virtual environment
      source ENV_NAME/bin/activate
      

      or

      . ENV_NAME/bin/activate
      

    • Launch python
      python3
      

    • Import the package
      from zaowr_polsl_kisiel import load_calibration
      

    • Locate the file with calibration params or create new file with structure shown below
      {
      	"mse": 5.984166144997382,
      	"rms": 0.5399844606283781,
      	"cameraMatrix": [
      		[1272.011234078766, 0.0, 1058.4537673810164],
      		[0.0, 1266.8726860857762, 617.7592332273604],
      		[0.0, 0.0, 1.0]
      	],
      	"distortionCoefficients": [
      		[-0.39935647747478337, 0.18200290247627665, 0.0020154085712910707, -0.012190829753206725, -0.04648398598417859]
      	],
      	"rotationVectors": [
      		[[0.014376302442723948], [0.1667778841470017], [0.018832348485715023]],
      		[[-0.3405035725192283], [0.526867552280327], [-0.13373157952652456]]
      	],
      	"translationVectors": [
      		[[71.27846898868391], [50.76036240921024], [1400.9402673825555]],
      		[[-476.2081267995082], [-120.35757569213392], [803.862414335442]]
      	]
      }
      

    • Try reading the params from file
      # remember to provide appropriate path to the calibration params
      # you can simply create a json file with structure shown above
      calibrationParams = load_calibration("../../tests/calibration_params/calibration_params.json")
      

    • Display the MSE value to test if the load succeeded
      print(calibrationParams["mse"])
      


Sources

This package has been prepared following this tutorial.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

zaowr_polsl_kisiel-0.0.5.tar.gz (13.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

zaowr_polsl_kisiel-0.0.5-py3-none-any.whl (11.9 kB view details)

Uploaded Python 3

File details

Details for the file zaowr_polsl_kisiel-0.0.5.tar.gz.

File metadata

  • Download URL: zaowr_polsl_kisiel-0.0.5.tar.gz
  • Upload date:
  • Size: 13.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.12.6

File hashes

Hashes for zaowr_polsl_kisiel-0.0.5.tar.gz
Algorithm Hash digest
SHA256 32849f6da9d416a35dc3739736606782e73ebbdf7ced014e6eb792bdbdb61fa0
MD5 6681bbd0d921e0baa90bf00cd29c3cec
BLAKE2b-256 a4b4a6aa385a566cd56ee142f09aaf437152e9a242e6b29c23678b8d0c0ebfae

See more details on using hashes here.

File details

Details for the file zaowr_polsl_kisiel-0.0.5-py3-none-any.whl.

File metadata

File hashes

Hashes for zaowr_polsl_kisiel-0.0.5-py3-none-any.whl
Algorithm Hash digest
SHA256 a83dfdd699d511513db4dff9f212fd4851ee123d05812abca7984d8915ddda6e
MD5 eb4307b815d9acddf5f184076c263c6a
BLAKE2b-256 145e790899597e0c844a1beacf4e2629b921371aa32707cb2d69a18e72c4d86f

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page