Anubis - Bachelor thesis project

Public Member Functions | Public Attributes | Private Member Functions | Private Attributes | List of all members
camera.Camera Class Reference

This class implements backend for the communication with cameras using Harvester and any other implemented API. More...

Collaboration diagram for camera.Camera:

## Public Member Functions
def | __init__ (self, producer_paths=None)
| Initialize Camera object. More...
def | get_camera_list (self)
| Connected camera discovery. More...
def | select_camera (self, selected_device)
| choose camera to connect to More...
def | get_parameters (self, feature_queue, flag, visibility=Config_level.Unknown)
| Read parameters from camera. More...
def | read_param_value (self, param_name)
| Used to get value of one parameter based on its name. More...
def | set_parameter (self, parameter_name, new_value)
| Method for setting camera's parameters. More...
def | execute_command (self, command_feature)
def | get_single_frame (self)
| Grab single frame from camera. More...
def | start_acquisition (self)
| Starts continuous acquisition of image frames. More...
def | stop_acquisition (self)
| Stops continuous acquisition. More...
def | start_recording (self, folder_path, name_scheme, configuration)
| Starts continuous acquisition of image frames and saves them to files/video. More...
def | stop_recording (self)
| Stops continuous acquisition of image frames and closes all files. More...
def | load_config (self, path)
| Load existing camera configuration. More...
def | save_config (self, path)
| Saves configuration of a camera to .xml file. More...
def | add_gentl_producer (self, producer_path)
| Add a new frame producer to the harvester object. More...
def | remove_gentl_producer (self, producer_path)
| Remove existing frame producer from the harvester object. More...
def | get_gentl_producers (self)
| Used to get a list of all path used by Harvesters in a present moment. More...
def | disconnect_harvester (self)
| Destroys harvester object so other APIs can access cameras. More...
def | disconnect_camera (self)
| Disconnect camera and restores the object to its initial state. More...

## Public Attributes
| h
| Harvester object used to communicate with Harvester module. More...
| paths
| paths to GenTL producers More...
| vendor
| Camera vendor used to select the correct API. More...
| is_recording
| Recording state. More...
| acquisition_running
| Image acquisition state. More...
| devices_info
| Detected devices. More...
| active_camera
| Index of active camera for active API. More...
| ia
| Image acquifier object used by Harvester. More...

## Private Member Functions
def | _translate_selected_device (self, selected_device)
| attrs camera ID to index in a list of detected cameras More...
def | _frame_producer (self)
| Gets frames from camera while continuous acquisition is active. More...
def | _frame_consumer (self, folder_path, name_scheme, additional_config)
| Gradually saves frames generated by _frame_producer_thread. More...
def | _frame_handler_vimba (self, cam, frame)
| Defines how to process incoming frames. More...

## Private Attributes
| _stream_stop_switch
| _frame_producer_thread
| _frame_consumer_thread

## Detailed Description

This class implements backend for the communication with cameras using Harvester and any other implemented API.

Currently the app contains Harvester and API Vimba.

Definition at line 32 of file camera.py.

## Constructor & Destructor Documentation

## ◆ __init__()

def camera.Camera.__init__ | ( |  | self,
|  |  | producer_paths = `None`
| ) |  |

Initialize Camera object.

Definition at line 37 of file camera.py.

## Member Function Documentation

## ◆ _frame_consumer()

def camera.Camera._frame_consumer | ( |  | self,
|  |  | folder_path,
|  |  | name_scheme,
|  |  | additional_config
| ) |  |
| private

Gradually saves frames generated by _frame_producer_thread.

Uses openCV to saves images from frame_queue to file_path according to additional_config

Parameters

  [in] | folder_path | Path where the files will be saved
  [in] | name_scheme | Defines how to name output files
  [in] | additional_config | Reserved.

Definition at line 676 of file camera.py.

## ◆ _frame_handler_vimba()

def camera.Camera._frame_handler_vimba | ( |  | self,
|  |  | cam,
|  |  | frame
| ) |  |
| private

