PUtils Class Reference

Detailed Description

The PUtils class is a toolbox of common helper functions.

You cannot create instances of PUtils.

Definition at line 34 of file PUtils.h.

#include <PUtils.h>

Member Enumeration Documentation

◆ ELabelColourScheme

Enumerator
E_BLACK 

White text on black background.

E_RED 

White text on red background.

E_GREEN 

White text on green background.

E_SILVER 

White text on silver background.

E_BLUE 

White text on blue background.

E_ORANGE 

White text on orange background.

E_PINK 

Black text on pink background.

Definition at line 114 of file PUtils.h.

◆ ELabelPosition

Enumerator
E_CENTRE 
E_TOP_CENTRE 
E_BOTTOM_CENTRE 

Definition at line 107 of file PUtils.h.

Member Function Documentation

◆ BlurDetection()

static PResult PUtils::BlurDetection ( PImage image,
const PDetection detection,
const PColour3i color,
papillon::int32  lineWidth 
)
static

Blurs the specified list of detections in an image.

Returns PResult::C_OK if success, another result otherwise.

◆ BlurDetectionList()

static PResult PUtils::BlurDetectionList ( PImage image,
const PDetectionList detectionList,
const PColour3i color,
papillon::int32  lineWidth 
)
static

Blurs the specified list of detections in an image.

Returns PResult::C_OK if success, another result otherwise.

◆ CropDetection() [1/2]

static PResult PUtils::CropDetection ( const PDetection detection,
PImage croppedImage,
PPoint2Di origin,
double  scale = 0.333 
)
static

Returns a cropped image from the image contained in the specified detection and the bounding rectangle of this detection.

Returns PResult::C_OK if success, another result otherwise.

◆ CropDetection() [2/2]

static PResult PUtils::CropDetection ( const PDetection detection,
PImage croppedImage,
double  scale = 0.333 
)
static

◆ DisplayDetection()

static PResult PUtils::DisplayDetection ( const PDetection detection,
const PString windowTitle,
float  scaleFactor = 1.0f,
const PColour3i colour = PColour3i::Red(),
bool  drawId = false,
bool  boundingBoxOnly = false,
papillon::int32  lineWidth = 1 
)
static

Displays one detection on an image.

This will make a copy of the image and overlay the detections on it. Returns PResult::C_OK if success, another result otherwise.

◆ DisplayDetectionList()

static PResult PUtils::DisplayDetectionList ( const PFrame frame,
const PDetectionList detectionList,
const PString windowTitle,
float  scaleFactor = 1.0f,
const PColour3i colour = PColour3i::Red(),
bool  drawId = false,
bool  boundingBoxOnly = false,
papillon::int32  lineWidth = 1,
papillon::int32  waitTimeMs = 0 
)
static

Displays some detections on an image.

This will make a copy of the image and overlay the detections on it. Returns PResult::C_OK if success, another result otherwise.

◆ DisplayFeatureMap()

static PResult PUtils::DisplayFeatureMap ( const PFrame frame,
const PFeatureMap featureMap,
const PString windowTitle,
float  scaleFactor = 1.0f,
const PColour3i colour = PColour3i::Red(),
bool  boundingBoxOnly = false,
papillon::int32  lineWidth = 1 
)
static

Displays a feature map on an image This will make a copy of the image and overlay the feature map on it Returns PResult::C_OK if success, another result otherwise.

◆ DisplayFirstFaceDetection()

static PResult PUtils::DisplayFirstFaceDetection ( const PFrame frame,
const PDetectionList detectionList,
const PString windowTitle,
const PColour3i colour = PColour3i::Red(),
bool  boundingBoxOnly = false,
papillon::int32  lineWidth = 1 
)
static

Displays first face detection on an image.

Crop to face rectangle. This will make a copy of the image and overlay the detections on it. Returns PResult::C_OK if success, another result otherwise. Specifically: an empty detection list or a missing face rectangle will give rise to an error.

◆ DrawDetection() [1/2]

static PResult PUtils::DrawDetection ( PImage  image,
const PDetection detection,
const PColour3i colour = PColour3i::Red(),
bool  drawId = false,
bool  boundingBoxOnly = false,
papillon::int32  lineWidth = 1 
)
static

Draws one detection on an image.

Returns PResult::C_OK if success, another result otherwise.

◆ DrawDetection() [2/2]

static PResult PUtils::DrawDetection ( PImage  image,
const PDetection detection,
const PString message,
const PColour3i colour = PColour3i::Red(),
bool  boundingBoxOnly = false,
papillon::int32  lineWidth = 1 
)
static

Draws one detection on an image.

Returns PResult::C_OK if success, another result otherwise.

◆ DrawDetectionList()

static PResult PUtils::DrawDetectionList ( PImage  image,
const PDetectionList detectionList,
const PColour3i colour = PColour3i::Red(),
bool  drawId = false,
bool  boundingBoxOnly = false,
papillon::int32  lineWidth = 1 
)
static

Draws some detections on an image.

Returns PResult::C_OK if success, another result otherwise.

◆ DrawFeatureMap()

static PResult PUtils::DrawFeatureMap ( PImage  image,
const PFeatureMap featureMap,
const PColour3i colour = PColour3i::Red(),
bool  boundingBoxOnly = false,
papillon::int32  lineWidth = 1 
)
static

Draws a feature map on an image Returns PResult::C_OK if success, another result otherwise.

◆ DrawLabel() [1/2]

static PResult PUtils::DrawLabel ( PImage  image,
const PDetection detection,
const PString message,
ELabelPosition  position = PUtils::E_TOP_CENTRE,
ELabelColourScheme  colourScheme = PUtils::E_BLACK,
double  fontSize = 1.0,
papillon::int32  lineWidth = 1,
const PColour3i boundingBoxColour = PColour3i::White(),
const PImage::EFont font = PImage::E_FONT_HERSHEY_PLAIN 
)
static

