hbp_nrp_cle.tf_framework.tf_lib module

Contains a library of transfer functions

class Camera[source]

Bases: object

Utility class for converting between measures in the Field of View

static angle2metric(a, e)[source]

Converts an (azimuth, elevation) pair to a metric distance from the image’s center.

Parameters
  • a – the azimuth angle from the image’s center (deg)

  • e – the elevation angle from the image’s center (deg)

Returns

a pair (xm, ym) denoting the metric distance from the center of the image (pure number)

angle2pixel(a, e)[source]

Converts an (azimuth, elevation) pair to a pixel coordinate on the image.

Parameters
  • a – the azimuth angle from the image’s center (deg)

  • e – the elevation angle from the image’s center (deg)

Returns

a pair (u, v) denoting a pixel’s coordinates (px)

property cal_cx

Gets the image center’s x coordinate computed during calibration (px)

property cal_cy

Gets the image center’s y coordinate computed during calibration (px)

property cal_fx

Gets the image’s x focal length computed during calibration (px)

property cal_fy

Gets the image’s y focal length computed during calibration (px)

property cal_height

Gets the image’s height computed during calibration (px)

property cal_width

Gets the image’s width computed during calibration (px)

property cx

Gets the image center’s x coordinate (px)

property cy

Gets the image center’s y coordinate (px)

property fx

Gets the image’s x focal length (px)

property fy

Gets the image’s y focal length (px)

property height

Gets the image’s height (px)

static metric2angle(xm, ym)[source]

Converts a metric distance from the image’s center to an (azimuth, elevation) pair.

Parameters
  • xm – the x distance from the center (pure number)

  • ym – the y distance from the center (pure number)

Returns

a pair (a, e) denoting the azimuth and the elevation, the center being (0, 0) (deg)

metric2pixel(xm, ym)[source]

Converts a metric distance from the image center to a pixel coordinate.

Parameters
  • xm – the x distance from the center (pure number)

  • ym – the y distance from the center (pure number)

Returns

a pair (u, v) denoting a pixel’s coordinates (px)

norm2angle(x, y)[source]
Converts a normalized distance from the image’s center to the corresponding

(azimuth, elevation) pair.

Parameters
  • x – the x coordinate of the distance from the center (pure number in range [-1, 1])

  • y – the y coordinate of the distance from the center (pure number in range [-1, 1])

Returns

a pair (a, e) denoting the azimuth and the elevation, the center being (0, 0) (deg)

norm2metric(x, y)[source]

Converts a normalized distance from the image’s center to a metric distance from its center

Parameters
  • x – the x coordinate of the distance from the center (pure number in range [-1, 1])

  • y – the y coordinate of the distance from the center (pure number in range [-1, 1])

Returns

a pair (xm, ym) denoting the metric distance from the center of the image (pure number)

norm2pixel(x, y)[source]

Converts a normalized distance from the image’s center to the corresponding pixel.

Parameters
  • x – the x coordinate of the distance from the center (pure number in range [-1, 1])

  • y – the y coordinate of the distance from the center (pure number in range [-1, 1])

Returns

a pair (u, v) denoting a pixel’s coordinates (px)

pixel2angle(u, v)[source]

Converts a pixel coordinate on the image to an (azimuth, elevation) pair.

Parameters
  • u – the x coordinate (column) of the pixel (px)

  • v – the y coordinate (row) of the pixel (px)

Returns

a pair (a, e) denoting the azimuth and the elevation, the center being (0, 0) (deg)

pixel2metric(u, v)[source]

Converts a pixel coordinate on the image to a metric distance from its center.

Parameters
  • u – the x coordinate (column) of the pixel (px)

  • v – the y coordinate (row) of the pixel (px)

Returns

a pair (xm, ym) denoting the metric distance from the center of the image (pure number)

pixel2norm(u, v)[source]

Converts a pixel coordinate on the image to a normalized distance from its center.

Parameters
  • u – the x coordinate (column) of the pixel (px)

  • v – the y coordinate (row) of the pixel (px)

Returns

a pair (x, y) denoting the distance from the center of the image (pure number in range [-1, 1] x [-1, 1])

set_image_size(w, h)[source]

Sets the image size

Parameters
  • w – image’s new width

  • h – image’s new height

property width

Gets the image’s width (px)

detect_red(image)[source]

Performs a very simple image detection as used in the Braitenberg demo.

Parameters

image – The image

Returns

An object with three properties: - left: This is the percentage of red pixels in the left half of the image - right: This is the percentage of red pixels in the right half of the image - go_on: This is the percentage of non-red pixels of the overall image

Example

A completely red image (255,0,0) results in (1,1,0)

Example

A completely yellow image (255,255,0) results in (0,0,1)

The lightest color that is recognized as red is (255,127,127).

find_centroid_hsv(image, lower, upper)[source]

Finds the centroid of the pixels in an image lying in a given HSV slice.

Parameters
  • image – A Gazebo ROS image (sensor_msgs.msg.Image)

  • lower – The lower value of the HSV slice we want to detect (a 3 elements int list with values in range 0-255, refer to cv2 documentation for more details).

  • upper – The upper value of the HSV slice we want to detect (a 3 elements int list with values in range 0-255, refer to cv2 documentation for more details).

Returns

a pair (x, y) denoting the image pixel where the centroid lies, or None if anything goes wrong.

getValueFromFloat64MultiArray(message, row, column, channel=0)[source]

Gets the value at position (row, column, channel) from a std_msgs/Float64MultiArray message containing a bidimensional image.

Parameters
  • message – The message containing the data

  • row – Row coordinate

  • column – Column coordinate

  • channel – Channel coordinate. Defaults to zero, it can be omitted.

Returns

The value at the specified coordinates.

get_color_values(image, width=40, height=30)[source]

Gets the color values of an image for use in the Braitenberg demo. An incoming image is resized and then analyzed per pixel. All the red, green and blue values of all pixels are returned as a result

Parameters

image – The image

Returns

An object with the color channels of the image separated in two image halves, each

The lightest color that is recognized as red is (255,127,127).