Python Interface Development User Manual
Python Interface Development User Manual
Version: V1.0.3
Date: 2019-05-07
All rights reserved. No parts of this manual may be used or reproduced, in any forms or by any means,
without prior written permission of China Daheng Group, Inc. Beijing Image Vision Technology Branch.
The right is also reserved to modify or change any parts of this manual in the future without prior notification.
© 2019 China Daheng Group, Inc. Beijing Image Vision Technology Branch
Web: http://www.daheng-imaging.com
Sales Email: [email protected]
Sales Tel: +86 10 8282 8878
Support Email: [email protected]
Contents
1. Camera Workflow ............................................................................................................1
1.1. Overall workflow ...................................................................................................... 1
1.2. Function control flow ............................................................................................... 2
1.3. Overall code sample ................................................................................................ 3
2. Programming Guide ........................................................................................................4
2.1. Build programming environment.............................................................................. 4
2.1.1. Linux .................................................................................................................................... 4
2.1.2. Windows .............................................................................................................................. 5
2.2. QuickStart................................................................................................................ 5
2.2.1. Importing library ................................................................................................................... 5
2.2.2. Enumeration device ............................................................................................................. 6
2.2.3. Open or close the device ..................................................................................................... 7
2.2.4. Acquisition control................................................................................................................ 9
2.2.5. Image processing ................................................................................................................ 9
2.2.6. Camera control .................................................................................................................. 11
2.2.7. Import and export camera configuration parameter .......................................................... 15
2.2.8. Error handling .................................................................................................................... 15
3. Appendix ........................................................................................................................17
3.1. Feature parameter................................................................................................. 17
3.1.1. Device feature parameter .................................................................................................. 17
3.1.2. Stream feature parameter ................................................................................................. 27
3.2. Function class definition ........................................................................................ 28
3.2.1. Feature .............................................................................................................................. 28
3.2.2. IntFeature .......................................................................................................................... 30
3.2.3. FloatFeature ...................................................................................................................... 31
3.2.4. EnumFeature ..................................................................................................................... 33
3.2.5. BoolFeature ....................................................................................................................... 35
3.2.6. StringFeature ..................................................................................................................... 37
3.2.7. BufferFeature ..................................................................................................................... 39
3.2.8. CommandFeature.............................................................................................................. 41
3.3. Data type definition ................................................................................................ 42
3.3.1. GxDeviceClassList ............................................................................................................ 42
3.3.2. GxAccessStatus ................................................................................................................ 42
3.3.3. GxAccessMode ................................................................................................................. 42
3.3.4. GxPixelFormatEntry .......................................................................................................... 42
3.3.5. GxFrameStatusList ............................................................................................................ 43
3.3.6. GxPixelSizeEntry ............................................................................................................... 43
3.3.7. GxPixelColorFilterEntry ..................................................................................................... 44
3.3.8. GxAcquisitionModeEntry ................................................................................................... 44
3.3.9. GxTriggerSourceEntry ....................................................................................................... 44
3.3.10. GxTriggerActivationEntry................................................................................................. 44
3.3.11. GxExposureModeEntry.................................................................................................... 44
3.3.12. GxUserOutputSelectorEntry ............................................................................................ 45
© China Daheng Group, Inc. Beijing Image Vision Technology Branch III
1. Camera Workflow
1. Camera Workflow
# Open device
# Get the list of basic device information
strSN = dev_info_list[0].get("sn")
# Open the device by serial number
cam = device_manager.open_device_by_sn(strSN)
# Start acquisition
cam.stream_on()
# Get data
# num is the number of images acquired
num = 1
for i in range(num):
# Get an image from the 0 th stream channel
raw_image = cam.data_stream[0].get_image()
# Get RGB images from color raw images
rgb_image = raw_image.convert("RGB")
if rgb_image is None:
continue
# Create numpy array from RGB image data
numpy_image = rgb_image.get_numpy_array()
if numpy_image is None:
continue
# Display and save the acquired RGB image
image = Image.fromarray(numpy_image, 'RGB')
image.show()
image.save("image.jpg")
# Stop acquisition, close device
cam.stream_off()
cam.close_device()
2. Programming Guide
2.1.1. Linux
2) Create a new project, select the Python interpreter that has a gxipy library. If there is no option,
select Settings on the right to add the corresponding version of the Python interpreter.
2.1.2. Windows
Take the Python2.7 and pycharm2018 platforms as examples to demonstrate the installation of the gxipy
library in the Windows 7 64-bit operating system environment. When installing the gxipy library for the first
time:
2) Select New environment, select Inherit global site-packages and Make available to all projects,
and select OK. At this point, the user will see that the gxipy library has been successfully loaded into the
current project environment in the newly created interpreter.
2.2. QuickStart
When using any classes, methods, and data types of the library in your code, the libraries should be
imported at the beginning of the program in order to use the installed libraries.
Sample code:
import gxipy as gx
device_manager = gx.DeviceManager()
The user enumerates all currently available devices by calling DeviceManager.update_device_list(). The
return values of the function are the number of devices dev_num and the device information list
dev_info_list. The number of elements in the device information list is the number of devices enumerated,
the data type of the elements in the list is a dictionary, and the keys of the dictionary are as follows:
Note: MER-GEV: Mercury (Gen 1) GigE Vision camera, MER-U3V: Mercury (Gen 1) USB3.0 camera,
MER-U2: Mercury (Gen 1) USB2.0 camera, MER2-GEV: Mercury2 (Gen 2) GigE Vision camera.
MER- MER- MER MER2
Key name Significance Type
GEV U3V -U2 -GEV
ip address(GEV camera
ip string √ √
only)
Gateway(GEV camera
gateway string √ √
only)
nic_mac address(GEV
nic_mac string √ √
camera only)
nic_ip address(GEV
nic_ip string √ √
camera only)
sk camera only)
Note:
In addition to the enumeration interfaces above, DeviceManager provides another enumeration interface
DeviceManager.update_all_device_list():
1) For non-GigE Vision cameras, the two enumeration interfaces are functionally identical.
2) For GigE Vision cameras, the enumeration mechanisms used inside the library are different:
update_all_device_list:Using entire network enumeration, you can enumerate all GigE Vision cameras
on the LAN.
update_device_list:Using subnet enumeration, you can only enumerate GigE Vision cameras that are
on the same network segment within the LAN.
The user can open the device by the following five different methods:
DeviceManager.open_device_by_sn(self, sn, access_mode=GxAccessMode.CONTROL)
DeviceManager.open_device_by_user_id(self,user_id,access_mode=GxAccessMode.CONTROL)
DeviceManager.open_device_by_index(self,index,access_mode=GxAccessMode.CONTROL)
DeviceManager.open_device_by_ip(ip, access_mode=GxAccessMode.CONTROL)
DeviceManager.open_device_by_mac(mac, access_mode=GxAccessMode.CONTROL)
Parameters:
mac The device mac address (non-GigE Vision cameras are not support)
Note:
The last two functions are only for GigE Vision cameras.
The user can call the Device. close_device() interface provided by Device to close the device and release
all device’s resources.
Sample code:
import gxipy as gx
# Enumerate devices. dev_info_list is a list of device information.
#The number of elements in the list is the number of devices
#enumerated. The list elements are dictionaries, which contain
#device information such as device index and ip information
device_manager = gx.DeviceManager()
dev_num, dev_info_list = device_manager.update_device_list()
if dev_num == 0:
sys.exit(1)
# Open device
# Method 1
# Get the list of basic device information
str_sn = dev_info_list[0].get("sn")
# Open the device by serial number
cam = device_manager.open_device_by_sn(str_sn)
# Method 2
# Open the device by user ID
# str_user_id = dev_info_list[0].get("user_id")
# cam = device_manager.open_device_by_user_id(str_user_id)
# Method 3
# Open the device by index
# str_index = dev_info_list[0].get("index")
# cam = device_manager.open_device_by_index(str_index)
# Method 4
# Open the device by ip address
# str_ip= dev_info_list[0].get("ip")
# cam = device_manager.open_device_by_ip(str_ip)
# Method 5
# Open the device by mac address
# str_mac = dev_info_list[0].get("mac")
# cam = device_manager.open_device_by_mac(str_mac)
# Close device
cam.close_device()
After the device is opened successfully and the camera acquisition parameters are set, the user can call
Device.stream_on() and Device.stream_off() to start and stop acquiring:
The interface and parameters related to the acquisition are provided by DataStream, and you can control
the number of images acquired by setting the number of loops. You can get the number of stream channels
of the device through the Device.get_stream_channel_num() interface. The acquired image uses
RawImage.get_status() to determine whether it is an incomplete frame. The returned data structure codes
are as follows:
# Start acquisition
cam.stream_on()
# Get data
# num is the number of images acquired
num = 1
for i in range(num):
# Open the data stream of channel 0
raw_image = cam.data_stream[0].get_image()
if raw_image.get_status() == gx.GxFrameStatusList.INCOMPLETE:
print("incomplete frame")
# Stop acquisition
cam.stream_off()
The image format conversion object is the raw_image got by acquiring the image with
DataStream.get_image().
Functional description:
Convert Bayer format images to RGB format images. See the RawImage.convert() interface of RawImage
for details.
Sample code:
1) Color camera
raw_image = cam.data_stream[0].get_image()
# Save raw images
raw_image.save_raw("raw_image.raw")
# Get RGB images from color raw images
rgb_image = raw_image.convert("RGB")
if rgb_image is None:
continue
# Create numpy array from RGB image data
numpy_image = rgb_image.get_numpy_array()
if numpy_image is None:
continue
# Then, the user can display and save the image according to the
#got numpy_array
2) Monochrome camera
raw_image = cam.data_stream[0].get_image()
# Get numpy array from mono raw images
numpy_image = raw_image.get_numpy()
if numpy_image is None:
continue
# Then, the user can display and save the image according to the
#got numpy_array
◆ Image quality improvement
The interface library also provides an image quality improvement interface on the software side, and the
user can selectively perform color correction, contrast, Gamma and other image quality improvement
operations. The user can call the RGBImage.image_improvement() interface of RGBImage to implement
the function. A simple example is as follows:
# Set image quality improvement parameters
if cam.GammaParam.is_readable():
gamma_value = cam.GammaParam.get()
gamma_lut = gx.Utility.get_gamma_lut(gamma_value)
else:
gamma_lut = None
if cam.ContrastParam.is_readable():
contrast_value = cam.ContrastParam.get()
contrast_lut = gx.Utility.get_contrast_lut(contrast_value)
else:
contrast_lut = None
color_correction_param = cam.ColorCorrectionParam.get()
# Acquire images, and convert the format
# .......
# Implement image quality improvement
rgb_image.image_improvement(color_correction_param, contrast_lut,
gamma_lut)
1) Color correction:
Explanation: Improve the color reproduction of the camera to make the image closer to the visual
perception of the human eye.
2) Contrast adjustment:
Explanation: The brightness ratio between the bright part and the dark part of the image is called contrast.
For images with high contrast, the contour of the subject is clearer and the image is clearer. Conversely,
the image with low contrast has unclear contour and unclear image.
3) Gamma adjustment:
Call the Image.fromarray () interface of PIL (Python Imaging Library), convert the numpy array to an
Image, display and save it. The codes are as follows:
1) Monochrome camera
# Display and save the got mono image
image = Image.fromarray(numpy_image, 'L')
image.show()
image.save("acquisition_mono_image.jpg")
2) Color camera
# Display and save the got color image
image = Image.fromarray(numpy_image, 'RGB')
image.show()
image.save("acquisition_RGB_image.jpg")
Here are three types of access to feature parameter: whether it is implemented, readable, or writable. The
interfaces are designed as follows:
Feature.is_implement Is this current feature controller support this feature
It is recommended that the user query the access type of the feature before operating the feature
parameter.
Sample code:
# Whether the acquisition function is implemented
is_implemented = cam.PixelFormat.is_implemented()
if is_implemented == True:
# Is this writable
is_writable = cam.PixelFormat.is_writable()
if is_writable == True:
# Set pixel format
cam.PixelFormat.set(gx.GxPixelFormatEntry.MONO8)
# Is this readable
is_readable = cam.PixelFormat.is_readable()
if is_readable == True:
# Print pixel format
print(cam.PixelFormat.get())
◆ Feature control
Feature control is divided into two categories: Device feature parameter and Stream feature parameter.
The difference is that the control functions of the feature parameters are different:
Device feature parameter: device information, such as width, height, exposure, gain, etc.
Stream feature parameter: feature access controllers for acquisition control and the acquisition of data
statistics.
After acquiring the camera instantiation object, you can access the control interfaces of the feature
parameter by accessing the feature parameter, which are in the Camera control.
For example:
Int:
Related interfaces:
IntFeature.set(int_value) // Set
IntFeature.get() // Get
Sample code:
# Get the settable range of the image width
int_range = cam.Width.get_range()
# Set the current image width to any value in the range
cam.Width.set(800)
# Get the width of current image
int_Width_value = cam.Width.get()
Float:
Related interfaces:
FloatFeature.set(float_value) // Set
FloatFeature.get() // Get
Sample code:
# Get the settable range and maximum value of the exposure time
float_range = cam.ExposureTime.get_range()
float_max = float_range["max"]
# Set the current exposure time to any value in the range
cam.ExposureTime.set(10.0)
# Get the current exposure time
float_exposure_value = cam.ExposureTime.get()
Enum:
Related interfaces:
EnumFeature.set(enum_value) // Set
EnumFeature.get() // Get
Sample code:
# Get the settable range of enum value
enum_range = cam.PixelFormat.get_range()
# Set the current enum value
cam.PixelFormat.set(gx.GxPixelFormatEntry.MONO8)
# print the current enum value
enum_PixelForamt_value,enum_PixelFormat_key = cam.PixelFormat.get()
Bool:
Related interfaces:
BoolFeature.set(bool_value) // Set
BoolFeature.get() // Get
Sample code:
# Set the current bool value
cam.LineInverter.set(True)
# Get bool value
bool_LineInverter_value = cam.LineInverter.get()
String:
Related interfaces:
StringFeature.set(string_value) // Set
StringFeature.get() // Get
Sample code:
# Get the maximum length of the string feature can be set
string_max_length = cam.DeviceUserID.get_string_max_length()
# Get the current value of string
current_string = cam.DeviceUserID.get()
# Set string value
cam.DeviceUserID.set("MyUserID")
Buffer:
Related interfaces:
BufferFeature.set_buffer(buf) // Set
BufferFeature.get_buffer() // Get
Sample code:
import gxipy as gx
# Get the length of buffer data
buffer_length = cam. UserData.get_buffer_length()
# Set the buffer data
cam.UserData.set_buffer(gx.Buffer.from_string(b'BufferFeature
Test!'))
# Get the buffer data
buffer_data = cam.LUTValueAll.get_buffer()
print("UserData: %s" % (buffer_data.get_data().decode())
Command:
Related interface:
CommandFeature.send_command // Send command
Sample code:
All the camera's feature parameters can be got in the Feature parameter of appendix.
In the interface library, there is an interface for importing and exporting device configuration files for the
user to call.
Sample code:
# Import camera configuration parameter file
cam.import_config_file("import_config_file.txt")
# Export camera configuration parameter file
cam.export_config_file("export_config_file.txt")
When an exception occurs inside the calling interface function, the error handling mechanism detects and
throws different types of exception, and the exception types inherit from Exception.
The user can also perform classification processing by testing the specific type of error captured:
if isinstance(exception, OutOfRange):
print("OutOfRange: %s" % exception)
elif isinstance(exception, OffLine):
print("OffLine: %s" % exception)
else:
print("Other Error Type %s" % exception)
Exception type:
Exception type Significance
UnexpectedError Unexpected
OffLine Offline
Timeout Timeout
3. Appendix
CommandFea
DeviceReset Device reset √
ture
CommandFea
TimestampLatch Timestamp latch √
ture
CommandFea
TimestampReset Timestamp reset √
ture
CommandFea
TimestampLatchReset Timestamp latch reset √
ture
for details
GevCurrentIPConfiguration
Configuring IP in LLA mode BoolFeature √ √
LLA
User-defined output
selector, see C Software
UserOutputSelector Development Manual and EnumFeature √ √ √ √
GxUserOutputSelectorEntry
for details
for details
Minimum automatic
AutoExposureTimeMin FloatFeature √ √ √ √
exposure
Maximum automatic
AutoExposureTimeMax FloatFeature √ √ √ √
exposure
The X coordinate of
AWBROIOffsetX automatic white balance IntFeature √ √ √ √
ROI
The Y coordinate of
AWBROIOffsetY automatic white balance IntFeature √ √ √ √
ROI
CommandFea
UserSetLoad Load the user set √ √ √ √
ture
CommandFea
UserSetSave Save the user set √ √ √ √
ture
CommandFea
AcquisitionStart Start acquisition √ √ √ √
ture
CommandFea
AcquisitionStop Stop acquisition √ √ √ √
ture
CommandFea
TriggerSoftware Software trigger √ √ √ √
ture
CommandFea
TransferStart Start transfer √ √ √ √
ture
GxExposureModeEntry for
details
Announced buffer
StreamAnnouncedBufferCount IntFeature √ √ √ √
count
Delivered frame
StreamDeliveredFrameCount count (including IntFeature √ √ √ √
incomplete frames)
Delivered incomplete
StreamIncompleteFrameCount IntFeature √ √ √ √
frame count
Delivered packet
StreamDeliveredPacketCount IntFeature √ √ √ √
count
Rescued packet
StreamRescuedPacketCount IntFeature √ √
count
Resend command
StreamResendCommandCount IntFeature √ √
count
Unexpected packet
StreamUnexpectedPacketCount IntFeature √ √
count
Maximum resend
MaxPacketCountInOneBlock packet count in one IntFeature √ √
block
Maximum packet
MaxPacketCountInOneCommand count in one resend IntFeature √ √
command
Maximum waiting
MaxWaitPacketCount IntFeature √ √
packet count
Missing BlockID
StreamMissingBlockIDCount IntFeature √ √
count
Maximum number of
MaxNumQueueBuffer Buffer in the IntFeature √ √
acquisition queue
3.2.1. Feature
It is responsible for checking the basic functions of various data type functions and testing if they are
implemented, readable and writable.
Interface list:
is_implemented() Test if the feature is implemented
◆ Interface description
➢ is_implemented
Statement:
Feature.is_implemented()
Significance:
Return value:
Ture: Implement
False: Unimplement
Exception handling:
2) If it fails due to other reasons, an exception is thrown. For details, see Error handling.
➢ is_readable
Statement:
Feature.is_readable()
Significance:
Return value:
Ture: Readable
False: Unreadable
Exception handling:
2) If it fails due to other reasons, an exception is thrown. For details, see Error handling.
➢ is_writable
Statement:
Feature.is_writable()
Significance:
Return value:
Ture: Writable
False: Unwritable
Exception handling:
2) If it fails due to other reasons, an exception is thrown. For details, see Error handling.
3.2.2. IntFeature
It is responsible for checking and controlling the camera's int feature, inherited from the Feature class.
Interface list:
is_implemented() Test if the int feature is implemented
◆ Interface description
➢ is_implemented
➢ is_readable
➢ is_writable
➢ get_range
Statement:
IntFeature.get_range()
Significance:
Return value:
Record the dictionary of int feature ranges. The key contains: minimum, maximum and step size.
Exception handling:
1) If the int feature is not implemented, then prints the information that does not support the int feature
to get range, and the function returns None.
2) If getting the parameter range of the int feature unsuccessfully, an exception is thrown. For details,
see Error handling.
➢ get
Statement:
IntFeature.get()
Significance:
Return value:
Exception handling:
1) If the int feature is not implemented or is unreadable, then prints the unreadable information of the int
feature, and the function returns None.
2) If getting the int feature value unsuccessfully, an exception is thrown. For details, see Error handling.
➢ set
Statement:
IntFeature.set(self,int_value)
Significance:
Formal parameter:
Exception handling:
2) If the int feature is not implemented or is not writable, then prints the information that the int feature is
not writable, and the function returns None.
3) If the input parameter is not within the range of the int feature, then prints the information that exceeds
the range of the int feature and prints the range, and the function returns None.
4) If setting the int feature unsuccessfully, an exception is thrown. For details, see Error handling.
3.2.3. FloatFeature
It is responsible for checking and controlling the camera's float feature, inherited from the Feature class.
Interface list:
◆ Interface description
➢ is_implemented
➢ is_readable
➢ is_writable
➢ get_range
Statement:
FloatFeature.get_range()
Significance:
Return value:
Record the dictionary of float feature ranges. The keys contain: minimum, maximum, inc step size, unit,
whether the inc_is_valid unit is valid.
Exception handling:
1) If the float feature is not implemented, then prints the information that does not support the float feature
to get range, and the function returns None.
2) If getting the parameter range of the float feature unsuccessfully, an exception is thrown. For details,
see Error handling.
➢ get
Statement:
FloatFeature.get()
Significance:
Return value:
Exception handling:
1) If the float feature is not implemented or is unreadable, then prints the unreadable information of the
float feature, and the function returns None.
2) If getting the float feature value unsuccessfully, an exception is thrown. For details, see Error handling.
➢ set
Statement:
FloatFeature.set(float_value)
Significance:
Formal parameter:
Exception handling:
2) If the float feature is not implemented or is not writable, then prints the information that the float feature
is not writable, and the function returns None.
3) If the input parameter is not within the range of the float feature, then prints the information that
exceeds the range of the float feature and prints the range, and the function returns None.
4) If setting the float feature unsuccessfully, an exception is thrown. For details, see Error handling.
3.2.4. EnumFeature
It is responsible for checking and controlling the camera's enum feature, inherited from the Feature
class.
Interface list:
◆ Interface description
➢ is_implemented
➢ is_readable
➢ is_writable
➢ get_range
Statement:
EnumFeature.get_range()
Significance:
Return value:
Exception handling:
1) If the enum feature is not implemented, then prints the information that does not support the enum
feature to get range, and the function returns None.
2) If getting the range of the enum feature unsuccessfully, an exception is thrown. For details, see Error
handling.
➢ get
Statement:
EnumFeature.get()
Significance:
Return value:
Exception handling:
1) If the enum feature is not implemented or is unreadable, then prints the unreadable information of the
enmu feature, and the function returns None.
2) If getting enmu feature unsuccessfully, an exception is thrown. For details, see Error handling.
➢ set
Statement:
EnumFeature.set( enum_value)
Significance:
Formal parameter:
Exception handling:
2) If the enmu feature is not implemented or is not writable, then prints the information that the enmu
feature is not writable, and the function returns None.
3) If the input parameter is not within the range of the enmu feature, then prints the information that
exceeds the range of the enmu feature and prints the range, and the function returns None.
4) If setting the enmu feature unsuccessfully, an exception is thrown. For details, see Error handling.
3.2.5. BoolFeature
It is responsible for checking and controlling the camera's bool feature, inherited from the Feature class.
Interface list:
is_implemented() Test if the bool feature is implemented
◆ Interface description
➢ is_implemented
➢ is_readable
➢ is_writable
➢ get
Statement:
BoolFeature.get()
Significance:
Return value:
Exception handling:
1) If the bool feature is not implemented or is unreadable, then prints the unreadable information of the
bool feature, and the function returns None.
2) If getting bool feature value unsuccessfully, an exception is thrown. For details, see Error handling.
➢ set
Statement:
BoolFeature.set( bool_value)
Significance:
Formal parameter:
Exception handling:
2) If the bool feature is not implemented or is not writable, then prints the information that the bool feature
is not writable, and the function returns None.
3) If setting the bool feature unsuccessfully, an exception is thrown. For details, see Error handling.
3.2.6. StringFeature
It is responsible for checking and controlling the camera's string feature, inherited from the Feature class.
Interface list:
is_implemented() Test if the string feature is implemented
get_string_max_length() Get the maximum length that a string feature value can be set
◆ Interface description
➢ is_implemented
➢ is_readable
➢ is_writable
➢ get_string_max_length
Statement:
StringFeature.get_string_max_length()
Significance:
Return value:
Exception handling:
1) If the string feature is not implemented, then prints the information that is not implemented, and the
function returns None.
2) If getting the maximum length of the string feature unsuccessfully, an exception is thrown. For details,
see Error handling.
➢ get
Statement:
StringFeature.get()
Significance:
Return value:
Exception handling:
1) If the string feature is not implemented or is unreadable, then prints the unreadable information of the
string feature, and the function returns None.
2) If getting the string feature value unsuccessfully, an exception is thrown. For details, see Error handling.
➢ set
Statement:
StringFeature.set( input_string)
Significance:
Formal parameter:
Exception handling:
2) If the string feature is not implemented or is not writable, then prints the information that the string
feature is not writable, and the function returns None.
3) If the input parameter length is greater than the settable maximum length, then prints the information
that exceeds the maximum value of the string type feature length and prints the maximum value, and the
function returns None.
4) If setting the string feature unsuccessfully, an exception is thrown. For details, see Error handling.
3.2.7. BufferFeature
It is responsible for checking and controlling the camera's buffer feature, inherited from the Feature
class.
Interface list:
is_implemented() Test if the buffer feature is implemented
◆ Interface description
➢ is_implemented
➢ is_readable
➢ is_writable
➢ get_buffer_length
Statement:
BufferFeature.get_buffer_length()
Significance:
Return value:
Exception handling:
1) If the buffer feature is not implemented, then prints the information that does not support the buffer
feature to get range, and the function returns None.
2) If getting the range of the buffer feature unsuccessfully, an exception is thrown. For details, see Error
handling.
➢ get_buffer
Statement:
BufferFeature.get_buffer()
Significance:
Return value:
Buffer object
Exception handling:
1) If the buffer feature is not implemented or is unreadable, then prints the unreadable information of the
buffer feature, and the function returns None.
2) If getting the buffer feature value unsuccessfully, an exception is thrown. For details, see Error
handling.
➢ set_buffer
Statement:
BufferFeature.set_buffer(buf)
Significance:
Formal parameter:
Exception handling:
2) If the buffer feature is not implemented or is not writable, then prints the information that the buffer
feature is not writable, and the function returns None.
3) If the input buffer feature data length is greater than the maximum length, then prints the information
that exceeding the maximum length of the buffer feature and prints the maximum value, and the function
returns None.
4) If setting the buffer feature unsuccessfully, an exception is thrown. For details, see Error handling.
3.2.8. CommandFeature
It is responsible for the command type function of the camera, inherited from the Feature class.
Interface list:
is_implemented() Test if the command feature is implemented
◆ Interface description
➢ is_implemented
➢ is_readable
➢ is_writable
➢ send_command
Statement:
CommandFeature.send_command()
Significance:
Send command
Exception handling:
1) If the command feature is not implemented, then prints the information that does not support the
command feature, and the function returns None.
2) If sending the command feature unsuccessfully, an exception is thrown. For details, see Error handling.
3.3.1. GxDeviceClassList
Definition Value Explanation
3.3.2. GxAccessStatus
Definition Value Explanation
3.3.3. GxAccessMode
Definition Value Explanation
3.3.4. GxPixelFormatEntry
Definition Value Value Explanation
3.3.5. GxFrameStatusList
Definition Value Explanation
3.3.6. GxPixelSizeEntry
Definition Value Explanation
3.3.7. GxPixelColorFilterEntry
Definition Value Explanation
NONE 0 None
BAYER_RG 1 RG format
BAYER_GB 2 GB format
BAYER_GR 3 GR format
BAYER_BG 4 BG format
3.3.8. GxAcquisitionModeEntry
Definition Value Explanation
3.3.9. GxTriggerSourceEntry
Definition Value Explanation
3.3.10. GxTriggerActivationEntry
Definition Value Explanation
3.3.11. GxExposureModeEntry
Definition Value Explanation
3.3.12. GxUserOutputSelectorEntry
Definition Value Explanation
OUTPUT0 1 Output 0
OUTPUT1 2 Output 1
OUTPUT2 4 Output 2
3.3.13. GxUserOutputModeEntry
Definition Value Explanation
STROBE 0 Strobe
3.3.14. GxGainSelectorEntry
Definition Value Explanation
3.3.15. GxBlackLevelSelectEntry
Definition Value Explanation
3.3.16. GxBalanceRatioSelectorEntry
Definition Value Explanation
3.3.17. GxAALightEnvironmentEntry
Definition Value Explanation
3.3.18. GxUserSetEntry
Definition Value Explanation
3.3.19. GxAWBLampHouseEntry
Definition Value Explanation
3.3.20. GxTestPatternEntry
Definition Value Explanation
OFF 0 Off
3.3.21. GxTriggerSelectorEntry
Definition Value Explanation
3.3.22. GxLineSelectorEntry
Definition Value Explanation
LINE0 0 Pin 0
LINE1 1 Pin 1
LINE2 2 Pin 2
LINE3 3 Pin 3
3.3.23.GxLineModeEntry
Definition Value Explanation
INPUT 0 Input
OUTPUT 1 Output
3.3.24. GxLineSourceEntry
Definition Value Explanation
OFF 0 Off
STROBE 1 Strobe
3.3.25. GxLutSelectorEntry
Definition Value Explanation
LUMINANCE 0 Luminance
3.3.26. GxTransferControlModeEntry
Definition Value Explanation
3.3.27. GxTransferOperationModeEntry
Definition Value Explanation
3.3.28. GxTestPatternGeneratorSelectorEntry
Definition Value Explanation
3.3.29. GxChunkSelectorEntry
Definition Value Explanation
FRAME_ID 1 Frame ID
TIME_STAMP 2 Timestamp
3.3.30. GxBinningHorizontalModeEntry
Definition Value Explanation
3.3.31. GxBinningVerticalModeEntry
Definition Value Explanation
3.3.32. GxAcquisitionStatusSelectorEntry
Definition Value Explanation
3.3.33. GxGammaModeEntry
Definition Value Explanation
3.3.34. GxColorTransformationModeEntry
Definition Value Explanation
3.3.35. GxColorTransformationValueSelectorEntry
Definition Value Explanation
3.3.36. GxAutoEntry
Definition Value Explanation
OFF 0 Off
CONTINUOUS 1 Continuous
ONCE 2 Once
3.3.37. GxSwitchEntry
Definition Value Explanation
OFF 0 Off
ON 1 On
3.3.38. GxRegionSendModeEntry
Definition Value Explanation
3.3.39. GxRegionSelectorEntry
Definition Value Explanation
REGION0 0 Region 0
REGION1 1 Region 1
REGION2 2 Region 2
REGION3 3 Region 3
REGION4 4 Region 4
REGION5 5 Region 5
REGION6 6 Region 6
REGION7 7 Region 7
3.3.40. GxTimerSelectorEntry
Definition Value Explanation
TIMER1 1 Timer 1
3.3.41. GxTimerTriggerSourceEntry
Definition Value Explanation
3.3.42. GxCounterSelectorEntry
Definition Value Explanation
COUNTER1 1 Counter 1
3.3.43. GxCounterEventSourceEntry
Definition Value Explanation
3.3.44. GxCounterResetSourceEntry
Definition Value Explanation
LINE0 2 Pin 0
LINE1 3 Pin 1
LINE2 4 Pin 2
LINE3 5 Pin 3
3.3.45. GxCounterResetActivationEntry
Definition Value Explanation
3.3.46. DxBayerConvertType
Definition Value Explanation
3.3.47. DxValidBit
Definition Value Explanation
3.3.48. DxImageMirrorMode
Definition Value Explanation
3.4.1. DeviceManager
It is responsible for the management of the camera, including enumerating device, opening device, getting
the number of devices, etc.
Interface list:
update_device_list ( timeout=200) Enumerate devices on the same network segment
open_device_by_sn (sn,
Open the device by serial number
access_mode=GxAccessMode.CONTROL)
open_device_by_user_id
(user_id,access_mode=GxAccessMode.CONT Open the device by user ID
ROL)
open_device_by_index (index,
Open the device by device index
access_mode=GxAccessMode.CONTROL)
open_device_by_ip (ip,
Open the device by IP address
access_mode=GxAccessMode.CONTROL)
open_device_by_mac (mac,
Open the device by mac address
access_mode=GxAccessMode.CONTROL)
◆ Interface description
➢ update_device_list
Statement:
DeviceManager.update_device_list (timeout=200)
Significance:
For non-GigE Vision cameras, enumerate all devices. For GigE Vision cameras, enumerate devices on
the same network segment
Formal parameter:
Return value:
The return value is the number of the devices which are enumerated and the list that records the
enumeration information. The number of elements in the device information list is the number of devices
enumerated. The data type of the elements in the list is a dictionary, and the key names in the dictionary
are detailed in the Enumeration device.
Exception handling:
2) If the input parameter is less than 0 or greater than the maximum value of the unsigned int, then prints
DeviceManager.update_device_list: Out of bounds, timeout:minimum=0, maximum= 0xffffffff, and
the function returns None.
3) If the enumeration of device on the same segment fails, an exception is thrown. For details, see Error
handling.
4) If getting basic information of all devices unsuccessfully, an exception is thrown. For details, see Error
handling.
➢ update_all_device_list
Statement:
DeviceManager.update_all_device_list (timeout=200)
Significance:
For non-GigE Vision cameras, enumerate all devices, for GigE Vision cameras, enumerate network-wide
devices
Formal parameter:
Return value:
The return value is the number of the devices which is enumerated and the list that records the
enumeration information. The number of elements in the device information list is the number of devices
enumerated, the data type of the elements in the list is a dictionary, and the key names in the dictionary
are detailed in the Enumeration device.
Exception handling:
2) If the input parameter is less than 0 or greater than the maximum value of the unsigned int, then prints
DeviceManager.update_all_device_list: Out of bounds, timeout:minimum=0, maximum= 0xffffffff,
and the function returns None.
3) If the enumeration of device on the different segment fails, an exception is thrown. For details, see
Error handling.
4) If getting basic information of all devices unsuccessfully, an exception is thrown. For details, see Error
handling.
➢ get_device_number
Statement:
DeviceManager.get_device_number ()
Significance:
Return value:
➢ get_device_info
Statement:
DeviceManager.get_device_info()
Significance:
Return value:
A list of device information. The number of elements in the device information list is the number of devices
enumerated, the data type of the elements in the list is a dictionary, and the keys of the dictionary are
detailed in the Enumeration device.
➢ open_device_by_sn
Statement:
DeviceManager.open_device_by_sn( sn,access_mode=GxAccessMode.CONTR
OL)
Significance:
Formal parameter:
[in]sn Serial number [string type]
[in]access_mode Open device mode, the default is
GxAccessMode.CONTROL, check GxAccessMode
Return value:
Device object
Exception handling:
3) If input parameter 2 is not in device mode GxAccessMode, then prints interface name, open device
mode is not in the range and the enumeration value information supported by the current parameter, and
the function returns None.
5) If opening the device unsuccessfully, an exception is thrown. For details, see Error handling.
6) If the got device is not one of the U3V/USB2/GEV classes, a NotFoundDevice exception is thrown.
➢ open_device_by_user_id
Statement:
DeviceManager.open_device_by_user_id(user_id,access_mode=GxAccessM
ode.CONTROL)
Significance:
Formal parameter:
Return value:
Device object
Exception handling:
3) If the input parameter 2 is not in the open device mode GxAccessMode, then prints interface name,
open device mode is not in the range and the enumeration value information supported by the current
parameter, and the function returns None.
5) If opening the device unsuccessfully, an exception is thrown. For details, see Error handling.
6) If the got device is not one of the U3V/USB2/GEV classes, a NotFoundDevice exception is thrown.
➢ open_device_by_index
Statement:
DeviceManager.open_device_by_index(index,access_mode=GxAccessMode.
CONTROL)
Significance:
Formal parameter:
Return value:
Device object
Exception handling:
2) If the input parameter 1 is less than 0 or greater than the maximum value of the unsigned int, then
prints DeviceManager.open_device_by_index: index out of bounds, index: minimum=1, maximum=
0xffffffff, and the function returns None.
3) If the input parameter 2 is not in device mode GxAccessMode, then prints interface name, open device
mode is not in the range and information about the enumeration values supported by the current parameter,
the function returns None.
4) If the number of devices is less than the index of the input parameter 1, a NotFoundDevice exception
is thrown.
5) If opening the device unsuccessfully, an exception is thrown. For details, see Error handling.
6) If the got device is not one of the U3V/USB2/GEV classes, a NotFoundDevice exception is thrown.
➢ open_device_by_ip
Statement:
DeviceManager.open_device_by_ip(ip,access_mode=GxAccessMode.CONTRO
L)
Significance:
Formal parameter:
Return value:
Device object
Exception handling:
3) If the input parameter 2 is not in device mode GxAccessMode, then prints interface name, open device
mode is not in the range and information of the enumeration values supported by the current parameter,
the function returns None.
4) If opening the device unsuccessfully, an exception is thrown. For details, see Error handling.
➢ open_device_by_mac
Statement:
DeviceManager.open_device_by_mac(mac,access_mode=GxAccessMode.CONT
ROL)
Significance:
Formal parameter:
Return value:
Device object
Exception handling:
3) If the input parameter 2 is not in device mode GxAccessMode, then prints interface name, open device
mode is not in the range and the enumeration value information supported by the current parameter, the
function returns None.
4) If opening the device unsuccessfully, an exception is thrown. For details, see Error handling.
3.4.2. Device
It is responsible for camera acquisition control, device close, configuration file import and export, and get
the device handles, etc.
Interface list:
◆ Interface description
➢ get_stream_channel_num
Statement:
Device.get_stream_channel_num()
Significance:
Return value:
Note: Currently, GigE Vision cameras, USB3.0, and USB2.0 cameras do not support multi-stream
channels.
➢ stream_on
Statement:
Device.stream_on()
Significance:
Return value:
None
Exception handling:
1) If sending start command unsuccessfully, an exception is thrown. For details, see Error handling.
➢ stream_off
Statement:
Device.stream_off()
Significance:
Return value:
None
Exception handling:
1) If sending stop command unsuccessfully, an exception is thrown. For details, see Error handling.
➢ export_config_file
Statement:
Device.export_config_file( file_path)
Significance:
Formal parameter:
Return value:
None
Exception handling:
2) If exporting the current configuration file unsuccessfully, an exception is thrown. For details, see Error
handling.
➢ import_config_file
Statement:
Device.import_config_file(file_path, verify=False)
Significance:
Formal parameter:
Return value:
None
Exception handling:
3) If importing configuration file unsuccessfully, an exception is thrown. For details, see Error handling.
➢ close_device
Statement:
Device.close_device()
Significance:
Close the device, destroy the device handle, and set the handle to none
Return value:
None
Exception handling:
1) If closing the device unsuccessfully, an exception is thrown. For details, see Error handling.
Note:
if you still want to use this camera after you close the device, please reopen it.
3.4.3. DataStream
It is responsible for camera data stream setting, control, image acquisition, etc.
Interface list:
set_acquisition_buffer_number(buf_num) Set the size of the acquisition buffer
◆ Interface description
➢ set_acquisition_buffer_number
Statement:
DataStream.set_acquisition_buffer_number(buf_num)
Significance:
Formal parameter:
Return value:
None
Exception handling:
2) If the input parameter is less than 1 or greater than the maximum value of the unsigned int, then
prints DataStream.set_acquisition_buffer_number: buf_num out of bounds, minimum=1,
maximum=0xffffffff, and the function returns None.
3) If setting the size of the acquisition buffer unsuccessfully, an exception is thrown. For details, see Error
handling.
➢ get_image
Statement:
DataStream.get_image(timeout=1000)
Significance:
Get the image and successfully create the image class object
Formal parameter:
Return value:
None: Timeout
Exception handling:
2) If the input parameter is less than 0 or greater than 0xffffffff, then prints DataStream.get_image:
timeout out of bounds, minimum=0, maximum=0xffffffff, and the function returns None.
3) If getting the data size unsuccessfully, an exception is thrown, and the type of the exception is
described in Error handling.
4) If getting the image unsuccessfully caused by timeout, the function returns None.
5) If not timed out but failed to get the image, then prints status, DataStream, get_image, and the
function returns None.
➢ flush_queue
Statement:
DataStream.flush_queue()
Significance:
Exception handling:
1) If clearing the camera acquisition buffer queue unsuccessfully, an exception is thrown. For details,
see Error handling.
3.4.4. RGBImage
Interface list:
image_improvement( color_correction_param=0,
Improve image quality
contrast_lut=None, gamma_lut=None)
◆ Interface description
➢ image_improvement
Statement:
RGBImage.image_improvement(color_correction_param=0,contrast_lut=N
one, gamma_lut=None)
Significance:
Formal parameter:
Exception handling:
1) If parameter 1 and 2 is not a buffer type or None, throw the exception ParameterTypeError.
4) If parameters 1, 2, and 3 are default values, the image quality improvement processing is not
performed and the function exits.
➢ saturation
Statement:
RGBImage.saturation(factor)
Significance:
Formal parameter:
Return value:
None
Exception handling:
➢ sharpen
Statement:
RGBImage.sharpen()
Significance:
Formal parameter:
Return value:
None
Exception handling:
➢ get_numpy_array
Statement:
RGBImage.get_numpy_array()
Significance:
Return value:
Numpy object
➢ get_image_size
Statement:
RGBImage.get_image_size()
Significance:
Return value:
3.4.5. RawImage
Interface list:
convert(mode, flip=False,
valid_bits=DxValidBit.BIT4_11, Image format conversion
convert_type=DxBayerConvertType.NEIGHBOUR)
◆ Interface description
➢ convert
Statement:
Significance:
1) When mode = 'RAW8', convert the 16-bit raw image to an 8-bit raw image. The valid bit of the
interception defaults is the upper 8 bits of the current pixel format. The user can also manually set the valid
bit with the parameter valid_bits. Only 10/12-bit raw images are supported.
2) When mode = 'RGB', convert the raw image to RGB image. If the input is a 10/12-bit raw image, it is
first converted to an 8-bit raw image and then converted to an RGB image.
Formal parameter:
Return value:
Exception handling:
1) If the status of frame information is unsuccessful, then prints the error message RawImage. convert:
This is an incomplete image, and the function returns None.
5) If parameter 4 is not in DxBayerConvertType, then prints the prompt parameter is out of bounds, the
enumeration value supported by the current parameter, and the function returns None.
6) If parameter 4 is not in DxValidBit, then prints the prompt parameter is out of bounds, the enumeration
value supported by the current parameter, and the function returns None.
7) If the pixel is not 8/10/12bit, the error message RawImage.convert: This pixel format is not support
is printed, and the function returns None.
9) Mode = 'RAW8', the bit depth is not 10/12bit, the error message RawImage.convert: mode=RAW8
only support 10bit and 12bit is printed, and the function returns None.
10) If parameter 1 is not 'RAW8' or 'RGB', then prints interface name and the input mode are not in the
range, and the function returns None.
➢ defective_pixel_correct
Statement:
RawImage.defective_pixel_correct()
Significance:
Return value:
None
Exception handling:
➢ get_numpy_array
Statement:
RawImage.get_numpy_array()
Significance:
Return value:
None Unsuccessful
Exception handling:
2) If the pixel format is not 8 or 16 bits, and the function returns None.
➢ get_data
Statement:
RawImage.get_data()
Significance:
Return value:
➢ save_raw
Statement:
RawImage.save_raw( file_path)
Significance:
Formal parameter:
Return value:
None
Exception handling:
2) If saving the raw image data unsuccessfully, throw the exception UnexpectedError.
➢ get_status
Statement:
RawImage.get_status()
Significance:
Return value:
➢ get_width
Statement:
RawImage.get_width()
Significance:
Return value:
➢ get_height
Statement:
RawImage.get_height()
Significance:
Return value:
➢ get_pixel_format
Statement:
RawImage.get_pixel_format()
Significance:
Return value:
➢ get_image_size
Statement:
RawImage.get_image_size()
Significance:
Return value:
➢ get_frame_id
Statement:
RawImage.get_frame_id()
Significance:
Get frame ID
Return value:
Frame ID
➢ get_timestamp
Statement:
RawImage.get_timestamp()
Significance:
Get timestamp
Return value:
Timestamp
3.4.6. Buffer
It is responsible for the operation of the buffer class. The buffer class will be used in the image quality
improvement section. The buffer type object returned by the Utility.get_gamma_lut(gamma) and
Utility.get_contrast_lut(contrast) interfaces will be passed as an parameter to
RGBImage.image_improvement(color_correction_param=0, contrast_lut=None, gamma_lut=None)
interface.
Interface list:
from_file(file_name) Get buffer object from a file
get_length() Return the length of the data array of the buffer object
◆ Interface description
Statement:
Buffer.from_file(file_name)
Significance:
Formal parameter:
Return value:
Buffer object
Statement:
Buffer.from_string(string_data)
Significance:
Formal parameter:
[in]string_data String
Return value:
Buffer object
➢ get_data
Statement:
Buffer.get_data()
Significance:
Return value:
➢ get_ctype_array
Statement:
Buffer.get_ctype_array()
Significance:
Return value:
➢ get_numpy_array
Statement:
Buffer.get_numpy_array()
Significance:
Return value:
➢ get_length
Statement:
Buffer.get_length()
Significance:
Return value:
3.4.7. Utility
Interface list:
get_gamma_lut(gamma=1) Get gamma LUT by gamma value
◆ Interface description
Statement:
Significance:
Formal parameter:
Return value:
Gamma LUT
Exception handling:
2) If the input parameter is not in the range of 0.1 to 10.0, the error message
Utility.get_gamma_lut:gamma out of bounds, range:[0.1, 10.0] is printed, and the function returns
None.
3) If getting the gamma LUT unsuccessfully, the interface name, the gamma lut fail to get, and the error
code are printed. The function returns None.
Statement:
Utility.get_contrast_lut(contrast=0)(Static function)
Significance:
Formal parameter:
Return value:
Contrast LUT
Exception handling:
2) If the input parameter is not in the range of -50 to 100, the error message
Utility.get_contrast_lut:contrast out of bounds, range:[-50, 100] is printed, and the function returns
None.
3) If getting contrast LUT unsuccessfully, the interface name, the gamma lut fail to get, and the error
code are printed, and the function returns None.
4. FAQ
No. General Question Answer
5. Revision History
No. Version Changes Date
2 V1.0.1 Add the new function description for the Mercury2 cameras 2018-10-29