annotations.FaceSights package¶
Submodules¶
annotations.FaceSights.imgfacemark module¶
annotations.FaceSights.sights module¶
- filename
sppas.src.annotations.FaceSights.sights.py
- author
Brigitte Bigi
- contact
- 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
- check_index(value)[source]¶
Raise an exception if the given index is not valid.
- Parameters
value – (int)
- Raise
sppasTypeError, NegativeValueError, IndexRangeException
- 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)
- intermediate(other)[source]¶
Return the sights with the intermediate positions.
- Parameters
other – (Sights)
- Returns
(Sights)
- class annotations.FaceSights.sights.sppasImageSightsReader(csv_file)[source]¶
Bases:
object
Read&create sights from a CSV file.
Currently unused: To be tested.
- 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.
annotations.FaceSights.sppasfacesights module¶
annotations.FaceSights.videofacemark module¶
annotations.FaceSights.videosights module¶
- filename
sppas.src.annotations.FaceSights.videosights.py
- author
Brigitte Bigi
- contact
- 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)
- 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
- 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
- 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
- class annotations.FaceSights.videosights.sppasSightsVideoWriter(image_writer=None)[source]¶
Bases:
sppas.src.videodata.sppasCoordsVideoWriter
Write a video and optionally coords/sights into files.
- 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
- summary
Automatic detection of 68 face landmarks with opencv Facemark.
This package requires ‘video’ feature, for opencv and numpy dependencies.