AVT相机arm版本SDK
This commit is contained in:
120
Vimba_6_0/VimbaPython/Source/vimba/c_binding/__init__.py
Normal file
120
Vimba_6_0/VimbaPython/Source/vimba/c_binding/__init__.py
Normal file
@@ -0,0 +1,120 @@
|
||||
"""BSD 2-Clause License
|
||||
|
||||
Copyright (c) 2019, Allied Vision Technologies GmbH
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions are met:
|
||||
|
||||
1. Redistributions of source code must retain the above copyright notice, this
|
||||
list of conditions and the following disclaimer.
|
||||
|
||||
2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
this list of conditions and the following disclaimer in the documentation
|
||||
and/or other materials provided with the distribution.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
||||
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
||||
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
-------------------------------------------------------------------------
|
||||
|
||||
NOTE: Vimba/Vmb naming convention.
|
||||
VimbaPython is based heavily on VimbaC, this submodule contains all wrapped types and functions
|
||||
of VimbaC. All VimbaC Types and Functions are prefixed with 'Vmb', this convention is kept for
|
||||
all python types interfacing with the C - Layer. VimbaC developers should be able to understand
|
||||
the interface to VimbaC and keeping the name convention helps a lot in that regard.
|
||||
|
||||
However prefixing everything with 'Vmb' is not required in VimbaPython, therefore most Types
|
||||
of the public API have no prefix.
|
||||
"""
|
||||
|
||||
# Suppress 'imported but unused' - Error from static style checker.
|
||||
# flake8: noqa: F401
|
||||
|
||||
__all__ = [
|
||||
# Exports from vimba_common
|
||||
'VmbInt8',
|
||||
'VmbUint8',
|
||||
'VmbInt16',
|
||||
'VmbUint16',
|
||||
'VmbInt32',
|
||||
'VmbUint32',
|
||||
'VmbInt64',
|
||||
'VmbUint64',
|
||||
'VmbHandle',
|
||||
'VmbBool',
|
||||
'VmbUchar',
|
||||
'VmbDouble',
|
||||
'VmbError',
|
||||
'VimbaCError',
|
||||
'VmbPixelFormat',
|
||||
'decode_cstr',
|
||||
'decode_flags',
|
||||
|
||||
# Exports from vimba_c
|
||||
'VmbInterface',
|
||||
'VmbAccessMode',
|
||||
'VmbFeatureData',
|
||||
'VmbFeaturePersist',
|
||||
'VmbFeatureVisibility',
|
||||
'VmbFeatureFlags',
|
||||
'VmbFrameStatus',
|
||||
'VmbFrameFlags',
|
||||
'VmbVersionInfo',
|
||||
'VmbInterfaceInfo',
|
||||
'VmbCameraInfo',
|
||||
'VmbFeatureInfo',
|
||||
'VmbFeatureEnumEntry',
|
||||
'VmbFrame',
|
||||
'VmbFeaturePersistSettings',
|
||||
'G_VIMBA_C_HANDLE',
|
||||
'VIMBA_C_VERSION',
|
||||
'EXPECTED_VIMBA_C_VERSION',
|
||||
'call_vimba_c',
|
||||
'build_callback_type',
|
||||
|
||||
# Exports from vimba_image_transform
|
||||
'VmbImage',
|
||||
'VmbImageInfo',
|
||||
'VmbDebayerMode',
|
||||
'VmbTransformInfo',
|
||||
'VIMBA_IMAGE_TRANSFORM_VERSION',
|
||||
'EXPECTED_VIMBA_IMAGE_TRANSFORM_VERSION',
|
||||
'call_vimba_image_transform',
|
||||
'PIXEL_FORMAT_TO_LAYOUT',
|
||||
'LAYOUT_TO_PIXEL_FORMAT',
|
||||
'PIXEL_FORMAT_CONVERTIBILITY_MAP',
|
||||
|
||||
# Exports from ctypes
|
||||
'byref',
|
||||
'sizeof',
|
||||
'create_string_buffer'
|
||||
]
|
||||
|
||||
from .vimba_common import VmbInt8, VmbUint8, VmbInt16, VmbUint16, VmbInt32, VmbUint32, \
|
||||
VmbInt64, VmbUint64, VmbHandle, VmbBool, VmbUchar, VmbDouble, VmbError, \
|
||||
VimbaCError, VmbPixelFormat, decode_cstr, decode_flags, \
|
||||
_select_vimba_home
|
||||
|
||||
from .vimba_c import VmbInterface, VmbAccessMode, VmbFeatureData, \
|
||||
VmbFeaturePersist, VmbFeatureVisibility, VmbFeatureFlags, VmbFrameStatus, \
|
||||
VmbFrameFlags, VmbVersionInfo, VmbInterfaceInfo, VmbCameraInfo, VmbFeatureInfo, \
|
||||
VmbFeatureEnumEntry, VmbFrame, VmbFeaturePersistSettings, \
|
||||
G_VIMBA_C_HANDLE, EXPECTED_VIMBA_C_VERSION, VIMBA_C_VERSION, call_vimba_c, \
|
||||
build_callback_type
|
||||
|
||||
from .vimba_image_transform import VmbImage, VmbImageInfo, VmbDebayerMode, \
|
||||
VIMBA_IMAGE_TRANSFORM_VERSION, \
|
||||
EXPECTED_VIMBA_IMAGE_TRANSFORM_VERSION, VmbTransformInfo, \
|
||||
call_vimba_image_transform, PIXEL_FORMAT_TO_LAYOUT, \
|
||||
LAYOUT_TO_PIXEL_FORMAT, PIXEL_FORMAT_CONVERTIBILITY_MAP
|
||||
|
||||
from ctypes import byref, sizeof, create_string_buffer
|
||||
772
Vimba_6_0/VimbaPython/Source/vimba/c_binding/vimba_c.py
Normal file
772
Vimba_6_0/VimbaPython/Source/vimba/c_binding/vimba_c.py
Normal file
@@ -0,0 +1,772 @@
|
||||
"""BSD 2-Clause License
|
||||
|
||||
Copyright (c) 2019, Allied Vision Technologies GmbH
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions are met:
|
||||
|
||||
1. Redistributions of source code must retain the above copyright notice, this
|
||||
list of conditions and the following disclaimer.
|
||||
|
||||
2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
this list of conditions and the following disclaimer in the documentation
|
||||
and/or other materials provided with the distribution.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
||||
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
||||
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
"""
|
||||
|
||||
import copy
|
||||
import ctypes
|
||||
from typing import Callable, Any, Tuple
|
||||
from ctypes import c_void_p, c_char_p, byref, sizeof, POINTER as c_ptr, c_char_p as c_str
|
||||
from ..util import TraceEnable
|
||||
from ..error import VimbaSystemError
|
||||
from .vimba_common import Uint32Enum, Int32Enum, VmbInt32, VmbUint32, VmbInt64, VmbUint64, \
|
||||
VmbHandle, VmbBool, VmbDouble, VmbError, VimbaCError, VmbPixelFormat, \
|
||||
fmt_enum_repr, fmt_repr, fmt_flags_repr, load_vimba_lib
|
||||
|
||||
__version__ = None
|
||||
|
||||
__all__ = [
|
||||
'VmbPixelFormat',
|
||||
'VmbInterface',
|
||||
'VmbAccessMode',
|
||||
'VmbFeatureData',
|
||||
'VmbFeaturePersist',
|
||||
'VmbFeatureVisibility',
|
||||
'VmbFeatureFlags',
|
||||
'VmbFrameStatus',
|
||||
'VmbFrameFlags',
|
||||
'VmbVersionInfo',
|
||||
'VmbInterfaceInfo',
|
||||
'VmbCameraInfo',
|
||||
'VmbFeatureInfo',
|
||||
'VmbFeatureEnumEntry',
|
||||
'VmbFrame',
|
||||
'VmbFeaturePersistSettings',
|
||||
'G_VIMBA_C_HANDLE',
|
||||
'VIMBA_C_VERSION',
|
||||
'EXPECTED_VIMBA_C_VERSION',
|
||||
'call_vimba_c',
|
||||
'build_callback_type'
|
||||
]
|
||||
|
||||
|
||||
# Types
|
||||
class VmbInterface(Uint32Enum):
|
||||
"""
|
||||
Camera Interface Types:
|
||||
Unknown - Interface is not known to this version of the API
|
||||
Firewire - 1394
|
||||
Ethernet - GigE
|
||||
Usb - USB 3.0
|
||||
CL - Camera Link
|
||||
CSI2 - CSI-2
|
||||
"""
|
||||
Unknown = 0
|
||||
Firewire = 1
|
||||
Ethernet = 2
|
||||
Usb = 3
|
||||
CL = 4
|
||||
CSI2 = 5
|
||||
|
||||
def __str__(self):
|
||||
return self._name_
|
||||
|
||||
|
||||
class VmbAccessMode(Uint32Enum):
|
||||
"""
|
||||
Camera Access Mode:
|
||||
None_ - No access
|
||||
Full - Read and write access
|
||||
Read - Read-only access
|
||||
Config - Configuration access (GeV)
|
||||
Lite - Read and write access without feature access (only addresses)
|
||||
"""
|
||||
None_ = 0
|
||||
Full = 1
|
||||
Read = 2
|
||||
Config = 4
|
||||
Lite = 8
|
||||
|
||||
def __str__(self):
|
||||
return self._name_
|
||||
|
||||
|
||||
class VmbFeatureData(Uint32Enum):
|
||||
"""
|
||||
Feature Data Types
|
||||
Unknown - Unknown feature type
|
||||
Int - 64 bit integer feature
|
||||
Float - 64 bit floating point feature
|
||||
Enum - Enumeration feature
|
||||
String - String feature
|
||||
Bool - Boolean feature
|
||||
Command - Command feature
|
||||
Raw - Raw (direct register access) feature
|
||||
None_ - Feature with no data
|
||||
"""
|
||||
Unknown = 0
|
||||
Int = 1
|
||||
Float = 2
|
||||
Enum = 3
|
||||
String = 4
|
||||
Bool = 5
|
||||
Command = 6
|
||||
Raw = 7
|
||||
None_ = 8
|
||||
|
||||
def __str__(self):
|
||||
return self._name_
|
||||
|
||||
|
||||
class VmbFeaturePersist(Uint32Enum):
|
||||
"""
|
||||
Type of features that are to be saved (persisted) to the XML file
|
||||
when using VmbCameraSettingsSave
|
||||
|
||||
All - Save all features to XML, including look-up tables
|
||||
Streamable - Save only features marked as streamable, excluding
|
||||
look-up tables
|
||||
NoLUT - Save all features except look-up tables (default)
|
||||
"""
|
||||
All = 0
|
||||
Streamable = 1
|
||||
NoLUT = 2
|
||||
|
||||
def __str__(self):
|
||||
return self._name_
|
||||
|
||||
|
||||
class VmbFeatureVisibility(Uint32Enum):
|
||||
"""
|
||||
Feature Visibility
|
||||
Unknown - Feature visibility is not known
|
||||
Beginner - Feature is visible in feature list (beginner level)
|
||||
Expert - Feature is visible in feature list (expert level)
|
||||
Guru - Feature is visible in feature list (guru level)
|
||||
Invisible - Feature is not visible in feature list
|
||||
"""
|
||||
Unknown = 0
|
||||
Beginner = 1
|
||||
Expert = 2
|
||||
Guru = 3
|
||||
Invisible = 4
|
||||
|
||||
def __str__(self):
|
||||
return self._name_
|
||||
|
||||
|
||||
class VmbFeatureFlags(Uint32Enum):
|
||||
"""
|
||||
Feature Flags
|
||||
None_ - No additional information is provided
|
||||
Read - Static info about read access.
|
||||
Current status depends on access mode, check with
|
||||
VmbFeatureAccessQuery()
|
||||
Write - Static info about write access.
|
||||
Current status depends on access mode, check with
|
||||
VmbFeatureAccessQuery()
|
||||
Volatile - Value may change at any time
|
||||
ModifyWrite - Value may change after a write
|
||||
"""
|
||||
None_ = 0
|
||||
Read = 1
|
||||
Write = 2
|
||||
Undocumented = 4
|
||||
Volatile = 8
|
||||
ModifyWrite = 16
|
||||
|
||||
def __str__(self):
|
||||
return self._name_
|
||||
|
||||
|
||||
class VmbFrameStatus(Int32Enum):
|
||||
"""
|
||||
Frame transfer status
|
||||
Complete - Frame has been completed without errors
|
||||
Incomplete - Frame could not be filled to the end
|
||||
TooSmall - Frame buffer was too small
|
||||
Invalid - Frame buffer was invalid
|
||||
"""
|
||||
Complete = 0
|
||||
Incomplete = -1
|
||||
TooSmall = -2
|
||||
Invalid = -3
|
||||
|
||||
def __str__(self):
|
||||
return self._name_
|
||||
|
||||
|
||||
class VmbFrameFlags(Uint32Enum):
|
||||
"""
|
||||
Frame Flags
|
||||
None_ - No additional information is provided
|
||||
Dimension - Frame's dimension is provided
|
||||
Offset - Frame's offset is provided (ROI)
|
||||
FrameID - Frame's ID is provided
|
||||
Timestamp - Frame's timestamp is provided
|
||||
"""
|
||||
None_ = 0
|
||||
Dimension = 1
|
||||
Offset = 2
|
||||
FrameID = 4
|
||||
Timestamp = 8
|
||||
|
||||
def __str__(self):
|
||||
return self._name_
|
||||
|
||||
|
||||
class VmbVersionInfo(ctypes.Structure):
|
||||
"""
|
||||
Version Information
|
||||
Fields:
|
||||
major - Type: VmbUint32, Info: Major version number
|
||||
minor - Type: VmbUint32, Info: Minor version number
|
||||
patch - Type: VmbUint32, Info: Patch version number
|
||||
"""
|
||||
_fields_ = [
|
||||
("major", VmbUint32),
|
||||
("minor", VmbUint32),
|
||||
("patch", VmbUint32)
|
||||
]
|
||||
|
||||
def __str__(self):
|
||||
return '{}.{}.{}'.format(self.major, self.minor, self.patch)
|
||||
|
||||
def __repr__(self):
|
||||
rep = 'VmbVersionInfo'
|
||||
rep += '(major=' + repr(self.major)
|
||||
rep += ',minor=' + repr(self.minor)
|
||||
rep += ',patch=' + repr(self.patch)
|
||||
rep += ')'
|
||||
return rep
|
||||
|
||||
|
||||
class VmbInterfaceInfo(ctypes.Structure):
|
||||
"""
|
||||
Interface information. Holds read-only information about an interface.
|
||||
Fields:
|
||||
interfaceIdString - Type: c_char_p
|
||||
Info: Unique identifier for each interface
|
||||
interfaceType - Type: VmbInterface (VmbUint32)
|
||||
Info: Interface type, see VmbInterface
|
||||
interfaceName - Type: c_char_p
|
||||
Info: Interface name, given by transport layer
|
||||
serialString - Type: c_char_p
|
||||
Info: Serial number
|
||||
permittedAccess - Type: VmbAccessMode (VmbUint32)
|
||||
Info: Used access mode, see VmbAccessMode
|
||||
"""
|
||||
_fields_ = [
|
||||
("interfaceIdString", c_char_p),
|
||||
("interfaceType", VmbUint32),
|
||||
("interfaceName", c_char_p),
|
||||
("serialString", c_char_p),
|
||||
("permittedAccess", VmbUint32)
|
||||
]
|
||||
|
||||
def __repr__(self):
|
||||
rep = 'VmbInterfaceInfo'
|
||||
rep += fmt_repr('(interfaceIdString={}', self.interfaceIdString)
|
||||
rep += fmt_enum_repr(',interfaceType={}', VmbInterface, self.interfaceType)
|
||||
rep += fmt_repr(',interfaceName={}', self.interfaceName)
|
||||
rep += fmt_repr(',serialString={}', self.serialString)
|
||||
rep += fmt_flags_repr(',permittedAccess={}', VmbAccessMode, self.permittedAccess)
|
||||
rep += ')'
|
||||
return rep
|
||||
|
||||
|
||||
class VmbCameraInfo(ctypes.Structure):
|
||||
"""
|
||||
Camera information. Holds read-only information about a camera.
|
||||
Fields:
|
||||
cameraIdString - Type: c_char_p
|
||||
Info: Unique identifier for each camera
|
||||
cameraName - Type: c_char_p
|
||||
Info: Name of the camera
|
||||
modelName - Type: c_char_p
|
||||
Info: Model name
|
||||
serialString - Type: c_char_p
|
||||
Info: Serial number
|
||||
permittedAccess - Type: VmbAccessMode (VmbUint32)
|
||||
Info: Used access mode, see VmbAccessMode
|
||||
interfaceIdString - Type: c_char_p
|
||||
Info: Unique value for each interface or bus
|
||||
"""
|
||||
_fields_ = [
|
||||
("cameraIdString", c_char_p),
|
||||
("cameraName", c_char_p),
|
||||
("modelName", c_char_p),
|
||||
("serialString", c_char_p),
|
||||
("permittedAccess", VmbUint32),
|
||||
("interfaceIdString", c_char_p)
|
||||
]
|
||||
|
||||
def __repr__(self):
|
||||
rep = 'VmbCameraInfo'
|
||||
rep += fmt_repr('(cameraIdString={}', self.cameraIdString)
|
||||
rep += fmt_repr(',cameraName={}', self.cameraName)
|
||||
rep += fmt_repr(',modelName={}', self.modelName)
|
||||
rep += fmt_repr(',serialString={}', self.serialString)
|
||||
rep += fmt_flags_repr(',permittedAccess={}', VmbAccessMode, self.permittedAccess)
|
||||
rep += fmt_repr(',interfaceIdString={}', self.interfaceIdString)
|
||||
rep += ')'
|
||||
return rep
|
||||
|
||||
|
||||
class VmbFeatureInfo(ctypes.Structure):
|
||||
"""
|
||||
Feature information. Holds read-only information about a feature.
|
||||
Fields:
|
||||
name - Type: c_char_p
|
||||
Info: Name used in the API
|
||||
featureDataType - Type: VmbFeatureData (VmbUint32)
|
||||
Info: Data type of this feature
|
||||
featureFlags - Type: VmbFeatureFlags (VmbUint32)
|
||||
Info: Access flags for this feature
|
||||
category - Type: c_char_p
|
||||
Info: Category this feature can be found in
|
||||
displayName - Type: c_char_p
|
||||
Info: Feature name to be used in GUIs
|
||||
pollingTime - Type: VmbUint32
|
||||
Info: Predefined polling time for volatile
|
||||
features
|
||||
unit - Type: c_char_p
|
||||
Info: Measuring unit as given in the XML file
|
||||
representation - Type: c_char_p
|
||||
Info: Representation of a numeric feature
|
||||
visibility - Type: VmbFeatureVisibility (VmbUint32)
|
||||
Info: GUI visibility
|
||||
tooltip - Type: c_char_p
|
||||
Info: Short description, e.g. for a tooltip
|
||||
description - Type: c_char_p
|
||||
Info: Longer description
|
||||
sfncNamespace - Type: c_char_p
|
||||
Info: Namespace this feature resides in
|
||||
isStreamable - Type: VmbBool
|
||||
Info: Indicates if a feature can be stored
|
||||
to / loaded from a file
|
||||
hasAffectedFeatures - Type: VmbBool
|
||||
Info: Indicates if the feature potentially
|
||||
affects other features
|
||||
hasSelectedFeatures - Type: VmbBool
|
||||
Info: Indicates if the feature selects other
|
||||
features
|
||||
"""
|
||||
_fields_ = [
|
||||
("name", c_char_p),
|
||||
("featureDataType", VmbUint32),
|
||||
("featureFlags", VmbUint32),
|
||||
("category", c_char_p),
|
||||
("displayName", c_char_p),
|
||||
("pollingTime", VmbUint32),
|
||||
("unit", c_char_p),
|
||||
("representation", c_char_p),
|
||||
("visibility", VmbUint32),
|
||||
("tooltip", c_char_p),
|
||||
("description", c_char_p),
|
||||
("sfncNamespace", c_char_p),
|
||||
("isStreamable", VmbBool),
|
||||
("hasAffectedFeatures", VmbBool),
|
||||
("hasSelectedFeatures", VmbBool)
|
||||
]
|
||||
|
||||
def __repr__(self):
|
||||
rep = 'VmbFeatureInfo'
|
||||
rep += fmt_repr('(name={}', self.name)
|
||||
rep += fmt_enum_repr(',featureDataType={}', VmbFeatureData, self.featureDataType)
|
||||
rep += fmt_flags_repr(',featureFlags={}', VmbFeatureFlags, self.featureFlags)
|
||||
rep += fmt_repr(',category={}', self.category)
|
||||
rep += fmt_repr(',displayName={}', self.displayName)
|
||||
rep += fmt_repr(',pollingTime={}', self.pollingTime)
|
||||
rep += fmt_repr(',unit={}', self.unit)
|
||||
rep += fmt_repr(',representation={}', self.representation)
|
||||
rep += fmt_enum_repr(',visibility={}', VmbFeatureVisibility, self.visibility)
|
||||
rep += fmt_repr(',tooltip={}', self.tooltip)
|
||||
rep += fmt_repr(',description={}', self.description)
|
||||
rep += fmt_repr(',sfncNamespace={}', self.sfncNamespace)
|
||||
rep += fmt_repr(',isStreamable={}', self.isStreamable)
|
||||
rep += fmt_repr(',hasAffectedFeatures={}', self.hasAffectedFeatures)
|
||||
rep += fmt_repr(',hasSelectedFeatures={}', self.hasSelectedFeatures)
|
||||
rep += ')'
|
||||
return rep
|
||||
|
||||
|
||||
class VmbFeatureEnumEntry(ctypes.Structure):
|
||||
"""
|
||||
Info about possible entries of an enumeration feature:
|
||||
Fields:
|
||||
name - Type: c_char_p
|
||||
Info: Name used in the API
|
||||
displayName - Type: c_char_p
|
||||
Info: Enumeration entry name to be used in GUIs
|
||||
visibility - Type: VmbFeatureVisibility (VmbUint32)
|
||||
Info: GUI visibility
|
||||
tooltip - Type: c_char_p
|
||||
Info: Short description, e.g. for a tooltip
|
||||
description - Type: c_char_p
|
||||
Info: Longer description
|
||||
sfncNamespace - Type: c_char_p
|
||||
Info: Namespace this feature resides in
|
||||
intValue - Type: VmbInt64
|
||||
Info: Integer value of this enumeration entry
|
||||
"""
|
||||
_fields_ = [
|
||||
("name", c_char_p),
|
||||
("displayName", c_char_p),
|
||||
("visibility", VmbUint32),
|
||||
("tooltip", c_char_p),
|
||||
("description", c_char_p),
|
||||
("sfncNamespace", c_char_p),
|
||||
("intValue", VmbInt64)
|
||||
]
|
||||
|
||||
def __repr__(self):
|
||||
rep = 'VmbFeatureEnumEntry'
|
||||
rep += fmt_repr('(name={}', self.name)
|
||||
rep += fmt_repr(',displayName={}', self.displayName)
|
||||
rep += fmt_enum_repr(',visibility={}', VmbFeatureVisibility, self.visibility)
|
||||
rep += fmt_repr(',tooltip={}', self.tooltip)
|
||||
rep += fmt_repr(',description={}', self.description)
|
||||
rep += fmt_repr(',sfncNamespace={}', self.sfncNamespace)
|
||||
rep += fmt_repr(',intValue={},', self.intValue)
|
||||
rep += ')'
|
||||
return rep
|
||||
|
||||
|
||||
class VmbFrame(ctypes.Structure):
|
||||
"""
|
||||
Frame delivered by Camera
|
||||
Fields (in):
|
||||
buffer - Type: c_void_p
|
||||
Info: Comprises image and ancillary data
|
||||
bufferSize - Type: VmbUint32_t
|
||||
Info: Size of the data buffer
|
||||
context - Type: c_void_p[4]
|
||||
Info: 4 void pointers that can be employed by the user
|
||||
(e.g. for storing handles)
|
||||
|
||||
Fields (out):
|
||||
receiveStatus - Type: VmbFrameStatus (VmbInt32)
|
||||
Info: Resulting status of the receive operation
|
||||
receiveFlags - Type: VmbFrameFlags (VmbUint32)
|
||||
Info: Flags indicating which additional frame
|
||||
information is available
|
||||
imageSize - Type: VmbUint32
|
||||
Info: Size of the image data inside the data buffer
|
||||
ancillarySize - Type: VmbUint32
|
||||
Info: Size of the ancillary data inside the
|
||||
data buffer
|
||||
pixelFormat - Type: VmbPixelFormat (VmbUint32)
|
||||
Info: Pixel format of the image
|
||||
width - Type: VmbUint32
|
||||
Info: Width of an image
|
||||
height - Type: VmbUint32
|
||||
Info: Height of an image
|
||||
offsetX - Type: VmbUint32
|
||||
Info: Horizontal offset of an image
|
||||
offsetY - Type: VmbUint32
|
||||
Info: Vertical offset of an image
|
||||
frameID - Type: VmbUint64
|
||||
Info: Unique ID of this frame in this stream
|
||||
timestamp - Type: VmbUint64
|
||||
Info: Timestamp set by the camera
|
||||
"""
|
||||
_fields_ = [
|
||||
("buffer", c_void_p),
|
||||
("bufferSize", VmbUint32),
|
||||
("context", c_void_p * 4),
|
||||
("receiveStatus", VmbInt32),
|
||||
("receiveFlags", VmbUint32),
|
||||
("imageSize", VmbUint32),
|
||||
("ancillarySize", VmbUint32),
|
||||
("pixelFormat", VmbUint32),
|
||||
("width", VmbUint32),
|
||||
("height", VmbUint32),
|
||||
("offsetX", VmbUint32),
|
||||
("offsetY", VmbUint32),
|
||||
("frameID", VmbUint64),
|
||||
("timestamp", VmbUint64)
|
||||
]
|
||||
|
||||
def __repr__(self):
|
||||
rep = 'VmbFrame'
|
||||
rep += fmt_repr('(buffer={}', self.buffer)
|
||||
rep += fmt_repr(',bufferSize={}', self.bufferSize)
|
||||
rep += fmt_repr(',context={}', self.context)
|
||||
rep += fmt_enum_repr('receiveStatus: {}', VmbFrameStatus, self.receiveStatus)
|
||||
rep += fmt_flags_repr(',receiveFlags={}', VmbFrameFlags, self.receiveFlags)
|
||||
rep += fmt_repr(',imageSize={}', self.imageSize)
|
||||
rep += fmt_repr(',ancillarySize={}', self.ancillarySize)
|
||||
rep += fmt_enum_repr(',pixelFormat={}', VmbPixelFormat, self.pixelFormat)
|
||||
rep += fmt_repr(',width={}', self.width)
|
||||
rep += fmt_repr(',height={}', self.height)
|
||||
rep += fmt_repr(',offsetX={}', self.offsetX)
|
||||
rep += fmt_repr(',offsetY={}', self.offsetY)
|
||||
rep += fmt_repr(',frameID={}', self.frameID)
|
||||
rep += fmt_repr(',timestamp={}', self.timestamp)
|
||||
rep += ')'
|
||||
return rep
|
||||
|
||||
def deepcopy_skip_ptr(self, memo):
|
||||
result = VmbFrame()
|
||||
memo[id(self)] = result
|
||||
|
||||
result.buffer = None
|
||||
result.bufferSize = 0
|
||||
result.context = (None, None, None, None)
|
||||
|
||||
setattr(result, 'receiveStatus', copy.deepcopy(self.receiveStatus, memo))
|
||||
setattr(result, 'receiveFlags', copy.deepcopy(self.receiveFlags, memo))
|
||||
setattr(result, 'imageSize', copy.deepcopy(self.imageSize, memo))
|
||||
setattr(result, 'ancillarySize', copy.deepcopy(self.ancillarySize, memo))
|
||||
setattr(result, 'pixelFormat', copy.deepcopy(self.pixelFormat, memo))
|
||||
setattr(result, 'width', copy.deepcopy(self.width, memo))
|
||||
setattr(result, 'height', copy.deepcopy(self.height, memo))
|
||||
setattr(result, 'offsetX', copy.deepcopy(self.offsetX, memo))
|
||||
setattr(result, 'offsetY', copy.deepcopy(self.offsetY, memo))
|
||||
setattr(result, 'frameID', copy.deepcopy(self.frameID, memo))
|
||||
setattr(result, 'timestamp', copy.deepcopy(self.timestamp, memo))
|
||||
return result
|
||||
|
||||
|
||||
class VmbFeaturePersistSettings(ctypes.Structure):
|
||||
"""
|
||||
Parameters determining the operation mode of VmbCameraSettingsSave
|
||||
and VmbCameraSettingsLoad
|
||||
Fields:
|
||||
persistType - Type: VmbFeaturePersist (VmbUint32)
|
||||
Info: Type of features that are to be saved
|
||||
maxIterations - Type: VmbUint32
|
||||
Info: Number of iterations when loading settings
|
||||
loggingLevel - Type: VmbUint32
|
||||
Info: Determines level of detail for load/save
|
||||
settings logging
|
||||
"""
|
||||
_fields_ = [
|
||||
("persistType", VmbUint32),
|
||||
("maxIterations", VmbUint32),
|
||||
("loggingLevel", VmbUint32)
|
||||
]
|
||||
|
||||
def __repr__(self):
|
||||
rep = 'VmbFrame'
|
||||
rep += fmt_enum_repr('(persistType={}', VmbFeaturePersist, self.persistType)
|
||||
rep += fmt_repr(',maxIterations={}', self.maxIterations)
|
||||
rep += fmt_repr(',loggingLevel={}', self.loggingLevel)
|
||||
rep += ')'
|
||||
return rep
|
||||
|
||||
|
||||
G_VIMBA_C_HANDLE = VmbHandle(1)
|
||||
|
||||
VIMBA_C_VERSION = None
|
||||
EXPECTED_VIMBA_C_VERSION = '1.9.0'
|
||||
|
||||
# For detailed information on the signatures see "VimbaC.h"
|
||||
# To improve readability, suppress 'E501 line too long (> 100 characters)'
|
||||
# check of flake8
|
||||
_SIGNATURES = {
|
||||
'VmbVersionQuery': (VmbError, [c_ptr(VmbVersionInfo), VmbUint32]),
|
||||
'VmbStartup': (VmbError, None),
|
||||
'VmbShutdown': (None, None),
|
||||
'VmbCamerasList': (VmbError, [c_ptr(VmbCameraInfo), VmbUint32, c_ptr(VmbUint32), VmbUint32]),
|
||||
'VmbCameraInfoQuery': (VmbError, [c_str, c_ptr(VmbCameraInfo), VmbUint32]),
|
||||
'VmbCameraOpen': (VmbError, [c_str, VmbAccessMode, c_ptr(VmbHandle)]),
|
||||
'VmbCameraClose': (VmbError, [VmbHandle]),
|
||||
'VmbFeaturesList': (VmbError, [VmbHandle, c_ptr(VmbFeatureInfo), VmbUint32, c_ptr(VmbUint32), VmbUint32]), # noqa: E501
|
||||
'VmbFeatureInfoQuery': (VmbError, [VmbHandle, c_str, c_ptr(VmbFeatureInfo), VmbUint32]),
|
||||
'VmbFeatureListAffected': (VmbError, [VmbHandle, c_str, c_ptr(VmbFeatureInfo), VmbUint32, c_ptr(VmbUint32), VmbUint32]), # noqa: E501
|
||||
'VmbFeatureListSelected': (VmbError, [VmbHandle, c_str, c_ptr(VmbFeatureInfo), VmbUint32, c_ptr(VmbUint32), VmbUint32]), # noqa: E501
|
||||
'VmbFeatureAccessQuery': (VmbError, [VmbHandle, c_str, c_ptr(VmbBool), c_ptr(VmbBool)]),
|
||||
'VmbFeatureIntGet': (VmbError, [VmbHandle, c_str, c_ptr(VmbInt64)]),
|
||||
'VmbFeatureIntSet': (VmbError, [VmbHandle, c_str, VmbInt64]),
|
||||
'VmbFeatureIntRangeQuery': (VmbError, [VmbHandle, c_str, c_ptr(VmbInt64), c_ptr(VmbInt64)]), # noqa: E501
|
||||
'VmbFeatureIntIncrementQuery': (VmbError, [VmbHandle, c_str, c_ptr(VmbInt64)]),
|
||||
'VmbFeatureFloatGet': (VmbError, [VmbHandle, c_str, c_ptr(VmbDouble)]),
|
||||
'VmbFeatureFloatSet': (VmbError, [VmbHandle, c_str, VmbDouble]),
|
||||
'VmbFeatureFloatRangeQuery': (VmbError, [VmbHandle, c_str, c_ptr(VmbDouble), c_ptr(VmbDouble)]),
|
||||
'VmbFeatureFloatIncrementQuery': (VmbError, [VmbHandle, c_str, c_ptr(VmbBool), c_ptr(VmbDouble)]), # noqa: E501
|
||||
'VmbFeatureEnumGet': (VmbError, [VmbHandle, c_str, c_ptr(c_str)]),
|
||||
'VmbFeatureEnumSet': (VmbError, [VmbHandle, c_str, c_str]),
|
||||
'VmbFeatureEnumRangeQuery': (VmbError, [VmbHandle, c_str, c_ptr(c_str), VmbUint32, c_ptr(VmbUint32)]), # noqa: E501
|
||||
'VmbFeatureEnumIsAvailable': (VmbError, [VmbHandle, c_str, c_str, c_ptr(VmbBool)]),
|
||||
'VmbFeatureEnumAsInt': (VmbError, [VmbHandle, c_str, c_str, c_ptr(VmbInt64)]),
|
||||
'VmbFeatureEnumAsString': (VmbError, [VmbHandle, c_str, VmbInt64, c_ptr(c_str)]),
|
||||
'VmbFeatureEnumEntryGet': (VmbError, [VmbHandle, c_str, c_str, c_ptr(VmbFeatureEnumEntry), VmbUint32]), # noqa: E501
|
||||
'VmbFeatureStringGet': (VmbError, [VmbHandle, c_str, c_str, VmbUint32, c_ptr(VmbUint32)]), # noqa: E501
|
||||
'VmbFeatureStringSet': (VmbError, [VmbHandle, c_str, c_str]),
|
||||
'VmbFeatureStringMaxlengthQuery': (VmbError, [VmbHandle, c_str, c_ptr(VmbUint32)]),
|
||||
'VmbFeatureBoolGet': (VmbError, [VmbHandle, c_str, c_ptr(VmbBool)]),
|
||||
'VmbFeatureBoolSet': (VmbError, [VmbHandle, c_str, VmbBool]),
|
||||
'VmbFeatureCommandRun': (VmbError, [VmbHandle, c_str]),
|
||||
'VmbFeatureCommandIsDone': (VmbError, [VmbHandle, c_str, c_ptr(VmbBool)]),
|
||||
'VmbFeatureRawGet': (VmbError, [VmbHandle, c_str, c_str, VmbUint32, c_ptr(VmbUint32)]),
|
||||
'VmbFeatureRawSet': (VmbError, [VmbHandle, c_str, c_str, VmbUint32]),
|
||||
'VmbFeatureRawLengthQuery': (VmbError, [VmbHandle, c_str, c_ptr(VmbUint32)]),
|
||||
'VmbFeatureInvalidationRegister': (VmbError, [VmbHandle, c_str, c_void_p, c_void_p]), # noqa: E501
|
||||
'VmbFeatureInvalidationUnregister': (VmbError, [VmbHandle, c_str, c_void_p]),
|
||||
'VmbFrameAnnounce': (VmbError, [VmbHandle, c_ptr(VmbFrame), VmbUint32]),
|
||||
'VmbFrameRevoke': (VmbError, [VmbHandle, c_ptr(VmbFrame)]),
|
||||
'VmbFrameRevokeAll': (VmbError, [VmbHandle]),
|
||||
'VmbCaptureStart': (VmbError, [VmbHandle]),
|
||||
'VmbCaptureEnd': (VmbError, [VmbHandle]),
|
||||
'VmbCaptureFrameQueue': (VmbError, [VmbHandle, c_ptr(VmbFrame), c_void_p]),
|
||||
'VmbCaptureFrameWait': (VmbError, [VmbHandle, c_ptr(VmbFrame), VmbUint32]),
|
||||
'VmbCaptureQueueFlush': (VmbError, [VmbHandle]),
|
||||
'VmbInterfacesList': (VmbError, [c_ptr(VmbInterfaceInfo), VmbUint32, c_ptr(VmbUint32), VmbUint32]), # noqa: E501
|
||||
'VmbInterfaceOpen': (VmbError, [c_str, c_ptr(VmbHandle)]),
|
||||
'VmbInterfaceClose': (VmbError, [VmbHandle]),
|
||||
'VmbAncillaryDataOpen': (VmbError, [c_ptr(VmbFrame), c_ptr(VmbHandle)]),
|
||||
'VmbAncillaryDataClose': (VmbError, [VmbHandle]),
|
||||
'VmbMemoryRead': (VmbError, [VmbHandle, VmbUint64, VmbUint32, c_str, c_ptr(VmbUint32)]),
|
||||
'VmbMemoryWrite': (VmbError, [VmbHandle, VmbUint64, VmbUint32, c_str, c_ptr(VmbUint32)]),
|
||||
'VmbRegistersRead': (VmbError, [VmbHandle, VmbUint32, c_ptr(VmbUint64), c_ptr(VmbUint64), c_ptr(VmbUint32)]), # noqa: E501
|
||||
'VmbRegistersWrite': (VmbError, [VmbHandle, VmbUint32, c_ptr(VmbUint64), c_ptr(VmbUint64), c_ptr(VmbUint32)]), # noqa: E501
|
||||
'VmbCameraSettingsSave': (VmbError, [VmbHandle, c_str, c_ptr(VmbFeaturePersistSettings), VmbUint32]), # noqa: E501
|
||||
'VmbCameraSettingsLoad': (VmbError, [VmbHandle, c_str, c_ptr(VmbFeaturePersistSettings), VmbUint32]) # noqa: E501
|
||||
}
|
||||
|
||||
|
||||
def _attach_signatures(lib_handle):
|
||||
global _SIGNATURES
|
||||
|
||||
for function_name, signature in _SIGNATURES.items():
|
||||
fn = getattr(lib_handle, function_name)
|
||||
fn.restype, fn.argtypes = signature
|
||||
fn.errcheck = _eval_vmberror
|
||||
|
||||
return lib_handle
|
||||
|
||||
|
||||
def _check_version(lib_handle):
|
||||
global EXPECTED_VIMBA_C_VERSION
|
||||
global VIMBA_C_VERSION
|
||||
|
||||
v = VmbVersionInfo()
|
||||
lib_handle.VmbVersionQuery(byref(v), sizeof(v))
|
||||
|
||||
VIMBA_C_VERSION = str(v)
|
||||
|
||||
loaded_version = (v.major, v.minor, v.patch)
|
||||
expected_version = tuple(map(int, EXPECTED_VIMBA_C_VERSION.split(".")))
|
||||
# major and minor version must be equal, patch version may be equal or greater
|
||||
if not(loaded_version[0:2] == expected_version[0:2] and
|
||||
loaded_version[2] >= expected_version[2]):
|
||||
msg = 'Invalid VimbaC Version: Expected: {}, Found:{}'
|
||||
raise VimbaSystemError(msg.format(EXPECTED_VIMBA_C_VERSION, VIMBA_C_VERSION))
|
||||
|
||||
return lib_handle
|
||||
|
||||
|
||||
def _eval_vmberror(result: VmbError, func: Callable[..., Any], *args: Tuple[Any, ...]):
|
||||
if result not in (VmbError.Success, None):
|
||||
raise VimbaCError(result)
|
||||
|
||||
|
||||
_lib_instance = _check_version(_attach_signatures(load_vimba_lib('VimbaC')))
|
||||
|
||||
|
||||
@TraceEnable()
|
||||
def call_vimba_c(func_name: str, *args):
|
||||
"""This function encapsulates the entire VimbaC access.
|
||||
|
||||
For Details on valid function signatures see the 'VimbaC.h'.
|
||||
|
||||
Arguments:
|
||||
func_name: The function name from VimbaC to be called.
|
||||
args: Varargs passed directly to the underlaying C-Function.
|
||||
|
||||
Raises:
|
||||
TypeError if given are do not match the signature of the function.
|
||||
AttributeError if func with name 'func_name' does not exist.
|
||||
VimbaCError if the function call is valid but neither None or VmbError.Success was returned.
|
||||
|
||||
The following functions of VimbaC can be executed:
|
||||
VmbVersionQuery
|
||||
VmbStartup
|
||||
VmbShutdown
|
||||
VmbCamerasList
|
||||
VmbCameraInfoQuery
|
||||
VmbCameraOpen
|
||||
VmbCameraClose
|
||||
VmbFeaturesList
|
||||
VmbFeatureInfoQuery
|
||||
VmbFeatureListAffected
|
||||
VmbFeatureListSelected
|
||||
VmbFeatureAccessQuery
|
||||
VmbFeatureIntGet
|
||||
VmbFeatureIntSet
|
||||
VmbFeatureIntRangeQuery
|
||||
VmbFeatureIntIncrementQuery
|
||||
VmbFeatureFloatGet
|
||||
VmbFeatureFloatSet
|
||||
VmbFeatureFloatRangeQuery
|
||||
VmbFeatureFloatIncrementQuery
|
||||
VmbFeatureEnumGet
|
||||
VmbFeatureEnumSet
|
||||
VmbFeatureEnumRangeQuery
|
||||
VmbFeatureEnumIsAvailable
|
||||
VmbFeatureEnumAsInt
|
||||
VmbFeatureEnumAsString
|
||||
VmbFeatureEnumEntryGet
|
||||
VmbFeatureStringGet
|
||||
VmbFeatureStringSet
|
||||
VmbFeatureStringMaxlengthQuery
|
||||
VmbFeatureBoolGet
|
||||
VmbFeatureBoolSet
|
||||
VmbFeatureCommandRun
|
||||
VmbFeatureCommandIsDone
|
||||
VmbFeatureRawGet
|
||||
VmbFeatureRawSet
|
||||
VmbFeatureRawLengthQuery
|
||||
VmbFeatureInvalidationRegister
|
||||
VmbFeatureInvalidationUnregister
|
||||
VmbFrameAnnounce
|
||||
VmbFrameRevoke
|
||||
VmbFrameRevokeAll
|
||||
VmbCaptureStart
|
||||
VmbCaptureEnd
|
||||
VmbCaptureFrameQueue
|
||||
VmbCaptureFrameWait
|
||||
VmbCaptureQueueFlush
|
||||
VmbInterfacesList
|
||||
VmbInterfaceOpen
|
||||
VmbInterfaceClose
|
||||
VmbAncillaryDataOpen
|
||||
VmbAncillaryDataClose
|
||||
VmbMemoryRead
|
||||
VmbMemoryWrite
|
||||
VmbRegistersRead
|
||||
VmbRegistersWrite
|
||||
VmbCameraSettingsSave
|
||||
VmbCameraSettingsLoad
|
||||
"""
|
||||
global _lib_instance
|
||||
getattr(_lib_instance, func_name)(*args)
|
||||
|
||||
|
||||
def build_callback_type(*args):
|
||||
global _lib_instance
|
||||
|
||||
lib_type = type(_lib_instance)
|
||||
|
||||
if lib_type == ctypes.CDLL:
|
||||
return ctypes.CFUNCTYPE(*args)
|
||||
|
||||
elif lib_type == ctypes.WinDLL:
|
||||
return ctypes.WINFUNCTYPE(*args)
|
||||
|
||||
else:
|
||||
raise VimbaSystemError('Unknown Library Type. Abort.')
|
||||
611
Vimba_6_0/VimbaPython/Source/vimba/c_binding/vimba_common.py
Normal file
611
Vimba_6_0/VimbaPython/Source/vimba/c_binding/vimba_common.py
Normal file
@@ -0,0 +1,611 @@
|
||||
"""BSD 2-Clause License
|
||||
|
||||
Copyright (c) 2019, Allied Vision Technologies GmbH
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions are met:
|
||||
|
||||
1. Redistributions of source code must retain the above copyright notice, this
|
||||
list of conditions and the following disclaimer.
|
||||
|
||||
2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
this list of conditions and the following disclaimer in the documentation
|
||||
and/or other materials provided with the distribution.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
||||
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
||||
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
"""
|
||||
|
||||
import ctypes
|
||||
import enum
|
||||
import os
|
||||
import sys
|
||||
import platform
|
||||
import functools
|
||||
from typing import Tuple, List
|
||||
from ..error import VimbaSystemError
|
||||
|
||||
|
||||
__all__ = [
|
||||
'Int32Enum',
|
||||
'Uint32Enum',
|
||||
'VmbInt8',
|
||||
'VmbUint8',
|
||||
'VmbInt16',
|
||||
'VmbUint16',
|
||||
'VmbInt32',
|
||||
'VmbUint32',
|
||||
'VmbInt64',
|
||||
'VmbUint64',
|
||||
'VmbHandle',
|
||||
'VmbBool',
|
||||
'VmbUchar',
|
||||
'VmbFloat',
|
||||
'VmbDouble',
|
||||
'VmbError',
|
||||
'VimbaCError',
|
||||
'VmbPixelFormat',
|
||||
'decode_cstr',
|
||||
'decode_flags',
|
||||
'fmt_repr',
|
||||
'fmt_enum_repr',
|
||||
'fmt_flags_repr',
|
||||
'load_vimba_lib'
|
||||
]
|
||||
|
||||
|
||||
# Types
|
||||
class Int32Enum(enum.IntEnum):
|
||||
@classmethod
|
||||
def from_param(cls, obj):
|
||||
return ctypes.c_int(obj)
|
||||
|
||||
|
||||
class Uint32Enum(enum.IntEnum):
|
||||
@classmethod
|
||||
def from_param(cls, obj):
|
||||
return ctypes.c_uint(obj)
|
||||
|
||||
|
||||
# Aliases for vmb base types
|
||||
VmbInt8 = ctypes.c_byte
|
||||
VmbUint8 = ctypes.c_ubyte
|
||||
VmbInt16 = ctypes.c_short
|
||||
VmbUint16 = ctypes.c_ushort
|
||||
VmbInt32 = ctypes.c_int
|
||||
VmbUint32 = ctypes.c_uint
|
||||
VmbInt64 = ctypes.c_longlong
|
||||
VmbUint64 = ctypes.c_ulonglong
|
||||
VmbHandle = ctypes.c_void_p
|
||||
VmbBool = ctypes.c_bool
|
||||
VmbUchar = ctypes.c_char
|
||||
VmbFloat = ctypes.c_float
|
||||
VmbDouble = ctypes.c_double
|
||||
|
||||
|
||||
class VmbError(Int32Enum):
|
||||
"""
|
||||
Enum containing error types returned
|
||||
Success - No error
|
||||
InternalFault - Unexpected fault in VimbaC or driver
|
||||
ApiNotStarted - VmbStartup() was not called before the current
|
||||
command
|
||||
NotFound - The designated instance (camera, feature etc.)
|
||||
cannot be found
|
||||
BadHandle - The given handle is not valid
|
||||
DeviceNotOpen - Device was not opened for usage
|
||||
InvalidAccess - Operation is invalid with the current access mode
|
||||
BadParameter - One of the parameters is invalid (usually an illegal
|
||||
pointer)
|
||||
StructSize - The given struct size is not valid for this version
|
||||
of the API
|
||||
MoreData - More data available in a string/list than space is
|
||||
provided
|
||||
WrongType - Wrong feature type for this access function
|
||||
InvalidValue - The value is not valid; Either out of bounds or not
|
||||
an increment of the minimum
|
||||
Timeout - Timeout during wait
|
||||
Other - Other error
|
||||
Resources - Resources not available (e.g. memory)
|
||||
InvalidCall - Call is invalid in the current context (callback)
|
||||
NoTL - No transport layers are found
|
||||
NotImplemented_ - API feature is not implemented
|
||||
NotSupported - API feature is not supported
|
||||
Incomplete - A multiple registers read or write is partially
|
||||
completed
|
||||
IO - low level IO error in transport layer
|
||||
"""
|
||||
Success = 0
|
||||
InternalFault = -1
|
||||
ApiNotStarted = -2
|
||||
NotFound = -3
|
||||
BadHandle = -4
|
||||
DeviceNotOpen = -5
|
||||
InvalidAccess = -6
|
||||
BadParameter = -7
|
||||
StructSize = -8
|
||||
MoreData = -9
|
||||
WrongType = -10
|
||||
InvalidValue = -11
|
||||
Timeout = -12
|
||||
Other = -13
|
||||
Resources = -14
|
||||
InvalidCall = -15
|
||||
NoTL = -16
|
||||
NotImplemented_ = -17
|
||||
NotSupported = -18
|
||||
Incomplete = -19
|
||||
IO = -20
|
||||
|
||||
def __str__(self):
|
||||
return self._name_
|
||||
|
||||
|
||||
class _VmbPixel(Uint32Enum):
|
||||
Mono = 0x01000000
|
||||
Color = 0x02000000
|
||||
|
||||
|
||||
class _VmbPixelOccupy(Uint32Enum):
|
||||
Bit8 = 0x00080000
|
||||
Bit10 = 0x000A0000
|
||||
Bit12 = 0x000C0000
|
||||
Bit14 = 0x000E0000
|
||||
Bit16 = 0x00100000
|
||||
Bit24 = 0x00180000
|
||||
Bit32 = 0x00200000
|
||||
Bit48 = 0x00300000
|
||||
Bit64 = 0x00400000
|
||||
|
||||
|
||||
class VmbPixelFormat(Uint32Enum):
|
||||
"""
|
||||
Enum containing Pixelformats
|
||||
Mono formats:
|
||||
Mono8 - Monochrome, 8 bits (PFNC:Mono8)
|
||||
Mono10 - Monochrome, 10 bits in 16 bits (PFNC:Mono10)
|
||||
Mono10p - Monochrome, 4x10 bits continuously packed in 40 bits
|
||||
(PFNC:Mono10p)
|
||||
Mono12 - Monochrome, 12 bits in 16 bits (PFNC:Mono12)
|
||||
Mono12Packed - Monochrome, 2x12 bits in 24 bits (GEV:Mono12Packed)
|
||||
Mono12p - Monochrome, 2x12 bits continuously packed in 24 bits
|
||||
(PFNC:Mono12p)
|
||||
Mono14 - Monochrome, 14 bits in 16 bits (PFNC:Mono14)
|
||||
Mono16 - Monochrome, 16 bits (PFNC:Mono16)
|
||||
|
||||
Bayer formats:
|
||||
BayerGR8 - Bayer-color, 8 bits, starting with GR line
|
||||
(PFNC:BayerGR8)
|
||||
BayerRG8 - Bayer-color, 8 bits, starting with RG line
|
||||
(PFNC:BayerRG8)
|
||||
BayerGB8 - Bayer-color, 8 bits, starting with GB line
|
||||
(PFNC:BayerGB8)
|
||||
BayerBG8 - Bayer-color, 8 bits, starting with BG line
|
||||
(PFNC:BayerBG8)
|
||||
BayerGR10 - Bayer-color, 10 bits in 16 bits, starting with GR
|
||||
line (PFNC:BayerGR10)
|
||||
BayerRG10 - Bayer-color, 10 bits in 16 bits, starting with RG
|
||||
line (PFNC:BayerRG10)
|
||||
BayerGB10 - Bayer-color, 10 bits in 16 bits, starting with GB
|
||||
line (PFNC:BayerGB10)
|
||||
BayerBG10 - Bayer-color, 10 bits in 16 bits, starting with BG
|
||||
line (PFNC:BayerBG10)
|
||||
BayerGR12 - Bayer-color, 12 bits in 16 bits, starting with GR
|
||||
line (PFNC:BayerGR12)
|
||||
BayerRG12 - Bayer-color, 12 bits in 16 bits, starting with RG
|
||||
line (PFNC:BayerRG12)
|
||||
BayerGB12 - Bayer-color, 12 bits in 16 bits, starting with GB
|
||||
line (PFNC:BayerGB12)
|
||||
BayerBG12 - Bayer-color, 12 bits in 16 bits, starting with BG
|
||||
line (PFNC:BayerBG12)
|
||||
BayerGR12Packed - Bayer-color, 2x12 bits in 24 bits, starting with GR
|
||||
line (GEV:BayerGR12Packed)
|
||||
BayerRG12Packed - Bayer-color, 2x12 bits in 24 bits, starting with RG
|
||||
line (GEV:BayerRG12Packed)
|
||||
BayerGB12Packed - Bayer-color, 2x12 bits in 24 bits, starting with GB
|
||||
line (GEV:BayerGB12Packed)
|
||||
BayerBG12Packed - Bayer-color, 2x12 bits in 24 bits, starting with BG
|
||||
line (GEV:BayerBG12Packed)
|
||||
BayerGR10p - Bayer-color, 4x10 bits continuously packed in 40
|
||||
bits, starting with GR line (PFNC:BayerGR10p)
|
||||
BayerRG10p - Bayer-color, 4x10 bits continuously packed in 40
|
||||
bits, starting with RG line (PFNC:BayerRG10p)
|
||||
BayerGB10p - Bayer-color, 4x10 bits continuously packed in 40
|
||||
bits, starting with GB line (PFNC:BayerGB10p)
|
||||
BayerBG10p - Bayer-color, 4x10 bits continuously packed in 40
|
||||
bits, starting with BG line (PFNC:BayerBG10p)
|
||||
BayerGR12p - Bayer-color, 2x12 bits continuously packed in 24
|
||||
bits, starting with GR line (PFNC:BayerGR12p)
|
||||
BayerRG12p - Bayer-color, 2x12 bits continuously packed in 24
|
||||
bits, starting with RG line (PFNC:BayerRG12p)
|
||||
BayerGB12p - Bayer-color, 2x12 bits continuously packed in 24
|
||||
bits, starting with GB line (PFNC:BayerGB12p)
|
||||
BayerBG12p - Bayer-color, 2x12 bits continuously packed in 24
|
||||
bits, starting with BG line (PFNC:BayerBG12p)
|
||||
BayerGR16 - Bayer-color, 16 bits, starting with GR line
|
||||
(PFNC:BayerGR16)
|
||||
BayerRG16 - Bayer-color, 16 bits, starting with RG line
|
||||
(PFNC:BayerRG16)
|
||||
BayerGB16 - Bayer-color, 16 bits, starting with GB line
|
||||
(PFNC:BayerGB16)
|
||||
BayerBG16 - Bayer-color, 16 bits, starting with BG line
|
||||
(PFNC:BayerBG16)
|
||||
|
||||
RGB formats:
|
||||
Rgb8 - RGB, 8 bits x 3 (PFNC:RGB8)
|
||||
Bgr8 - BGR, 8 bits x 3 (PFNC:Bgr8)
|
||||
Rgb10 - RGB, 10 bits in 16 bits x 3 (PFNC:RGB10)
|
||||
Bgr10 - BGR, 10 bits in 16 bits x 3 (PFNC:BGR10)
|
||||
Rgb12 - RGB, 12 bits in 16 bits x 3 (PFNC:RGB12)
|
||||
Bgr12 - BGR, 12 bits in 16 bits x 3 (PFNC:BGR12)
|
||||
Rgb14 - RGB, 14 bits in 16 bits x 3 (PFNC:RGB14)
|
||||
Bgr14 - BGR, 14 bits in 16 bits x 3 (PFNC:BGR14)
|
||||
Rgb16 - RGB, 16 bits x 3 (PFNC:RGB16)
|
||||
Bgr16 - BGR, 16 bits x 3 (PFNC:BGR16)
|
||||
|
||||
RGBA formats:
|
||||
Argb8 - ARGB, 8 bits x 4 (PFNC:RGBa8)
|
||||
Rgba8 - RGBA, 8 bits x 4, legacy name
|
||||
Bgra8 - BGRA, 8 bits x 4 (PFNC:BGRa8)
|
||||
Rgba10 - RGBA, 10 bits in 16 bits x 4
|
||||
Bgra10 - BGRA, 10 bits in 16 bits x 4
|
||||
Rgba12 - RGBA, 12 bits in 16 bits x 4
|
||||
Bgra12 - BGRA, 12 bits in 16 bits x 4
|
||||
Rgba14 - RGBA, 14 bits in 16 bits x 4
|
||||
Bgra14 - BGRA, 14 bits in 16 bits x 4
|
||||
Rgba16 - RGBA, 16 bits x 4
|
||||
Bgra16 - BGRA, 16 bits x 4
|
||||
|
||||
YUV/YCbCr formats:
|
||||
Yuv411 - YUV 411 with 8 bits (GEV:YUV411Packed)
|
||||
Yuv422 - YUV 422 with 8 bits (GEV:YUV422Packed)
|
||||
Yuv444 - YUV 444 with 8 bits (GEV:YUV444Packed)
|
||||
YCbCr411_8_CbYYCrYY - Y´CbCr 411 with 8 bits
|
||||
(PFNC:YCbCr411_8_CbYYCrYY) - identical to Yuv411
|
||||
YCbCr422_8_CbYCrY - Y´CbCr 422 with 8 bits
|
||||
(PFNC:YCbCr422_8_CbYCrY) - identical to Yuv422
|
||||
YCbCr8_CbYCr - Y´CbCr 444 with 8 bits
|
||||
(PFNC:YCbCr8_CbYCr) - identical to Yuv444
|
||||
"""
|
||||
None_ = 0
|
||||
Mono8 = _VmbPixel.Mono | _VmbPixelOccupy.Bit8 | 0x0001
|
||||
Mono10 = _VmbPixel.Mono | _VmbPixelOccupy.Bit16 | 0x0003
|
||||
Mono10p = _VmbPixel.Mono | _VmbPixelOccupy.Bit10 | 0x0046
|
||||
Mono12 = _VmbPixel.Mono | _VmbPixelOccupy.Bit16 | 0x0005
|
||||
Mono12Packed = _VmbPixel.Mono | _VmbPixelOccupy.Bit12 | 0x0006
|
||||
Mono12p = _VmbPixel.Mono | _VmbPixelOccupy.Bit12 | 0x0047
|
||||
Mono14 = _VmbPixel.Mono | _VmbPixelOccupy.Bit16 | 0x0025
|
||||
Mono16 = _VmbPixel.Mono | _VmbPixelOccupy.Bit16 | 0x0007
|
||||
BayerGR8 = _VmbPixel.Mono | _VmbPixelOccupy.Bit8 | 0x0008
|
||||
BayerRG8 = _VmbPixel.Mono | _VmbPixelOccupy.Bit8 | 0x0009
|
||||
BayerGB8 = _VmbPixel.Mono | _VmbPixelOccupy.Bit8 | 0x000A
|
||||
BayerBG8 = _VmbPixel.Mono | _VmbPixelOccupy.Bit8 | 0x000B
|
||||
BayerGR10 = _VmbPixel.Mono | _VmbPixelOccupy.Bit16 | 0x000C
|
||||
BayerRG10 = _VmbPixel.Mono | _VmbPixelOccupy.Bit16 | 0x000D
|
||||
BayerGB10 = _VmbPixel.Mono | _VmbPixelOccupy.Bit16 | 0x000E
|
||||
BayerBG10 = _VmbPixel.Mono | _VmbPixelOccupy.Bit16 | 0x000F
|
||||
BayerGR12 = _VmbPixel.Mono | _VmbPixelOccupy.Bit16 | 0x0010
|
||||
BayerRG12 = _VmbPixel.Mono | _VmbPixelOccupy.Bit16 | 0x0011
|
||||
BayerGB12 = _VmbPixel.Mono | _VmbPixelOccupy.Bit16 | 0x0012
|
||||
BayerBG12 = _VmbPixel.Mono | _VmbPixelOccupy.Bit16 | 0x0013
|
||||
BayerGR12Packed = _VmbPixel.Mono | _VmbPixelOccupy.Bit12 | 0x002A
|
||||
BayerRG12Packed = _VmbPixel.Mono | _VmbPixelOccupy.Bit12 | 0x002B
|
||||
BayerGB12Packed = _VmbPixel.Mono | _VmbPixelOccupy.Bit12 | 0x002C
|
||||
BayerBG12Packed = _VmbPixel.Mono | _VmbPixelOccupy.Bit12 | 0x002D
|
||||
BayerGR10p = _VmbPixel.Mono | _VmbPixelOccupy.Bit10 | 0x0056
|
||||
BayerRG10p = _VmbPixel.Mono | _VmbPixelOccupy.Bit10 | 0x0058
|
||||
BayerGB10p = _VmbPixel.Mono | _VmbPixelOccupy.Bit10 | 0x0054
|
||||
BayerBG10p = _VmbPixel.Mono | _VmbPixelOccupy.Bit10 | 0x0052
|
||||
BayerGR12p = _VmbPixel.Mono | _VmbPixelOccupy.Bit12 | 0x0057
|
||||
BayerRG12p = _VmbPixel.Mono | _VmbPixelOccupy.Bit12 | 0x0059
|
||||
BayerGB12p = _VmbPixel.Mono | _VmbPixelOccupy.Bit12 | 0x0055
|
||||
BayerBG12p = _VmbPixel.Mono | _VmbPixelOccupy.Bit12 | 0x0053
|
||||
BayerGR16 = _VmbPixel.Mono | _VmbPixelOccupy.Bit16 | 0x002E
|
||||
BayerRG16 = _VmbPixel.Mono | _VmbPixelOccupy.Bit16 | 0x002F
|
||||
BayerGB16 = _VmbPixel.Mono | _VmbPixelOccupy.Bit16 | 0x0030
|
||||
BayerBG16 = _VmbPixel.Mono | _VmbPixelOccupy.Bit16 | 0x0031
|
||||
Rgb8 = _VmbPixel.Color | _VmbPixelOccupy.Bit24 | 0x0014
|
||||
Bgr8 = _VmbPixel.Color | _VmbPixelOccupy.Bit24 | 0x0015
|
||||
Rgb10 = _VmbPixel.Color | _VmbPixelOccupy.Bit48 | 0x0018
|
||||
Bgr10 = _VmbPixel.Color | _VmbPixelOccupy.Bit48 | 0x0019
|
||||
Rgb12 = _VmbPixel.Color | _VmbPixelOccupy.Bit48 | 0x001A
|
||||
Bgr12 = _VmbPixel.Color | _VmbPixelOccupy.Bit48 | 0x001B
|
||||
Rgb14 = _VmbPixel.Color | _VmbPixelOccupy.Bit48 | 0x005E
|
||||
Bgr14 = _VmbPixel.Color | _VmbPixelOccupy.Bit48 | 0x004A
|
||||
Rgb16 = _VmbPixel.Color | _VmbPixelOccupy.Bit48 | 0x0033
|
||||
Bgr16 = _VmbPixel.Color | _VmbPixelOccupy.Bit48 | 0x004B
|
||||
Argb8 = _VmbPixel.Color | _VmbPixelOccupy.Bit32 | 0x0016
|
||||
Rgba8 = Argb8
|
||||
Bgra8 = _VmbPixel.Color | _VmbPixelOccupy.Bit32 | 0x0017
|
||||
Rgba10 = _VmbPixel.Color | _VmbPixelOccupy.Bit64 | 0x005F
|
||||
Bgra10 = _VmbPixel.Color | _VmbPixelOccupy.Bit64 | 0x004C
|
||||
Rgba12 = _VmbPixel.Color | _VmbPixelOccupy.Bit64 | 0x0061
|
||||
Bgra12 = _VmbPixel.Color | _VmbPixelOccupy.Bit64 | 0x004E
|
||||
Rgba14 = _VmbPixel.Color | _VmbPixelOccupy.Bit64 | 0x0063
|
||||
Bgra14 = _VmbPixel.Color | _VmbPixelOccupy.Bit64 | 0x0050
|
||||
Rgba16 = _VmbPixel.Color | _VmbPixelOccupy.Bit64 | 0x0064
|
||||
Bgra16 = _VmbPixel.Color | _VmbPixelOccupy.Bit64 | 0x0051
|
||||
Yuv411 = _VmbPixel.Color | _VmbPixelOccupy.Bit12 | 0x001E
|
||||
Yuv422 = _VmbPixel.Color | _VmbPixelOccupy.Bit16 | 0x001F
|
||||
Yuv444 = _VmbPixel.Color | _VmbPixelOccupy.Bit24 | 0x0020
|
||||
YCbCr411_8_CbYYCrYY = _VmbPixel.Color | _VmbPixelOccupy.Bit12 | 0x003C
|
||||
YCbCr422_8_CbYCrY = _VmbPixel.Color | _VmbPixelOccupy.Bit16 | 0x0043
|
||||
YCbCr8_CbYCr = _VmbPixel.Color | _VmbPixelOccupy.Bit24 | 0x003A
|
||||
|
||||
def __str__(self):
|
||||
return self._name_
|
||||
|
||||
|
||||
class VimbaCError(Exception):
|
||||
"""Error Type containing an error code from the C-Layer. This error code is highly context
|
||||
sensitive. All wrapped C-Functions that do not return VmbError.Success or None must
|
||||
raise a VimbaCError and the surrounding code must deal if the Error is possible.
|
||||
"""
|
||||
|
||||
def __init__(self, c_error: VmbError):
|
||||
super().__init__(repr(c_error))
|
||||
self.__c_error = c_error
|
||||
|
||||
def __str__(self):
|
||||
return repr(self)
|
||||
|
||||
def __repr__(self):
|
||||
return 'VimbaCError({})'.format(repr(self.__c_error))
|
||||
|
||||
def get_error_code(self) -> VmbError:
|
||||
""" Get contained Error Code """
|
||||
return self.__c_error
|
||||
|
||||
|
||||
# Utility Functions
|
||||
def _split_into_powers_of_two(num: int) -> Tuple[int, ...]:
|
||||
result = []
|
||||
for mask in [1 << i for i in range(32)]:
|
||||
if mask & num:
|
||||
result.append(mask)
|
||||
|
||||
if not result:
|
||||
result.append(0)
|
||||
|
||||
return tuple(result)
|
||||
|
||||
|
||||
def _split_flags_into_enum(num: int, enum_type):
|
||||
return [enum_type(val) for val in _split_into_powers_of_two(num)]
|
||||
|
||||
|
||||
def _repr_flags_list(enum_type, flag_val: int):
|
||||
values = _split_flags_into_enum(flag_val, enum_type)
|
||||
|
||||
if values:
|
||||
def fold_func(acc, arg):
|
||||
return '{} {}'.format(acc, repr(arg))
|
||||
|
||||
return functools.reduce(fold_func, values, '')
|
||||
|
||||
else:
|
||||
return '{}'.format(repr(enum_type(0)))
|
||||
|
||||
|
||||
def decode_cstr(val: bytes) -> str:
|
||||
"""Converts c_char_p stored in interface structures to a str.
|
||||
|
||||
Arguments:
|
||||
val - Byte sequence to convert into str.
|
||||
|
||||
Returns:
|
||||
str represented by 'val'
|
||||
"""
|
||||
return val.decode() if val else ''
|
||||
|
||||
|
||||
def decode_flags(enum_type, enum_val: int):
|
||||
"""Splits C-styled bit mask into a set of flags from a given Enumeration.
|
||||
|
||||
Arguments:
|
||||
enum_val - Bit mask to decode.
|
||||
enum_type - Enum Type represented within 'enum_val'
|
||||
|
||||
Returns:
|
||||
A set of all values of enum_type occurring in enum_val.
|
||||
|
||||
Raises:
|
||||
Attribute error a set value is not within the given 'enum_type'.
|
||||
"""
|
||||
|
||||
return tuple(_split_flags_into_enum(enum_val, enum_type))
|
||||
|
||||
|
||||
def fmt_repr(fmt: str, val):
|
||||
"""Append repr to a format string."""
|
||||
return fmt.format(repr(val))
|
||||
|
||||
|
||||
def fmt_enum_repr(fmt: str, enum_type, enum_val):
|
||||
"""Append repr of a given enum type to a format string.
|
||||
|
||||
Arguments:
|
||||
fmt - Format string
|
||||
enum_type - Enum Type to construct.
|
||||
enum_val - Enum value.
|
||||
|
||||
Returns:
|
||||
formatted string
|
||||
"""
|
||||
return fmt.format(repr(enum_type(enum_val)))
|
||||
|
||||
|
||||
def fmt_flags_repr(fmt: str, enum_type, enum_val):
|
||||
"""Append repr of a c-style flag value in the form of a set containing
|
||||
all bits set from a given enum_type.
|
||||
|
||||
Arguments:
|
||||
fmt - Format string
|
||||
enum_type - Enum Type to construct.
|
||||
enum_val - Enum value.
|
||||
|
||||
Returns:
|
||||
formatted string
|
||||
"""
|
||||
return fmt.format(_repr_flags_list(enum_type, enum_val))
|
||||
|
||||
|
||||
def load_vimba_lib(vimba_project: str):
|
||||
""" Load shared library shipped with the Vimba installation
|
||||
|
||||
Arguments:
|
||||
vimba_project - Library name without prefix or extension
|
||||
|
||||
Return:
|
||||
CDLL or WinDLL Handle on loaded library
|
||||
|
||||
Raises:
|
||||
VimbaSystemError if given library could not be loaded.
|
||||
"""
|
||||
|
||||
platform_handlers = {
|
||||
'linux': _load_under_linux,
|
||||
'win32': _load_under_windows
|
||||
}
|
||||
|
||||
if sys.platform not in platform_handlers:
|
||||
msg = 'Abort. Unsupported Platform ({}) detected.'
|
||||
raise VimbaSystemError(msg.format(sys.platform))
|
||||
|
||||
return platform_handlers[sys.platform](vimba_project)
|
||||
|
||||
|
||||
def _load_under_linux(vimba_project: str):
|
||||
# Construct VimbaHome based on TL installation paths
|
||||
path_list: List[str] = []
|
||||
tl32_path = os.environ.get('GENICAM_GENTL32_PATH', "")
|
||||
if tl32_path:
|
||||
path_list += tl32_path.split(':')
|
||||
tl64_path = os.environ.get('GENICAM_GENTL64_PATH', "")
|
||||
if tl64_path:
|
||||
path_list += tl64_path.split(':')
|
||||
|
||||
# Remove empty strings from path_list if there are any.
|
||||
# Necessary because the GENICAM_GENTLXX_PATH variable might start with a :
|
||||
path_list = [path for path in path_list if path]
|
||||
|
||||
# Early return if required variables are not set.
|
||||
if not path_list:
|
||||
raise VimbaSystemError('No TL detected. Please verify Vimba installation.')
|
||||
|
||||
vimba_home_candidates: List[str] = []
|
||||
for path in path_list:
|
||||
vimba_home = os.path.dirname(os.path.dirname(os.path.dirname(path)))
|
||||
|
||||
if vimba_home not in vimba_home_candidates:
|
||||
vimba_home_candidates.append(vimba_home)
|
||||
|
||||
# Select the most likely directory from the candidates
|
||||
vimba_home = _select_vimba_home(vimba_home_candidates)
|
||||
|
||||
arch = platform.machine()
|
||||
|
||||
# Linux x86 64 Bit (Requires additional interpreter version check)
|
||||
if arch == 'x86_64':
|
||||
dir_ = 'x86_64bit' if _is_python_64_bit() else 'x86_32bit'
|
||||
|
||||
# Linux x86 32 Bit
|
||||
elif arch in ('i386', 'i686'):
|
||||
dir_ = 'x86_32bit'
|
||||
|
||||
# Linux arm 64 Bit (Requires additional interpreter version check)
|
||||
elif arch == 'aarch64':
|
||||
dir_ = 'arm_64bit' if _is_python_64_bit() else 'arm_32bit'
|
||||
|
||||
# Linux arm 32 Bit:
|
||||
elif arch == 'armv7l':
|
||||
dir_ = 'arm_32bit'
|
||||
|
||||
else:
|
||||
raise VimbaSystemError('Unknown Architecture \'{}\'. Abort'.format(arch))
|
||||
|
||||
lib_name = 'lib{}.so'.format(vimba_project)
|
||||
lib_path = os.path.join(vimba_home, vimba_project, 'DynamicLib', dir_, lib_name)
|
||||
|
||||
try:
|
||||
lib = ctypes.cdll.LoadLibrary(lib_path)
|
||||
|
||||
except OSError as e:
|
||||
msg = 'Failed to load library \'{}\'. Please verify Vimba installation.'
|
||||
raise VimbaSystemError(msg.format(lib_path)) from e
|
||||
|
||||
return lib
|
||||
|
||||
|
||||
def _load_under_windows(vimba_project: str):
|
||||
vimba_home = os.environ.get('VIMBA_HOME')
|
||||
|
||||
if vimba_home is None:
|
||||
raise VimbaSystemError('Variable VIMBA_HOME not set. Please verify Vimba installation.')
|
||||
|
||||
load_64bit = True if (platform.machine() == 'AMD64') and _is_python_64_bit() else False
|
||||
lib_name = '{}.dll'.format(vimba_project)
|
||||
lib_path = os.path.join(vimba_home, vimba_project, 'Bin', 'Win64' if load_64bit else 'Win32',
|
||||
lib_name)
|
||||
|
||||
try:
|
||||
# Load Library with 64 Bit and use cdecl call convention
|
||||
if load_64bit:
|
||||
lib = ctypes.cdll.LoadLibrary(lib_path)
|
||||
|
||||
# Load Library with 32 Bit and use stdcall call convention
|
||||
else:
|
||||
# Tell mypy to ignore this line to allow type checking on both windows and linux as
|
||||
# windll is not available on linux and would therefore produce an error there
|
||||
lib = ctypes.windll.LoadLibrary(lib_path) # type: ignore
|
||||
|
||||
except OSError as e:
|
||||
msg = 'Failed to load library \'{}\'. Please verify Vimba installation.'
|
||||
raise VimbaSystemError(msg.format(lib_path)) from e
|
||||
|
||||
return lib
|
||||
|
||||
|
||||
def _select_vimba_home(candidates: List[str]) -> str:
|
||||
"""
|
||||
Select the most likely candidate for VIMBA_HOME from the given list of
|
||||
candidates
|
||||
|
||||
Arguments:
|
||||
candidates - List of strings pointing to possible vimba home directories
|
||||
|
||||
Return:
|
||||
Path that represents the most likely VIMBA_HOME directory
|
||||
|
||||
Raises:
|
||||
VimbaSystemError if multiple VIMBA_HOME directories were found in candidates
|
||||
"""
|
||||
most_likely_candidates = []
|
||||
for candidate in candidates:
|
||||
if 'vimba' in candidate.lower():
|
||||
most_likely_candidates.append(candidate)
|
||||
|
||||
if len(most_likely_candidates) == 0:
|
||||
raise VimbaSystemError('No suitable Vimba installation found. The following paths '
|
||||
'were considered: {}'.format(candidates))
|
||||
elif len(most_likely_candidates) > 1:
|
||||
raise VimbaSystemError('Multiple Vimba installations found. Can\'t decide which to select: '
|
||||
'{}'.format(most_likely_candidates))
|
||||
|
||||
return most_likely_candidates[0]
|
||||
|
||||
|
||||
def _is_python_64_bit() -> bool:
|
||||
# Query if the currently running python interpreter is build as 64 bit binary.
|
||||
# The default method of getting this information seems to be rather hacky
|
||||
# (check if maxint > 2^32) but it seems to be the way to do this....
|
||||
return True if sys.maxsize > 2**32 else False
|
||||
@@ -0,0 +1,569 @@
|
||||
"""BSD 2-Clause License
|
||||
|
||||
Copyright (c) 2019, Allied Vision Technologies GmbH
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions are met:
|
||||
|
||||
1. Redistributions of source code must retain the above copyright notice, this
|
||||
list of conditions and the following disclaimer.
|
||||
|
||||
2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
this list of conditions and the following disclaimer in the documentation
|
||||
and/or other materials provided with the distribution.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
||||
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
||||
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
"""
|
||||
|
||||
import ctypes
|
||||
import sys
|
||||
from ctypes import byref, sizeof, c_char_p, POINTER as c_ptr
|
||||
from typing import Callable, Any, Tuple, Dict, List
|
||||
|
||||
from ..error import VimbaSystemError
|
||||
from ..util import TraceEnable
|
||||
from .vimba_common import Uint32Enum, VmbUint32, VmbInt32, VmbError, VmbFloat, VimbaCError, \
|
||||
VmbPixelFormat, load_vimba_lib, fmt_repr, fmt_enum_repr
|
||||
|
||||
|
||||
__all__ = [
|
||||
'VmbBayerPattern',
|
||||
'VmbEndianness',
|
||||
'VmbAligment',
|
||||
'VmbAPIInfo',
|
||||
'VmbPixelLayout',
|
||||
'VmbDebayerMode',
|
||||
'VmbImage',
|
||||
'VmbImageInfo',
|
||||
'VmbTransformInfo',
|
||||
'VIMBA_IMAGE_TRANSFORM_VERSION',
|
||||
'EXPECTED_VIMBA_IMAGE_TRANSFORM_VERSION',
|
||||
'call_vimba_image_transform',
|
||||
'PIXEL_FORMAT_TO_LAYOUT',
|
||||
'LAYOUT_TO_PIXEL_FORMAT',
|
||||
'PIXEL_FORMAT_CONVERTIBILITY_MAP'
|
||||
]
|
||||
|
||||
|
||||
class VmbBayerPattern(Uint32Enum):
|
||||
"""Enum defining BayerPatterns
|
||||
Values:
|
||||
RGGB - RGGB pattern, red pixel comes first
|
||||
GBRG - RGGB pattern, green pixel of blue row comes first
|
||||
GRBG - RGGB pattern, green pixel of red row comes first
|
||||
BGGR - RGGB pattern, blue pixel comes first
|
||||
CYGM - CYGM pattern, cyan pixel comes first in the first row, green in the second row
|
||||
GMCY - CYGM pattern, green pixel comes first in the first row, cyan in the second row
|
||||
CYMG - CYGM pattern, cyan pixel comes first in the first row, magenta in the second row
|
||||
MGCY - CYGM pattern, magenta pixel comes first in the first row, cyan in the second row
|
||||
LAST - Indicator for end of defined range
|
||||
"""
|
||||
RGGB = 0
|
||||
GBRG = 1
|
||||
GRBG = 2
|
||||
BGGR = 3
|
||||
CYGM = 128
|
||||
GMCY = 129
|
||||
CYMG = 130
|
||||
MGCY = 131
|
||||
LAST = 255
|
||||
|
||||
def __str__(self):
|
||||
return self._name_
|
||||
|
||||
|
||||
class VmbEndianness(Uint32Enum):
|
||||
"""Enum defining Endian Formats
|
||||
Values:
|
||||
LITTLE - Little Endian
|
||||
BIG - Big Endian
|
||||
LAST - Indicator for end of defined range
|
||||
"""
|
||||
LITTLE = 0
|
||||
BIG = 1
|
||||
LAST = 255
|
||||
|
||||
def __str__(self):
|
||||
return self._name_
|
||||
|
||||
|
||||
class VmbAligment(Uint32Enum):
|
||||
"""Enum defining image alignment
|
||||
Values:
|
||||
MSB - Alignment (pppp pppp pppp ....)
|
||||
LSB - Alignment (.... pppp pppp pppp)
|
||||
LAST - Indicator for end of defined range
|
||||
"""
|
||||
MSB = 0
|
||||
LSB = 1
|
||||
LAST = 255
|
||||
|
||||
def __str__(self):
|
||||
return self._name_
|
||||
|
||||
|
||||
class VmbAPIInfo(Uint32Enum):
|
||||
"""API Info Types
|
||||
Values:
|
||||
ALL - All Infos
|
||||
PLATFORM - Platform the API was built for
|
||||
BUILD - Build Types (debug or release)
|
||||
TECHNOLOGY - Special technology info
|
||||
LAST - Indicator for end of defined range
|
||||
"""
|
||||
ALL = 0
|
||||
PLATFORM = 1
|
||||
BUILD = 2
|
||||
TECHNOLOGY = 3
|
||||
LAST = 4
|
||||
|
||||
def __str__(self):
|
||||
return self._name_
|
||||
|
||||
|
||||
class VmbPixelLayout(Uint32Enum):
|
||||
"""Image Pixel Layout Information. C Header offers no further documentation."""
|
||||
Mono = 0
|
||||
MonoPacked = 1
|
||||
Raw = 2
|
||||
RawPacked = 3
|
||||
RGB = 4
|
||||
BGR = 5
|
||||
RGBA = 6
|
||||
BGRA = 7
|
||||
YUV411 = 8
|
||||
YUV422 = 9
|
||||
YUV444 = 10
|
||||
MonoP = 11
|
||||
MonoPl = 12
|
||||
RawP = 13
|
||||
RawPl = 14
|
||||
YYCbYYCr411 = 15
|
||||
CbYYCrYY411 = YUV411,
|
||||
YCbYCr422 = 16
|
||||
CbYCrY422 = YUV422
|
||||
YCbCr444 = 17
|
||||
CbYCr444 = YUV444
|
||||
LAST = 19
|
||||
|
||||
def __str__(self):
|
||||
return self._name_
|
||||
|
||||
|
||||
class VmbColorSpace(Uint32Enum):
|
||||
"""Image Color space. C Header offers no further documentation."""
|
||||
Undefined = 0
|
||||
ITU_BT709 = 1
|
||||
ITU_BT601 = 2
|
||||
|
||||
def __str__(self):
|
||||
return self._name_
|
||||
|
||||
|
||||
class VmbDebayerMode(Uint32Enum):
|
||||
"""Debayer Mode. C Header offers no further documentation."""
|
||||
Mode_2x2 = 0
|
||||
Mode_3x3 = 1
|
||||
Mode_LCAA = 2
|
||||
Mode_LCAAV = 3
|
||||
Mode_YUV422 = 4
|
||||
|
||||
def __str__(self):
|
||||
return self._name_
|
||||
|
||||
|
||||
class VmbTransformType(Uint32Enum):
|
||||
"""TransformType Mode. C Header offers no further documentation."""
|
||||
None_ = 0
|
||||
DebayerMode = 1
|
||||
ColorCorrectionMatrix = 2
|
||||
GammaCorrection = 3
|
||||
Offset = 4
|
||||
Gain = 5
|
||||
|
||||
def __str__(self):
|
||||
return self._name_
|
||||
|
||||
|
||||
class VmbPixelInfo(ctypes.Structure):
|
||||
"""Structure containing pixel information. Sadly c_header contains no more documentation"""
|
||||
_fields_ = [
|
||||
('BitsPerPixel', VmbUint32),
|
||||
('BitsUsed', VmbUint32),
|
||||
('Alignment', VmbUint32),
|
||||
('Endianness', VmbUint32),
|
||||
('PixelLayout', VmbUint32),
|
||||
('BayerPattern', VmbUint32),
|
||||
('Reserved', VmbUint32)
|
||||
]
|
||||
|
||||
def __repr__(self):
|
||||
rep = 'VmbPixelInfo'
|
||||
rep += fmt_repr('(BitsPerPixel={}', self.BitsPerPixel)
|
||||
rep += fmt_repr(',BitsUsed={}', self.BitsUsed)
|
||||
rep += fmt_enum_repr(',Alignment={}', VmbAligment, self.Alignment)
|
||||
rep += fmt_enum_repr(',Endianness={}', VmbEndianness, self.Endianness)
|
||||
rep += fmt_enum_repr(',PixelLayout={}', VmbPixelLayout, self.PixelLayout)
|
||||
rep += fmt_enum_repr(',BayerPattern={}', VmbBayerPattern, self.BayerPattern)
|
||||
rep += fmt_enum_repr(',Reserved={}', VmbColorSpace, self.Reserved)
|
||||
rep += ')'
|
||||
return rep
|
||||
|
||||
|
||||
class VmbImageInfo(ctypes.Structure):
|
||||
"""Structure containing image information. Sadly c_header contains no more documentation"""
|
||||
_fields_ = [
|
||||
('Width', VmbUint32),
|
||||
('Height', VmbUint32),
|
||||
('Stride', VmbInt32),
|
||||
('PixelInfo', VmbPixelInfo)
|
||||
]
|
||||
|
||||
def __repr__(self):
|
||||
rep = 'VmbImageInfo'
|
||||
rep += fmt_repr('(Width={}', self.Width)
|
||||
rep += fmt_repr(',Height={}', self.Height)
|
||||
rep += fmt_repr(',Stride={}', self.Stride)
|
||||
rep += fmt_repr(',PixelInfo={}', self.PixelInfo)
|
||||
rep += ')'
|
||||
return rep
|
||||
|
||||
|
||||
class VmbImage(ctypes.Structure):
|
||||
"""Structure containing image. Sadly c_header contains no more documentation"""
|
||||
_fields_ = [
|
||||
('Size', VmbUint32),
|
||||
('Data', ctypes.c_void_p),
|
||||
('ImageInfo', VmbImageInfo)
|
||||
]
|
||||
|
||||
def __repr__(self):
|
||||
rep = 'VmbImage'
|
||||
rep += fmt_repr('(Size={}', self.Size)
|
||||
rep += fmt_repr(',Data={}', self.Data)
|
||||
rep += fmt_repr(',ImageInfo={}', self.ImageInfo)
|
||||
rep += ')'
|
||||
return rep
|
||||
|
||||
|
||||
class VmbTransformParameterMatrix3x3(ctypes.Structure):
|
||||
"""Sadly c_header contains no more documentation"""
|
||||
_fields_ = [
|
||||
('Matrix', VmbFloat * 9)
|
||||
]
|
||||
|
||||
|
||||
class VmbTransformParameterGamma(ctypes.Structure):
|
||||
"""Sadly c_header contains no more documentation"""
|
||||
_fields_ = [
|
||||
('Gamma', VmbFloat)
|
||||
]
|
||||
|
||||
|
||||
class VmbTransformParameterDebayer(ctypes.Structure):
|
||||
"""Sadly c_header contains no more documentation"""
|
||||
_fields_ = [
|
||||
('Method', VmbUint32)
|
||||
]
|
||||
|
||||
|
||||
class VmbTransformParameterOffset(ctypes.Structure):
|
||||
"""Sadly c_header contains no more documentation"""
|
||||
_fields_ = [
|
||||
('Offset', VmbInt32)
|
||||
]
|
||||
|
||||
|
||||
class VmbTransformParameterGain(ctypes.Structure):
|
||||
"""Sadly c_header contains no more documentation"""
|
||||
_fields_ = [
|
||||
('Gain', VmbUint32)
|
||||
]
|
||||
|
||||
|
||||
class VmbTransformParameter(ctypes.Union):
|
||||
"""Sadly c_header contains no more documentation"""
|
||||
_fields_ = [
|
||||
('Matrix3x3', VmbTransformParameterMatrix3x3),
|
||||
('Debayer', VmbTransformParameterDebayer),
|
||||
('Gamma', VmbTransformParameterGamma),
|
||||
('Offset', VmbTransformParameterOffset),
|
||||
('Gain', VmbTransformParameterGain)
|
||||
]
|
||||
|
||||
|
||||
class VmbTransformInfo(ctypes.Structure):
|
||||
"""Struct holding transformation information"""
|
||||
_fields_ = [
|
||||
('TransformType', VmbUint32),
|
||||
('Parameter', VmbTransformParameter)
|
||||
]
|
||||
|
||||
|
||||
# API
|
||||
VIMBA_IMAGE_TRANSFORM_VERSION = None
|
||||
if sys.platform == 'linux':
|
||||
EXPECTED_VIMBA_IMAGE_TRANSFORM_VERSION = '1.0'
|
||||
|
||||
else:
|
||||
EXPECTED_VIMBA_IMAGE_TRANSFORM_VERSION = '1.6'
|
||||
|
||||
# For detailed information on the signatures see "VimbaImageTransform.h"
|
||||
# To improve readability, suppress 'E501 line too long (> 100 characters)'
|
||||
# check of flake8
|
||||
_SIGNATURES = {
|
||||
'VmbGetVersion': (VmbError, [c_ptr(VmbUint32)]),
|
||||
'VmbGetErrorInfo': (VmbError, [VmbError, c_char_p, VmbUint32]),
|
||||
'VmbGetApiInfoString': (VmbError, [VmbAPIInfo, c_char_p, VmbUint32]),
|
||||
'VmbSetDebayerMode': (VmbError, [VmbDebayerMode, c_ptr(VmbTransformInfo)]),
|
||||
'VmbSetColorCorrectionMatrix3x3': (VmbError, [c_ptr(VmbFloat), c_ptr(VmbTransformInfo)]),
|
||||
'VmbSetGammaCorrection': (VmbError, [VmbFloat, c_ptr(VmbTransformInfo)]),
|
||||
'VmbSetImageInfoFromPixelFormat': (VmbError, [VmbPixelFormat, VmbUint32, VmbUint32, c_ptr(VmbImage)]), # noqa: E501
|
||||
'VmbSetImageInfoFromString': (VmbError, [c_char_p, VmbUint32, VmbUint32, VmbUint32, c_ptr(VmbImage)]), # noqa: E501
|
||||
'VmbSetImageInfoFromInputParameters': (VmbError, [VmbPixelFormat, VmbUint32, VmbUint32, VmbPixelLayout, VmbUint32, c_ptr(VmbImage)]), # noqa: E501
|
||||
'VmbSetImageInfoFromInputImage': (VmbError, [c_ptr(VmbImage), VmbPixelLayout, VmbUint32, c_ptr(VmbImage)]), # noqa: E501
|
||||
'VmbImageTransform': (VmbError, [c_ptr(VmbImage), c_ptr(VmbImage), c_ptr(VmbTransformInfo), VmbUint32]) # noqa: E501
|
||||
}
|
||||
|
||||
|
||||
def _attach_signatures(lib_handle):
|
||||
global _SIGNATURES
|
||||
|
||||
for function_name, signature in _SIGNATURES.items():
|
||||
fn = getattr(lib_handle, function_name)
|
||||
fn.restype, fn.argtypes = signature
|
||||
fn.errcheck = _eval_vmberror
|
||||
|
||||
return lib_handle
|
||||
|
||||
|
||||
def _check_version(lib_handle):
|
||||
global EXPECTED_VIMBA_IMAGE_TRANSFORM_VERSION
|
||||
global VIMBA_IMAGE_TRANSFORM_VERSION
|
||||
|
||||
v = VmbUint32()
|
||||
lib_handle.VmbGetVersion(byref(v))
|
||||
|
||||
VIMBA_IMAGE_TRANSFORM_VERSION = '{}.{}'.format((v.value >> 24) & 0xff, (v.value >> 16) & 0xff)
|
||||
|
||||
loaded_version = tuple(map(int, VIMBA_IMAGE_TRANSFORM_VERSION.split(".")))
|
||||
expected_version = tuple(map(int, EXPECTED_VIMBA_IMAGE_TRANSFORM_VERSION.split(".")))
|
||||
# Major version must match. minor version may be equal or greater
|
||||
if not(loaded_version[0] == expected_version[0] and
|
||||
loaded_version[1] >= expected_version[1]):
|
||||
msg = 'Invalid VimbaImageTransform Version: Expected: {}, Found:{}'
|
||||
raise VimbaSystemError(msg.format(EXPECTED_VIMBA_IMAGE_TRANSFORM_VERSION,
|
||||
VIMBA_IMAGE_TRANSFORM_VERSION))
|
||||
|
||||
return lib_handle
|
||||
|
||||
|
||||
def _eval_vmberror(result: VmbError, func: Callable[..., Any], *args: Tuple[Any, ...]):
|
||||
if result not in (VmbError.Success, None):
|
||||
raise VimbaCError(result)
|
||||
|
||||
|
||||
_lib_instance = _check_version(_attach_signatures(load_vimba_lib('VimbaImageTransform')))
|
||||
|
||||
|
||||
@TraceEnable()
|
||||
def call_vimba_image_transform(func_name: str, *args):
|
||||
"""This function encapsulates the entire VimbaImageTransform access.
|
||||
|
||||
For Details on valid function signatures see the 'VimbaImageTransform.h'.
|
||||
|
||||
Arguments:
|
||||
func_name: The function name from VimbaImageTransform to be called.
|
||||
args: Varargs passed directly to the underlaying C-Function.
|
||||
|
||||
Raises:
|
||||
TypeError if given are do not match the signature of the function.
|
||||
AttributeError if func with name 'func_name' does not exist.
|
||||
VimbaCError if the function call is valid but neither None or VmbError.Success was returned.
|
||||
|
||||
The following functions of VimbaImageTransform can be executed:
|
||||
VmbGetVersion
|
||||
VmbGetTechnoInfo
|
||||
VmbGetErrorInfo
|
||||
VmbGetApiInfoString
|
||||
VmbSetDebayerMode
|
||||
VmbSetColorCorrectionMatrix3x3
|
||||
VmbSetGammaCorrection
|
||||
VmbSetImageInfoFromPixelFormat
|
||||
VmbSetImageInfoFromString
|
||||
VmbSetImageInfoFromInputParameters
|
||||
VmbSetImageInfoFromInputImage
|
||||
VmbImageTransform
|
||||
"""
|
||||
|
||||
global _lib_instance
|
||||
getattr(_lib_instance, func_name)(*args)
|
||||
|
||||
|
||||
PIXEL_FORMAT_TO_LAYOUT: Dict[VmbPixelFormat, Tuple[VmbPixelLayout, int]] = {
|
||||
VmbPixelFormat.Mono8: (VmbPixelLayout.Mono, 8),
|
||||
VmbPixelFormat.Mono10: (VmbPixelLayout.Mono, 16),
|
||||
VmbPixelFormat.Mono12: (VmbPixelLayout.Mono, 16),
|
||||
VmbPixelFormat.Mono14: (VmbPixelLayout.Mono, 16),
|
||||
VmbPixelFormat.Mono16: (VmbPixelLayout.Mono, 16),
|
||||
VmbPixelFormat.BayerGR8: (VmbPixelLayout.Raw, 8),
|
||||
VmbPixelFormat.BayerRG8: (VmbPixelLayout.Raw, 8),
|
||||
VmbPixelFormat.BayerGB8: (VmbPixelLayout.Raw, 8),
|
||||
VmbPixelFormat.BayerBG8: (VmbPixelLayout.Raw, 8),
|
||||
VmbPixelFormat.BayerGR10: (VmbPixelLayout.Raw, 16),
|
||||
VmbPixelFormat.BayerRG10: (VmbPixelLayout.Raw, 16),
|
||||
VmbPixelFormat.BayerGB10: (VmbPixelLayout.Raw, 16),
|
||||
VmbPixelFormat.BayerBG10: (VmbPixelLayout.Raw, 16),
|
||||
VmbPixelFormat.BayerGR12: (VmbPixelLayout.Raw, 16),
|
||||
VmbPixelFormat.BayerRG12: (VmbPixelLayout.Raw, 16),
|
||||
VmbPixelFormat.BayerGB12: (VmbPixelLayout.Raw, 16),
|
||||
VmbPixelFormat.BayerBG12: (VmbPixelLayout.Raw, 16),
|
||||
VmbPixelFormat.BayerGR16: (VmbPixelLayout.Raw, 16),
|
||||
VmbPixelFormat.BayerRG16: (VmbPixelLayout.Raw, 16),
|
||||
VmbPixelFormat.BayerGB16: (VmbPixelLayout.Raw, 16),
|
||||
VmbPixelFormat.BayerBG16: (VmbPixelLayout.Raw, 16),
|
||||
VmbPixelFormat.Rgb8: (VmbPixelLayout.RGB, 8),
|
||||
VmbPixelFormat.Rgb10: (VmbPixelLayout.RGB, 16),
|
||||
VmbPixelFormat.Rgb12: (VmbPixelLayout.RGB, 16),
|
||||
VmbPixelFormat.Rgb14: (VmbPixelLayout.RGB, 16),
|
||||
VmbPixelFormat.Rgb16: (VmbPixelLayout.RGB, 16),
|
||||
VmbPixelFormat.Bgr8: (VmbPixelLayout.BGR, 8),
|
||||
VmbPixelFormat.Bgr10: (VmbPixelLayout.BGR, 16),
|
||||
VmbPixelFormat.Bgr12: (VmbPixelLayout.BGR, 16),
|
||||
VmbPixelFormat.Bgr14: (VmbPixelLayout.BGR, 16),
|
||||
VmbPixelFormat.Bgr16: (VmbPixelLayout.BGR, 16),
|
||||
VmbPixelFormat.Rgba8: (VmbPixelLayout.RGBA, 8),
|
||||
VmbPixelFormat.Rgba10: (VmbPixelLayout.RGBA, 16),
|
||||
VmbPixelFormat.Rgba12: (VmbPixelLayout.RGBA, 16),
|
||||
VmbPixelFormat.Rgba14: (VmbPixelLayout.RGBA, 16),
|
||||
VmbPixelFormat.Rgba16: (VmbPixelLayout.RGBA, 16),
|
||||
VmbPixelFormat.Bgra8: (VmbPixelLayout.BGRA, 8),
|
||||
VmbPixelFormat.Bgra10: (VmbPixelLayout.BGRA, 16),
|
||||
VmbPixelFormat.Bgra12: (VmbPixelLayout.BGRA, 16),
|
||||
VmbPixelFormat.Bgra14: (VmbPixelLayout.BGRA, 16),
|
||||
VmbPixelFormat.Bgra16: (VmbPixelLayout.BGRA, 16)
|
||||
}
|
||||
|
||||
LAYOUT_TO_PIXEL_FORMAT = dict([(v, k) for k, v in PIXEL_FORMAT_TO_LAYOUT.items()])
|
||||
|
||||
|
||||
def _query_compatibility(pixel_format: VmbPixelFormat) -> Tuple[VmbPixelFormat, ...]:
|
||||
global LAYOUT_TO_PIXEL_FORMAT
|
||||
|
||||
# Query compatible formats from ImageTransform
|
||||
output_pixel_layouts = (VmbPixelLayout.Mono, VmbPixelLayout.MonoPacked, VmbPixelLayout.Raw,
|
||||
VmbPixelLayout.RawPacked, VmbPixelLayout.RGB, VmbPixelLayout.BGR,
|
||||
VmbPixelLayout.RGBA, VmbPixelLayout.BGRA)
|
||||
|
||||
output_bits_per_pixel = (8, 16)
|
||||
output_layouts = tuple([(layouts, bits)
|
||||
for layouts in output_pixel_layouts
|
||||
for bits in output_bits_per_pixel])
|
||||
|
||||
result: List[VmbPixelFormat] = []
|
||||
|
||||
src_image = VmbImage()
|
||||
src_image.Size = sizeof(src_image)
|
||||
|
||||
call_vimba_image_transform('VmbSetImageInfoFromPixelFormat', pixel_format, 0, 0,
|
||||
byref(src_image))
|
||||
|
||||
dst_image = VmbImage()
|
||||
dst_image.Size = sizeof(dst_image)
|
||||
|
||||
for layout, bits in output_layouts:
|
||||
|
||||
try:
|
||||
call_vimba_image_transform('VmbSetImageInfoFromInputImage', byref(src_image), layout,
|
||||
bits, byref(dst_image))
|
||||
|
||||
fmt = LAYOUT_TO_PIXEL_FORMAT[(layout, bits)]
|
||||
|
||||
if fmt not in result:
|
||||
result.append(fmt)
|
||||
|
||||
except VimbaCError as e:
|
||||
if e.get_error_code() not in (VmbError.NotImplemented_, VmbError.BadParameter):
|
||||
raise e
|
||||
|
||||
return tuple(result)
|
||||
|
||||
|
||||
PIXEL_FORMAT_CONVERTIBILITY_MAP: Dict[VmbPixelFormat, Tuple[VmbPixelFormat, ...]] = {
|
||||
VmbPixelFormat.Mono8: _query_compatibility(VmbPixelFormat.Mono8),
|
||||
VmbPixelFormat.Mono10: _query_compatibility(VmbPixelFormat.Mono10),
|
||||
VmbPixelFormat.Mono10p: _query_compatibility(VmbPixelFormat.Mono10p),
|
||||
VmbPixelFormat.Mono12: _query_compatibility(VmbPixelFormat.Mono12),
|
||||
VmbPixelFormat.Mono12Packed: _query_compatibility(VmbPixelFormat.Mono12Packed),
|
||||
VmbPixelFormat.Mono12p: _query_compatibility(VmbPixelFormat.Mono12p),
|
||||
VmbPixelFormat.Mono14: _query_compatibility(VmbPixelFormat.Mono14),
|
||||
VmbPixelFormat.Mono16: _query_compatibility(VmbPixelFormat.Mono16),
|
||||
|
||||
VmbPixelFormat.BayerGR8: _query_compatibility(VmbPixelFormat.BayerGR8),
|
||||
VmbPixelFormat.BayerRG8: _query_compatibility(VmbPixelFormat.BayerRG8),
|
||||
VmbPixelFormat.BayerGB8: _query_compatibility(VmbPixelFormat.BayerGB8),
|
||||
VmbPixelFormat.BayerBG8: _query_compatibility(VmbPixelFormat.BayerBG8),
|
||||
VmbPixelFormat.BayerGR10: _query_compatibility(VmbPixelFormat.BayerGR10),
|
||||
VmbPixelFormat.BayerRG10: _query_compatibility(VmbPixelFormat.BayerRG10),
|
||||
VmbPixelFormat.BayerGB10: _query_compatibility(VmbPixelFormat.BayerGB10),
|
||||
VmbPixelFormat.BayerBG10: _query_compatibility(VmbPixelFormat.BayerBG10),
|
||||
VmbPixelFormat.BayerGR12: _query_compatibility(VmbPixelFormat.BayerGR12),
|
||||
VmbPixelFormat.BayerRG12: _query_compatibility(VmbPixelFormat.BayerRG12),
|
||||
VmbPixelFormat.BayerGB12: _query_compatibility(VmbPixelFormat.BayerGB12),
|
||||
VmbPixelFormat.BayerBG12: _query_compatibility(VmbPixelFormat.BayerBG12),
|
||||
VmbPixelFormat.BayerGR12Packed: _query_compatibility(VmbPixelFormat.BayerGR12Packed),
|
||||
VmbPixelFormat.BayerRG12Packed: _query_compatibility(VmbPixelFormat.BayerRG12Packed),
|
||||
VmbPixelFormat.BayerGB12Packed: _query_compatibility(VmbPixelFormat.BayerGB12Packed),
|
||||
VmbPixelFormat.BayerBG12Packed: _query_compatibility(VmbPixelFormat.BayerBG12Packed),
|
||||
VmbPixelFormat.BayerGR10p: _query_compatibility(VmbPixelFormat.BayerGR10p),
|
||||
VmbPixelFormat.BayerRG10p: _query_compatibility(VmbPixelFormat.BayerRG10p),
|
||||
VmbPixelFormat.BayerGB10p: _query_compatibility(VmbPixelFormat.BayerGB10p),
|
||||
VmbPixelFormat.BayerBG10p: _query_compatibility(VmbPixelFormat.BayerBG10p),
|
||||
VmbPixelFormat.BayerGR12p: _query_compatibility(VmbPixelFormat.BayerGR12p),
|
||||
VmbPixelFormat.BayerRG12p: _query_compatibility(VmbPixelFormat.BayerRG12p),
|
||||
VmbPixelFormat.BayerGB12p: _query_compatibility(VmbPixelFormat.BayerGB12p),
|
||||
VmbPixelFormat.BayerBG12p: _query_compatibility(VmbPixelFormat.BayerBG12p),
|
||||
VmbPixelFormat.BayerGR16: _query_compatibility(VmbPixelFormat.BayerGR16),
|
||||
VmbPixelFormat.BayerRG16: _query_compatibility(VmbPixelFormat.BayerRG16),
|
||||
VmbPixelFormat.BayerGB16: _query_compatibility(VmbPixelFormat.BayerGB16),
|
||||
VmbPixelFormat.BayerBG16: _query_compatibility(VmbPixelFormat.BayerBG16),
|
||||
|
||||
VmbPixelFormat.Rgb8: _query_compatibility(VmbPixelFormat.Rgb8),
|
||||
VmbPixelFormat.Bgr8: _query_compatibility(VmbPixelFormat.Bgr8),
|
||||
VmbPixelFormat.Rgb10: _query_compatibility(VmbPixelFormat.Rgb10),
|
||||
VmbPixelFormat.Bgr10: _query_compatibility(VmbPixelFormat.Bgr10),
|
||||
VmbPixelFormat.Rgb12: _query_compatibility(VmbPixelFormat.Rgb12),
|
||||
VmbPixelFormat.Bgr12: _query_compatibility(VmbPixelFormat.Bgr12),
|
||||
VmbPixelFormat.Rgb14: _query_compatibility(VmbPixelFormat.Rgb14),
|
||||
VmbPixelFormat.Bgr14: _query_compatibility(VmbPixelFormat.Bgr14),
|
||||
VmbPixelFormat.Rgb16: _query_compatibility(VmbPixelFormat.Rgb16),
|
||||
VmbPixelFormat.Bgr16: _query_compatibility(VmbPixelFormat.Bgr16),
|
||||
VmbPixelFormat.Argb8: _query_compatibility(VmbPixelFormat.Argb8),
|
||||
VmbPixelFormat.Rgba8: _query_compatibility(VmbPixelFormat.Rgba8),
|
||||
VmbPixelFormat.Bgra8: _query_compatibility(VmbPixelFormat.Bgra8),
|
||||
VmbPixelFormat.Rgba10: _query_compatibility(VmbPixelFormat.Rgba10),
|
||||
VmbPixelFormat.Bgra10: _query_compatibility(VmbPixelFormat.Bgra10),
|
||||
VmbPixelFormat.Rgba12: _query_compatibility(VmbPixelFormat.Rgba12),
|
||||
VmbPixelFormat.Bgra12: _query_compatibility(VmbPixelFormat.Bgra12),
|
||||
VmbPixelFormat.Rgba14: _query_compatibility(VmbPixelFormat.Rgba14),
|
||||
VmbPixelFormat.Bgra14: _query_compatibility(VmbPixelFormat.Bgra14),
|
||||
VmbPixelFormat.Rgba16: _query_compatibility(VmbPixelFormat.Rgba16),
|
||||
VmbPixelFormat.Bgra16: _query_compatibility(VmbPixelFormat.Bgra16),
|
||||
|
||||
VmbPixelFormat.Yuv411: _query_compatibility(VmbPixelFormat.Yuv411),
|
||||
VmbPixelFormat.Yuv422: _query_compatibility(VmbPixelFormat.Yuv422),
|
||||
VmbPixelFormat.Yuv444: _query_compatibility(VmbPixelFormat.Yuv444),
|
||||
VmbPixelFormat.YCbCr411_8_CbYYCrYY: _query_compatibility(VmbPixelFormat.YCbCr411_8_CbYYCrYY),
|
||||
VmbPixelFormat.YCbCr422_8_CbYCrY: _query_compatibility(VmbPixelFormat.YCbCr422_8_CbYCrY),
|
||||
VmbPixelFormat.YCbCr8_CbYCr: _query_compatibility(VmbPixelFormat.YCbCr8_CbYCr)
|
||||
}
|
||||
Reference in New Issue
Block a user