Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/robotpy/pynivision

Archived obsolete python wrappers for NI Vision (nivision)
https://github.com/robotpy/pynivision

Last synced: 1 day ago
JSON representation

Archived obsolete python wrappers for NI Vision (nivision)

Awesome Lists containing this project

README

        

**Note**: This repository is no longer maintained by the RobotPy project.
The successor to this project can be found at https://github.com/chrisjbillington/pynivision

********************************************
Python Wrappers for NI Vision (nivision)
********************************************

:Author: Peter Johnson, FRC Team 294
:Copyright: Copyright |copy| 2012 Peter Johnson

About
=======

`NI Vision`_ is a `National Instruments`_ image/vision processing library.
It is available for multiple platforms including Windows and the
CompactRIO. This project makes the functionality of NI Vision available
in the `Python`_ programming language.

.. _NI Vision: http://www.ni.com/vision/
.. _National Instruments: http://www.ni.com/
.. _Python: http://www.python.org/

Features
==========

* Full wrapping of all structures, enumerations, and functions.
* All functions raise a ``nivision.ImaqError`` exception if an error occurs,
rather than relying on nonzero or NULL return values.
* Output parameters are returned as a tuple (in parameter order). If the
function additionally returns a value, this is returned as the first
element of the tuple, followed by the output parameters.
* Count/size/length parameters that specify the length of an array are
handled implicitly by using Python's ``len()`` function. This includes
return values (which are returned as a sized array).
* Additional Pythonic helper functions (see Documentation_).
* Automatic memory management of Image and other data types (see
Documentation_).

Usage
=======

Read a JPEG file and print its dimensions (width and height)::

import nivision
img = nivision.imaqCreateImage(nivision.IMAQ_IMAGE_RGB)
nivision.Priv_ReadJPEGString(img, open('example.jpg', 'rb').read())
print(nivision.imaqGetImageSize(img))

Requirements
==============

An installed and licensed version of `NI Vision`_. Only the 2011 version has
been tested.

The wrappers currently require ctypes, so this library is currently not usable
on platforms that don't have ctypes. Unfortunately this includes `RobotPy`_ as
of this writing, but this is being worked on.

.. _RobotPy: https://github.com/robotpy/robotpy

The wrappers have only been tested on Python 3.x.

Installation
==============

On the robot, this will be installed automatically as of RobotPy 2015.0.1. Otherwise,
you can install it via pip:

pip install pynivision

Run ``install.bat`` or ``python setup.py install``.

Documentation
===============

The "NI Vision for LabWindows/CVI Function Reference" help file
(NIVisionCVI.chm) is currently the best "complete" reference. However, the
Python wrappers deviate from the C library in several important ways (see
Features_).

A few helper functions are provided due to the use of in/out parameters.

* ``imaqGetCores()``: Returns the number of cores available to NI Vision.
* ``imaqSetCores(customNumCores)``: Sets the number of cores available to NI
Vision.
* ``imaqUseMaxAvailableCores()``: Configures NI Vision to use the maximum
number of available processor cores.

``imaqDispose()`` is automatically called when the corresponding Python object
is garbage collected for ``Image`` and all other structures/arrays returned
by imaq functions. It is still ok to explicitly call ``imaqDispose()`` on
these objects (but be careful, as the underlying object will be immediately
freed even though the Python object is still accessible).

Implementation
================

Most of the wrapper code is generated by the ``gen_wrap.py`` script.
Hand-written Python code in ``ctypes_core_prefix.py`` and
``ctypes_core_suffix.py`` complements the automatically generated code. The
``gen_wrap.py`` script creates ``nivision/core.py`` which includes the contents
of the prefix and suffix Python files.

The ``gen_wrap.py`` script reads an ``.ini`` file for Pythonic customizations
to the wrappers such as automatic disposal and handling of sized values as
arrays. The .ini file used is automatically determined by the nivision
version in use (or can alternatively be specified on the command line).

As ``Priv_ReadJPEGString_C`` is not exported on current Windows distributions of
``nivissvc.dll``, a custom implementation that uses GDI+ has been written in
``nivision/private.py`` and ``nivision/gdiplus.py``.

License
=========

Copyright |copy| 2012 Peter Johnson.

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.

.. |copy| unicode:: 0xA9 .. copyright sign

.. vim: tw=80 et ts=3 sw=3 ft=rst fenc=utf-8