Defines how to process incoming frames.

Is defined for Vimba and defines how to acquire whole frame and put into the frame_queue

Definition at line 709 of file camera.py.

## ◆ _frame_producer()

def camera.Camera._frame_producer | ( |  | self | ) |
| private

Gets frames from camera while continuous acquisition is active.

Loads frames from camera as they come and stores them in a frame queue for consumer thread to process. The thread runs until stream_stop_switch is set

Definition at line 641 of file camera.py.

## ◆ _translate_selected_device()

def camera.Camera._translate_selected_device | ( |  | self,
|  |  | selected_device
| ) |  |
| private

attrs camera ID to index in a list of detected cameras

Index is returned according to currently active camera vendor. This method must be called in every method where new connection to a camera is made.

Parameters

  [in] | selected_device | ID of a camera you want to connect to

Definition at line 125 of file camera.py.

## ◆ add_gentl_producer()

def camera.Camera.add_gentl_producer | ( |  | self,
|  |  | producer_path
| ) |  |

Add a new frame producer to the harvester object.

Adds .cti file specified by producer_path to the harvester object

Parameters

  [in] | producer_path | Path to a .cti file

Returns
  list of all active producers

Definition at line 597 of file camera.py.

## ◆ disconnect_camera()

def camera.Camera.disconnect_camera | ( |  | self | ) |

Disconnect camera and restores the object to its initial state.

Definition at line 634 of file camera.py.

## ◆ disconnect_harvester()

def camera.Camera.disconnect_harvester | ( |  | self | ) |

Destroys harvester object so other APIs can access cameras.

Definition at line 629 of file camera.py.

## ◆ execute_command()

def camera.Camera.execute_command | ( |  | self,
|  |  | command_feature
| ) |  |

    @brief Execute command feature type
    @param[in] command_feature Name of the selected command feature

Definition at line 428 of file camera.py.

## ◆ get_camera_list()

def camera.Camera.get_camera_list | ( |  | self | ) |

Connected camera discovery.

Uses Harvester object to discover all connected cameras

Returns
  List of Dictionaries cantaining informations about cameras

Definition at line 60 of file camera.py.

## ◆ get_gentl_producers()

def camera.Camera.get_gentl_producers | ( |  | self | ) |

Used to get a list of all path used by Harvesters in a present moment.

Returns
  List of defined cti file paths

Definition at line 622 of file camera.py.

## ◆ get_parameters()

def camera.Camera.get_parameters | ( |  | self,
|  |  | feature_queue,
|  |  | flag,
|  |  | visibility = `Config_level.Unknown`
| ) |  |

Read parameters from camera.

Based on self.vendor and self.active_camera chooses right API and loads all available camera parameters

Parameters

  [in] | feature_queue | each parameter's dictionary is put into this queue
  [in] | flag | used to signal that the method finished (threading object)
  [in] | visibility | Defines level of parameters that should be put in the queue

Returns
  True if success else False

Definition at line 142 of file camera.py.

## ◆ get_single_frame()

def camera.Camera.get_single_frame | ( |  | self | ) |

Grab single frame from camera.

Based on vendor variable chooses right API for acquisition and loads single frame from active_camera

Returns
  Unmodified frame from camera

Definition at line 449 of file camera.py.

## ◆ load_config()

def camera.Camera.load_config | ( |  | self,
|  |  | path
| ) |  |

Load existing camera configuration.

Parameters

  [in] | path | Defines a path and a name of the file containing the configuration of the camera

Returns
  True if success else False

Definition at line 518 of file camera.py.

## ◆ read_param_value()

def camera.Camera.read_param_value | ( |  | self,
|  |  | param_name
| ) |  |

Used to get value of one parameter based on its name.

Parameters

  [in] | param_name | Name of the parametr whose value we want to read

Returns
  A value of the selected parameter

Definition at line 383 of file camera.py.

## ◆ remove_gentl_producer()