Draws a label on an image relative to a given detection.

This method applies the optional offset handled by the specified detection (see PDetection::GetOrigin(), PDetection::SetOrigin()). WARNING: only 7-bit ASCII characters are accepted (limitation of the internal fonts used to draw characters); other characters will be displayed as '?'.

Parameters
imageThe input image. This will get modified.
detectionThe detection
messageThe message to write
positionThe relative position of the label
colourSchemeThe label colour scheme to use
fontSizeThe size of the font. The label will always be made just big enough
lineWidthIf line width is greater than 0, then the bounding rectangle will also be drawn
boundingBoxColourThe colour to make the bounding box
fontThe font to use
Returns
PResult

◆ DrawLabel() [2/2]

static PResult PUtils::DrawLabel ( PImage  image,
const PDetection detection,
const PString message,
const PColour3i backgroundColour,
const PColour3i fontColour,
ELabelPosition  position = PUtils::E_TOP_CENTRE,
double  fontSize = 1.0,
papillon::int32  lineWidth = 1,
const PColour3i boundingBoxColour = PColour3i::White(),
const PImage::EFont font = PImage::E_FONT_HERSHEY_PLAIN 
)
static

Draws a label on an image relative to a given detection.

This method applies the optional offset handled by the specified detection (see PDetection::GetOrigin(), PDetection::SetOrigin()). WARNING: only 7-bit ASCII characters are accepted (limitation of the internal fonts used to draw characters); other characters will be displayed as '?'.

Parameters
imageThe input image. This will get modified.
detectionThe detection
messageThe message to write
positionThe relative position of the label
backgroundColourThe background colour of the label
fontColourThe colour of the font on their label
fontSizeThe size of the font. The label will always be made just big enough
lineWidthIf line width is greater than 0, then the bounding rectangle will also be drawn
boundingBoxColourThe colour to make the bounding box
fontThe font to use
Returns
PResult

◆ DrawRectangle()

static PResult PUtils::DrawRectangle ( PImage image,
const PRectanglei rectangle,
const PString message,
ELabelPosition  position = PUtils::E_TOP_CENTRE,
double  fontSize = 1.0,
papillon::int32  lineWidth = 1,
const PColour3i rectangleColour = PColour3i::White(),
const PColour3i labelColour = PColour3i::Black(),
const PColour3i fontColour = PColour3i::White(),
PImage::EFont  font = PImage::E_FONT_HERSHEY_PLAIN 
)
static

Draws a rectangle on an image with a label WARNING: only 7-bit ASCII characters are accepted (limitation of the internal fonts used to draw characters); other characters will be displayed as '?'.

Parameters
imageThe input image. This will get modified.
rectangleThe detection
messageThe message to write
positionThe relative position of the label
fontSizeThe size of the font. The label will always be made just big enough
lineWidthIf line width is greater than 0, then the bounding rectangle will also be drawn
rectangleColourThe colour to make the bounding box
labelColourThe colour of the label.
fontColourThe colour of the font on their label
fontThe font to use
Returns
PResult

◆ GetCurrentProcessMemoryUsageMB()

static PResult PUtils::GetCurrentProcessMemoryUsageMB ( float &  currentMemoryUsageMB,
float &  peakMemoryUsageMB,
papillon::uint32 &  pageFaultCount 
)
static

Returns memory usage of the current process.

Returns PResult::C_OK if success, another result otherwise.

◆ GetEnv()

static PString PUtils::GetEnv ( const PString envVar)
static

Returns the value associated with the specified environment variable or an empty string if the environment variable does not exist.

◆ IsEscPressed()

static bool PUtils::IsEscPressed ( )
static

Returns true if ESCAPE key is pressed, false otherwise.

◆ IsKeyPressed()

static bool PUtils::IsKeyPressed ( papillon::int32  key = -1)
static

Returns true if any key is pressed, false otherwise.

You can test for a specific key. WARNING: If calling with default argument, the pressed key is "left in the queue" (i.e. the key-press is NOT consumed), whereas when you test for a specific key, it is removed with getchar() (i.e. the key-press IS consumed),

◆ MakeLabel()

static PImage PUtils::MakeLabel ( const PString text,
double  fontSize = 1.0,
papillon::int32  thickness = 1,
const PColour3i labelColour = PColour3i::Black(),
const PColour3i textColor = PColour3i::White(),
papillon::int32  border = 3,
PImage::EFont  font = PImage::E_FONT_HERSHEY_PLAIN,
PImage::EPixelFormat  pixelFormat = PImage::E_BGR8U 
)
static

Makes a label image.

Returns PResult::C_OK on success, another results otherwise. WARNING: only 7-bit ASCII characters are accepted (limitation of the internal fonts used to draw characters); other characters will be displayed as '?'.

Parameters
textThe text to write in the label.
fontSizeThe scale of the font. Note the label will automatically resize to fit the fontScale.
thicknessThickness of the lines used to draw a text.
labelColourThe colour of the label.
textColorThe colour of the text (make it in contrast to the label colour).
borderSize of the border in pixels.
fontThe font to use.
pixelFormatoutput pixel format.
Returns
PResult PResult::C_OK on success, another results otherwise

◆ PrintStackTrace()

static void PUtils::PrintStackTrace ( const PLogStream os)
static

Prints stack trace into the log stream.

◆ WaitForKeyPressed()

static void PUtils::WaitForKeyPressed ( )
static

Waits until any key is pressed.

WARNING: This might not do what you expect. At least on Linux, once a key has been pressed, repeated calls to this function will return immediately until you actually read the pressed key with some other function (i.e. WaitForKeyPressed() does NOT consume the key-press)