Module: camera

Executive Summary

The goal of the camera module is to simulate a camera in the Basilisk codebase. Although images are provided by the visualization, they are renders of the Unity engine and are not necessarily representative of a camera. The module reads in an image from a file, or in the simulation as a pointer to image data, then corrupts it according to input parameters.

Module Assumptions and Limitations

The practical limitation of this module is that it decodes and re-encodes the images that are corrupted. Outside of this design choice, the limitations are limited to the corruption methods used to replicate real camera physics. A Gaussian Dark Current might not always be a good model to represent such a phenomenon.

Message Connection Descriptions

The following table lists all the module input and output messages. The module msg variable name is set by the user from python. The msg type contains a link to the message structure definition, while the description provides information on what this message is used for

Module I/O Messages

Msg Variable Name

Msg Type

Description

imageInMsgName

cameraImageMsg

Input image message This image is theoretically uncorrupted though this module can also add additional errors.

cameraOutMsgName

cameraConfigMsg

Camera parameters message.

imageOutMsgName

cameraImageMsg

Output image with corruptions.

Detailed Module Description

This modules pulls heavily from the OpenCV library. The methods implemented create either:

  • Gaussian noise on the image

  • Dark Noise

  • Dead and stuck pixels

  • Random Cosmic rays

  • Bluring

Doxygen documentation for OpenCV can be found here.

User Guide

The test and these few lines show an example setup for the module.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
moduleConfig.imageInMsgName = "sample_image"
moduleConfig.cameraOutMsgName = "cameraOut"
moduleConfig.imageOutMsgName = "out_image"
moduleConfig.filename = ""
moduleConfig.saveImages = 0
# If images are to be saved, add the directory to which they
should be saved
#moduleConfig.saveDir = '/'.join(imagePath.split('/')[:-1]) + '/'

#Camera config values
moduleConfig.cameraIsOn = 1
moduleConfig.sigma_CB = [0,0,1]

#Noise Values
moduleConfig.gaussian = 2
moduleConfig.darkCurrent = 1
moduleConfig.saltPepper = 2
moduleConfig.cosmicRays = 1
moduleConfig.blurParam = 3

These values are written such that 0 provides no corruption of that type and 10 provides very high levels of errors (not bounding though)


class Camera : public SysModel

Public Functions

Camera()

The constructor for the Camera module. It also sets some default values at its creation.

~Camera()

This is the destructor

void UpdateState(uint64_t CurrentSimNanos)

This module reads an OpNav image and extracts circle information from its content using OpenCV’s HoughCircle Transform. It performs a greyscale, a bur, and a threshold on the image to facilitate circle-finding.

Return

void

Parameters
  • CurrentSimNanos: The clock time at which the function was called (nanoseconds)

void SelfInit()

Selfinit performs the first stage of initialization for this module. It’s primary function is to create messages that will be written to.

Return

void

void CrossInit()

CrossInit performs the second stage of initialization for this module. It’s primary function is to link the input messages that were created elsewhere.

Return

void

void Reset(uint64_t CurrentSimNanos)

This method performs a complete reset of the module. Local module variables that retain time varying states between function calls are reset to their default values.

Return

void

Parameters
  • this: The configuration data associated with the module

void AddGaussianNoise(const cv::Mat, cv::Mat &mDst, double, double)

Adds gaussian noise to an image. Can be used to add color noise and dark current.

Return

void

Parameters
  • cv::Mat: source image

  • cv::Mat: destination of modified image

  • double: mean pixel value

  • double: standard deviation of pixel value

void AddSaltPepper(const cv::Mat, cv::Mat &mDst, float, float)

Adds dead and hot pixels to an image.

Return

void

Parameters
  • cv::Mat: source image

  • cv::Mat: destination of modified image

  • float: probability of dead pixels

  • float: probability of hot pixels

void AddCosmicRay(const cv::Mat, cv::Mat &mDst, float, double, int)

Adds a cosmic ray to an image. The ray is modelled as a single pixel wide white line.

Return

void

Parameters
  • cv::Mat: source image

  • cv::Mat: destination of modified image

  • float: probability of getting a ray each frame

  • double: if adding multiple rays pass in the number of each to guarantee a random ray

  • int: max length of cosmic ray

void AddCosmicRayBurst(const cv::Mat, cv::Mat &mDst, double)

Adds a user specified number of cosmic rays to an image. Rays are modelled as a single pixel wide white line. The maximum length is hard-coded as 50 pixels.

Return

void

Parameters
  • cv::Mat: source image

  • cv::Mat: destination of modified image

  • double: number of cosmic rays to be added

void ApplyFilters(cv::Mat, cv::Mat &mDst, double gaussian, double darkCurrent, double saltPepper, double cosmicRays, double blurparam)

Applys all of the various pertubations to an image with user specified levels. Each parameter is a double scaling actor. A parameter of 0 will result in the respective perturbation not being applied.

Return

void

Parameters
  • cv::Mat: source image

  • cv::Mat: destination of modified image

  • double: scaling factor for gaussian noise

  • double: scaling factor for dark current

  • double: scaling factor for hot and dead pixels

  • double: number of cosmic rays to add

  • double: size of blur to apply

Public Members

std::string filename

Filename for module to read an image directly.

std::string imageInMsgName

The name of the ImageFswMsg input message.

std::string imageOutMsgName

The name of the CameraImageMsg output message.

std::string cameraOutMsgName

The name of the CameraConfigMsg output message.

std::string saveDir

The name of the directory to save images.

uint64_t sensorTimeTag

[ns] Current time tag for sensor out

int32_t saveImages

[-] 1 to save images to file for debugging

char parentName[MAX_MESSAGE_SIZE]

[-] Name of the parent body to which the camera should be attached

Camera parameters

int cameraIsOn

[-] Is the camera currently taking images

int cameraID

[-] Is the camera currently taking images

double fieldOfView

[rad] Camera Field of View

int resolution[2]

[-] Camera resolution, width/height in pixels (pixelWidth/pixelHeight in Unity) in pixels

uint64_t renderRate

[ns] Frame time interval at which to capture images in units of nanosecond

double focalLength

[m] Camera Focal Length in meters

double sensorSize[2]

[m] Size of the camera sensor-paired with resolution gives you pixel size in mm

double cameraPos_B[3]

[m] Camera position in body frame

double sigma_CB[3]

[-] MRP defining the orientation of the camera frame relative to the body frame

char skyBox[MAX_MESSAGE_SIZE]

[-] name of skyboz in use

double gaussian

Gaussian noise level.

Noise paramters

double darkCurrent

Dark current intensity.

double saltPepper

Stuck and Dark pixels probability.

double cosmicRays

Random cosmic rays (number)

double blurParam

Blur over image in pixels.

BSKLogger bskLogger

BSK Logging

Private Members

uint64_t OutputBufferCount

[-] Count on the number of output message buffers

int32_t imageInMsgID

ID for the outgoing message.

int32_t imageOutMsgID

ID for the outgoing message.

int32_t cameraOutID

ID for the outgoing message.

uint64_t CurrentSimNanos
void *pointImageOut

void pointer for image memory passing