def camera.Camera.remove_gentl_producer | ( |  | self,
|  |  | producer_path
| ) |  |

Remove existing frame producer from the harvester object.

Removes .cti file specified by producer_path from the harvester object

Parameters

  [in] | producer_path | Path to a .cti file

Definition at line 610 of file camera.py.

## ◆ save_config()

def camera.Camera.save_config | ( |  | self,
|  |  | path
| ) |  |

Saves configuration of a camera to .xml file.

Parameters

  [in] | path | A path where the file will be saved

Definition at line 570 of file camera.py.

## ◆ select_camera()

def camera.Camera.select_camera | ( |  | self,
|  |  | selected_device
| ) |  |

choose camera to connect to

Select camera you will be using and set Camera object accordingly

Parameters

  [in] | selected_device | ID of a camera you want to connect to

Definition at line 83 of file camera.py.

## ◆ set_parameter()

def camera.Camera.set_parameter | ( |  | self,
|  |  | parameter_name,
|  |  | new_value
| ) |  |

Method for setting camera's parameters.

Sets parameter to value defined by new_value

Parameters

  [in] | parameter_name | A name of the parameter to be changed
  [in] | new_value | Variable compatible with value key in parameter

Returns
  True if success else returns False

Definition at line 404 of file camera.py.

## ◆ start_acquisition()

def camera.Camera.start_acquisition | ( |  | self | ) |

Starts continuous acquisition of image frames.

Creates a threading object for the right API and starts frame acquisition in that thread (producer thread)

Definition at line 477 of file camera.py.

## ◆ start_recording()

def camera.Camera.start_recording | ( |  | self,
|  |  | folder_path,
|  |  | name_scheme,
|  |  | configuration
| ) |  |

Starts continuous acquisition of image frames and saves them to files/video.

Calls start_acquisition method and configures camera parameters for optimal acquisition

Parameters

  [in] | folder_path | Path where the files will be saved
  [in] | name_scheme | Naming template for saved files
  [in] | configuration | Parameters of output files and possibly camera parameters

Definition at line 500 of file camera.py.

## ◆ stop_acquisition()

def camera.Camera.stop_acquisition | ( |  | self | ) |

Stops continuous acquisition.

Sets stream_stop_switch, acquisition running to false and removes inner link to queue object

Definition at line 489 of file camera.py.

## ◆ stop_recording()

def camera.Camera.stop_recording | ( |  | self | ) |

Stops continuous acquisition of image frames and closes all files.

Definition at line 512 of file camera.py.

## Member Data Documentation

## ◆ _frame_consumer_thread

camera.Camera._frame_consumer_thread
| private

Definition at line 508 of file camera.py.

## ◆ _frame_producer_thread

camera.Camera._frame_producer_thread
| private

Definition at line 485 of file camera.py.

## ◆ _stream_stop_switch

camera.Camera._stream_stop_switch
| private

Definition at line 484 of file camera.py.

## ◆ acquisition_running

camera.Camera.acquisition_running

Image acquisition state.

Definition at line 52 of file camera.py.

## ◆ active_camera

camera.Camera.active_camera

Index of active camera for active API.

Definition at line 56 of file camera.py.

## ◆ devices_info

camera.Camera.devices_info

Detected devices.

Definition at line 54 of file camera.py.

## ◆ h

camera.Camera.h

Harvester object used to communicate with Harvester module.

Definition at line 40 of file camera.py.

## ◆ ia

camera.Camera.ia

Image acquifier object used by Harvester.

Definition at line 58 of file camera.py.

## ◆ is_recording

camera.Camera.is_recording

Recording state.

Definition at line 50 of file camera.py.

## ◆ paths

camera.Camera.paths

paths to GenTL producers

Definition at line 42 of file camera.py.

## ◆ vendor

camera.Camera.vendor

Camera vendor used to select the correct API.

Definition at line 48 of file camera.py.

The documentation for this class was generated from the following file:

- camera.py