Skip to main content

Python Wrappers for NI Vision and IMAQdx

Project description

Author:

Peter Johnson, FRC Team 294

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.

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.

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 © 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.

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

pynivision-2015.0.0.tar.gz (58.0 kB view details)

Uploaded Source

File details

Details for the file pynivision-2015.0.0.tar.gz.

File metadata

File hashes

Hashes for pynivision-2015.0.0.tar.gz
Algorithm Hash digest
SHA256 820669867928a315724d909b0a3bfb8b09561360d025f362f10947b1b9affed9
MD5 1a78422a50bee47c03c1eb67088ee54e
BLAKE2b-256 bb8971daf4eccf2ede465c3ee0aa2a8bd558e3e1f36a097a47a354c06df34ab7

See more details on using hashes here.

Supported by

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