annotations.FaceSights package

Submodules

annotations.FaceSights.imgfacemark module

annotations.FaceSights.sights module

filename

sppas.src.annotations.FaceSights.sights.py

author

Brigitte Bigi

contact

develop@sppas.org

summary

Data structure to store the 68 sights of a face.

class annotations.FaceSights.sights.Sights(nb=68)[source]

Bases: object

Data structure to store sights.

This class is storing nb sights; each sight is made of 3 values:
  • x: coordinate on the x axis, initialized to 0

  • y: coordinate on the y axis, initialized to 0

  • an optional confidence score, initialized to None

Notice that each of the sight parameter is stored into a list of ‘nb’ values, instead of storing a single list of ‘nb’ lists of values:

  • 2 lists of ‘nb’ int and 1 of float = [x1,x2,…] [y1,y2,…] [s1,s2,…]

    3*64 + 2*68*24 + 1*68*24 = 5088

  • 1 list of ‘nb’ lists of 2 int and 1 float: [[x1,y1,s1], [x2,y2,s2]…]

    64 + 68*64 + 2*68*24 + 1*68*24 = 9312

__init__(nb=68)[source]

Create a new instance.

Parameters

nb – (int) Number of expected sights.

check_index(value)[source]

Raise an exception if the given index is not valid.

Parameters

value – (int)

Raise

sppasTypeError, NegativeValueError, IndexRangeException

copy()[source]

Return a deep copy of the current Sights().

get_s()[source]

Return the list of confidence score values or None.

get_score(idx=None)[source]

Return the score of the sight at the given index or None.

Parameters

idx – (int) Index of the sight or None to get the average score

Returns

(int or None)

get_sight(idx)[source]

Return the (x, y, s) of the given sight.

Parameters

idx – (int) Index of the sight

Returns

tuple(x, y, confidence)

get_x()[source]

Return the list of x values.

get_y()[source]

Return the list of y values.

intermediate(other)[source]

Return the sights with the intermediate positions.

Parameters

other – (Sights)

Returns

(Sights)

set_score(idx, s)[source]

Set a score to the sight at the given index.

Parameters
  • idx – (int) Index of the sight

  • s – (float or None) An optional confidence score

set_sight(idx, x, y, s=None)[source]

Set the sight at the given index.

Parameters
  • idx – (int) Index of the sight

  • x – (int) pixel position on the x axis (width)

  • y – (int) pixel position on the y axis (height)

  • s – (float or None) An optional confidence score

class annotations.FaceSights.sights.sppasImageSightsReader(csv_file)[source]

Bases: object

Read&create sights from a CSV file.

Currently unused: To be tested.

__init__(csv_file)[source]

Set the list of sights defined in the given file.

Parameters

csv_file – sights from a sppasSightsImageWriter

class annotations.FaceSights.sights.sppasSightsImageWriter[source]

Bases: sppas.src.imgdata.sppasCoordsImageWriter

Write an image and optionally sights into files.

__init__()[source]

Create a new sppasSightsImageWriter instance.

Write the given image in the given filename. Parts of the image can be extracted in separate image files. Output images can be resized. Sights can be drawn in any of such output images.

tag_coords(img, coords, pen_width, colors=[])[source]

Override to tag image for the given coords OR sights.

Parameters
  • img – (sppasImage) The image to write

  • coords – (list of Sights) The sights of objects

  • colors – List of (r,g,b) Tuple with RGB int values

Returns

(sppasImage)

static write_coords(fd, coords, sep=';')[source]

Write sights in the given stream.

Parameters
  • fd – (Stream) File descriptor, String descriptor, stdout, etc

  • coords – (Sights) Sights to write in other columns.

  • sep – (char) CSV separator

annotations.FaceSights.sppasfacesights module

annotations.FaceSights.videofacemark module

annotations.FaceSights.videosights module

filename

sppas.src.annotations.FaceSights.videosights.py

author

Brigitte Bigi

contact

develop@sppas.org

summary

Data structure to manage the 68 sights on faces of a video.

class annotations.FaceSights.videosights.sppasSightsVideoBuffer(video=None, size=- 1)[source]

Bases: sppas.src.videodata.sppasCoordsVideoBuffer

A video buffer with lists of coordinates, identifiers and sights.

__init__(video=None, size=- 1)[source]

Create a new instance.

Parameters
  • video – (str) The video filename

  • size – (int) Number of images of the buffer or -1 for auto

append_coordinate(buffer_index, coord)[source]

Override. Append the coordinates to a given image index.

Parameters
  • buffer_index – (int) Index of the image in the buffer

  • coord – (sppasCoords) Append the given coord

Returns

(int) Index of the new coordinate

get_id(buffer_index, face_index)[source]

Return the identifier of a face of a given image.

Parameters
  • buffer_index – (int) Index of the image in the buffer

  • face_index – (int) Index of the face

Returns

(Sights)

get_id_coordinate(buffer_index, identifier)[source]

Return the coordinate of a given identifier in a given image.

Parameters
  • buffer_index – (int) Index of the image in the buffer

  • identifier – (int) Identifier to search

Returns

(sppasCoords) Coordinates or None

get_id_sight(buffer_index, identifier)[source]

Return the sights of a given identifier in a given image.

Parameters
  • buffer_index – (int) Index of the image in the buffer

  • identifier – (int) Identifier to search

