<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Recent changes to Tutorial</title><link>https://sourceforge.net/p/mvacquire/home/Tutorial/</link><description>Recent changes to Tutorial</description><atom:link href="https://sourceforge.net/p/mvacquire/home/Tutorial/feed" rel="self"/><language>en</language><lastBuildDate>Fri, 09 Dec 2011 12:52:09 -0000</lastBuildDate><atom:link href="https://sourceforge.net/p/mvacquire/home/Tutorial/feed" rel="self" type="application/rss+xml"/><item><title>WikiPage Tutorial modified by Gregor Thalhammer</title><link>https://sourceforge.net/p/mvacquire/home/Tutorial/</link><description>&lt;pre&gt;&lt;/pre&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Gregor Thalhammer</dc:creator><pubDate>Fri, 09 Dec 2011 12:52:09 -0000</pubDate><guid>https://sourceforge.net4369af9437892974ab70f368d43f52a01608e73a</guid></item><item><title>WikiPage tutorial modified by Gregor Thalhammer</title><link>https://sourceforge.net/p/mvacquire/home/tutorial/</link><description>**Please read tutorial.rst in the source code docs folder for up to date information!**

# Tutorial

The mv extension is designed to provide a very pythonic interface, such
that it can be easily used in an interactive environment like an IPython
shell.

## Initialization

Necessary for all interaction is the :py:class:\`mv.DeviceManager\`. On
loading the mv extension already creates an instance mv.dmg

    from mv import dmg

## Opening an imaging device

In an IPython shell, try typing 'dmg.' and hit TAB:

Installed devices (here: a BlueFOX USB camera and two virtual devices)
are accessible as attributes of the device manager instance dmg. They
are listed by their serial number. Acessing them opens a connection to
the device, which is automatically closed when the object goes out of
scope.

More detailed information about the available devices is returned by
:py:meth:\`DeviceManager.get\_device\_list\`.

## Getting an image

Some background: For image acquisition the underlying C library uses so
called 'request objects'. For each image one wants to acquire, such an
request object needs to be placed into a 'request queue'. For this, use
the :py:meth:\`\~mv.Device.image\_request\` method.

After an image has been acquired (or an timeout elapsed), the request
object is moved to the 'result queue'. To get a
:py:class:\`\~mv.ImageResult\` object, use
:py:meth:\`\~mv.Device.get\_image\`. This call blocks until a result is
available, or raises an :py:exc:\`\~mv.MVTimeoutError\` if a given
timeout has elapsed without a result getting ready.

To actually get the image data, use
:py:meth:\`\~mv.ImageResult.get\_buffer\`. This returns a \`memoryview\`
object to a copy of the image data. From this you can obtain a \`numpy\`
array with \`numpy.asarray\`.

For subsequent image acquisition, the request object needs to be
released, since only a limited number (default 4) of request objects is
available. For this, free (delete) the image result object obtained by
get\_image if you are done. A minimal command sequence might would be:

    dev.image_request()
    image_result = dev.get_image(timeout=1) #wait at most 1 second
    buf = image_result.get_buffer()
    del image_result

    img = np.asarray(buf)

## Changing camera settings

*All* available settings (also called a :py:class:\`\~mv.Property\`) are
organized in a tree like structure. They are accessible as attributes
(of attributes of attributes...), e.g.

    &gt;&gt;&gt; print dev.Setting.Base.Camera.Gain_dB
    1.000 dB

Code completion in ipython (with TAB key) displays a list of possible
attributes while typing. Alternatively, you get a list of child settings
with \`dir\`

    &gt;&gt;&gt; dir(dev.Setting.Base.Camera)
    ['Aoi',
     'BayerMosaicParity',
     'ChannelBitDepth',
     'FrameDelay_us',
     'Gain_dB',
     'ImageDirectory',
     'ImageRequestTimeout_ms',
     'ImageType',
     'PixelFormat',
     'PseudoFeatures',
     'TapsXGeometry',
     'TapsYGeometry',
     'TestImageBarWidth',
     'TestMode',
     'UserData']

Accessing a setting as an attribute returns its value as Python int,
long int, float, or bytes string, depending of the Property type.

For changing the value of a setting use the
:py:attr:\`\~mv.Property.value\` attribute:

    &gt;&gt;&gt; testmv.dev.Setting.Base.Camera.Gain_dB.value = 10.0
    &gt;&gt;&gt; print testmv.dev.Setting.Base.Camera.Gain_dB
    10.000 dB

Setting a Property value with a string argument is also possible, this
is especially useful for named integer properties.:

    &gt;&gt;&gt; dev.Setting.Base.Camera.TestMode.value = 'MovingMonoRamp'
    &gt;&gt;&gt; print dev.Setting.Base.Camera.TestMode
    MovingMonoRamp
</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Gregor Thalhammer</dc:creator><pubDate>Fri, 09 Dec 2011 12:44:17 -0000</pubDate><guid>https://sourceforge.net31c60cf8b0f9613eda6079a78ad80d8e00c60fbb</guid></item></channel></rss>