Returns

(sppasCoords) Coordinates or None

get_ids(buffer_index=None)[source]

Return the identifiers of all faces of a given image.

Parameters

buffer_index – (int) Index of the image in the buffer

Returns

(list of identifiers)

get_sight(buffer_index, face_index)[source]

Return the sights of a face of a given image.

Parameters
  • buffer_index – (int) Index of the image in the buffer

  • face_index – (int) Index of the face

Returns

(Sights)

get_sights(buffer_index=None)[source]

Return the sights of all faces of a given image.

Parameters

buffer_index – (int) Index of the image in the buffer

Returns

(list of Sights)

next()[source]

Override. Fill in the buffer with the next images & reset sights.

pop_coordinate(buffer_index, coord_index)[source]

Remove the coordinates to a given image index.

Override to pop the sights and the identifier too.

Parameters
  • buffer_index – (int) Index of the image in the buffer

  • coord_index – (int) Pop the given coord

remove_coordinate(buffer_index, coord)[source]

Remove the coordinates to a given image index.

Override to remove the sights and the identifier too.

Parameters
  • buffer_index – (int) Index of the image in the buffer

  • coord – (sppasCoords) Remove the given coord

reset()[source]

Override. Reset all the info related to the buffer content.

set_coordinates(buffer_index, coords)[source]

Set the coordinates to a given image index.

Override to invalidate the corresponding sights and identifiers.

Parameters
  • buffer_index – (int) Index of the image in the buffer

  • coords – (list of sppasCoords) Set the list of coords

set_id(buffer_index, coords_index, identifier)[source]

Set the id to coordinate of a given image index.

Parameters
  • buffer_index – (int) Index of the image in the buffer

  • coords_index – (int) Index of the coordinates for this id

  • identifier – (any) Any relevant information

set_ids(buffer_index, ids)[source]

Set the face identifiers of a given image index.

The number of identifiers must match the number of faces.

Parameters
  • buffer_index – (int) Index of the image in the buffer

  • ids – (list of identifiers) A list of face identifiers

set_sight(buffer_index, face_index, sight)[source]

Set the sights to a face of a given image index.

Parameters
  • buffer_index – (int) Index of the image in the buffer

  • sight – (Sights) the given sight object

set_sights(buffer_index, sights)[source]

Set the sights to a given image index.

The number of sights must match the number of faces.

Parameters
  • buffer_index – (int) Index of the image in the buffer

  • sights – (list of Sights) Set the list of sights

class annotations.FaceSights.videosights.sppasSightsVideoReader(csv_file, separator=';')[source]

Bases: object

Read&create list of coords and sights from a CSV file.

The CSV file must have the following columns:

  • frame number

  • the index of the coords – face_id in OpenFace2

  • timestamp

  • confidence – face detection

  • success – face detection

  • buffer number

  • index in the buffer

  • x, y, w, h

  • average confidence – face landmark

  • success – face landmark

  • n – number of sights

  • x_1 .. x_n

  • y_1 .. y_n

  • optionally score_1 .. score_n

__init__(csv_file, separator=';')[source]

Set the list of coords & sights defined in the given file.

Parameters
  • csv_file – (str) coords&sights from a sppasSightsVideoWriter

  • separator – (char) Columns separator in the CSV file

class annotations.FaceSights.videosights.sppasSightsVideoWriter(image_writer=None)[source]

Bases: sppas.src.videodata.sppasCoordsVideoWriter

Write a video and optionally coords/sights into files.

__init__(image_writer=None)[source]

Create a new instance.

write_coords(fd, video_buffer, buffer_idx, idx)[source]

Override to write the coords AND sights AND ids into the stream.

  • frame number

  • the index of the coords – face_id in OpenFace2

  • timestamp

  • confidence

  • success

  • buffer number

  • index in the buffer

  • x, y, w, h,

  • the nb of sights: 68

  • the 68 x values

  • the 68 y values

  • eventually, the 68 confidence scores

Parameters
  • fd – (Stream) File descriptor, String descriptor, stdout, etc

  • video_buffer – (sppasCoordsVideoBuffer)

  • buffer_idx – (int) Buffer number

  • idx – (int) An integer to write

write_video(video_buffer, out_name, pattern)[source]

Save the result in video format.

Parameters
  • video_buffer – (sppasImage) The image to write

  • out_name – (str) The filename of the output video file

  • pattern – (str) Pattern to add to cropped video filename(s)

Returns

list of newly created video file names

Module contents

filename

sppas.src.annotations.FaceSights.__init__.py

author

Brigitte Bigi

contact

develop@sppas.org

summary

Automatic detection of 68 face landmarks with opencv Facemark.

This package requires ‘video’ feature, for opencv and numpy dependencies.

class annotations.FaceSights.ImageFaceLandmark[source]

Bases: object

__init__()[source]
class annotations.FaceSights.Sights[source]

Bases: object

__init__()[source]
class annotations.FaceSights.sppasFaceSights[source]

Bases: object

__init__()[source]
class annotations.FaceSights.sppasSightsVideoBuffer[source]

Bases: object

__init__()[source]
class annotations.FaceSights.sppasSightsVideoReader[source]

Bases: object

__init__()[source]
class annotations.FaceSights.sppasSightsVideoWriter[source]

Bases: object

__init__()[source]