PUtils.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2015-2018 Digital Barriers plc. All rights reserved.
3  * Contact: http://www.digitalbarriers.com/
4  *
5  * This file is part of the Papillon SDK.
6  *
7  * You can't use, modify or distribute any part of this file without
8  * the explicit written agreements of Digital Barriers.
9  */
10 
15 #pragma once
16 #include <PapillonCommon.h>
17 #include <PColour3i.h>
18 #include <PDetectionList.h>
19 #include <PImage.h>
20 #include <PFrame.h>
21 #include <PFeatureMap.h>
22 #include <PString.h>
23 
24 PAPILLON_BEGIN_NAMESPACE
25 
28 
34 class PAPILLON_API_CORE PUtils
35 {
36 public:
41  static PString GetEnv(const PString& envVar);
42 
46  static bool IsEscPressed();
47 
54  static bool IsKeyPressed(papillon::int32 key = -1);
55 
61  static void WaitForKeyPressed();
62 
67  static PResult GetCurrentProcessMemoryUsageMB(float& currentMemoryUsageMB, float& peakMemoryUsageMB, papillon::uint32& pageFaultCount);
68 
72  static void PrintStackTrace(const PLogStream& os);
73 
78  static PResult DrawDetectionList(PImage image,
79  const PDetectionList& detectionList,
80  const PColour3i& colour = PColour3i::Red(),
81  bool drawId = false,
82  bool boundingBoxOnly = false,
83  papillon::int32 lineWidth = 1);
84 
89  static PResult DrawDetection(PImage image,
90  const PDetection& detection,
91  const PColour3i& colour = PColour3i::Red(),
92  bool drawId = false,
93  bool boundingBoxOnly = false,
94  papillon::int32 lineWidth = 1);
95 
100  static PResult DrawDetection(PImage image,
101  const PDetection& detection,
102  const PString& message,
103  const PColour3i& colour = PColour3i::Red(),
104  bool boundingBoxOnly = false,
105  papillon::int32 lineWidth = 1);
106 
108  {
111  E_BOTTOM_CENTRE
112  };
113 
115  {
122  E_PINK
123  };
124 
141  static PResult DrawRectangle(PImage& image,
142  const PRectanglei& rectangle,
143  const PString& message,
145  double fontSize = 1.0,
146  papillon::int32 lineWidth = 1,
147  const PColour3i& rectangleColour = PColour3i::White(),
148  const PColour3i& labelColour = PColour3i::Black(),
149  const PColour3i& fontColour = PColour3i::White(),
151  );
152 
169  static PResult DrawLabel(PImage image,
170  const PDetection& detection,
171  const PString& message,
173  ELabelColourScheme colourScheme = PUtils::E_BLACK,
174  double fontSize = 1.0,
175  papillon::int32 lineWidth = 1,
176  const PColour3i& boundingBoxColour = PColour3i::White(),
178  );
179 
197  static PResult DrawLabel(PImage image,
198  const PDetection& detection,
199  const PString& message,
200  const PColour3i& backgroundColour,
201  const PColour3i& fontColour,
203  double fontSize = 1.0,
204  papillon::int32 lineWidth = 1,
205  const PColour3i& boundingBoxColour = PColour3i::White(),
207 
223  static PImage MakeLabel(const PString& text,
224  double fontSize = 1.0,
225  papillon::int32 thickness = 1,
226  const PColour3i& labelColour = PColour3i::Black(),
227  const PColour3i& textColor = PColour3i::White(),
228  papillon::int32 border = 3,
230  PImage::EPixelFormat pixelFormat = PImage::E_BGR8U);
231 
237  static PResult DisplayDetectionList(const PFrame& frame,
238  const PDetectionList& detectionList,
239  const PString& windowTitle,
240  float scaleFactor = 1.0f,
241  const PColour3i& colour = PColour3i::Red(),
242  bool drawId = false,
243  bool boundingBoxOnly = false,
244  papillon::int32 lineWidth = 1,
245  papillon::int32 waitTimeMs = 0);
246 
252  static PResult DisplayFirstFaceDetection(const PFrame& frame,
253  const PDetectionList& detectionList,
254  const PString& windowTitle,
255  const PColour3i& colour = PColour3i::Red(),
256  bool boundingBoxOnly = false,
257  papillon::int32 lineWidth = 1);
258 
264  static PResult DisplayDetection(const PDetection& detection, const PString& windowTitle, float scaleFactor = 1.0f,
265  const PColour3i& colour = PColour3i::Red(), bool drawId = false, bool boundingBoxOnly = false,
266  papillon::int32 lineWidth = 1);
267 
273  static PResult DisplayFeatureMap(const PFrame& frame, const PFeatureMap& featureMap, const PString& windowTitle,
274  float scaleFactor = 1.0f, const PColour3i& colour = PColour3i::Red(), bool boundingBoxOnly = false,
275  papillon::int32 lineWidth = 1);
276 
281  static PResult DrawFeatureMap(PImage image, const PFeatureMap& featureMap, const PColour3i& colour = PColour3i::Red(),
282  bool boundingBoxOnly = false, papillon::int32 lineWidth = 1);
283 
289  static PResult CropDetection(const PDetection& detection, PImage& croppedImage, PPoint2Di& origin, double scale=0.333);
290  static PResult CropDetection(const PDetection& detection, PImage& croppedImage, double scale=0.333);
291 
296  static PResult BlurDetection(PImage& image, const PDetection& detection, const PColour3i& color, papillon::int32 lineWidth);
297 
302  static PResult BlurDetectionList(PImage& image, const PDetectionList& detectionList, const PColour3i& color, papillon::int32 lineWidth);
303 
304 private:
305  PUtils(); // cannot be instantiated
306 };
307 
309 
310 PAPILLON_END_NAMESPACE
White text on blue background.
Definition: PUtils.h:120
The PString class provides an Unicode character strings.
Definition: PString.h:37
White text on green background.
Definition: PUtils.h:118
The PFrame class represents any 2D-image (RGB, gray-scale, ...) with a container of additional data p...
Definition: PFrame.h:50
Class PDetectionList: a collection of detections (see PDetection).
Colour image: each pixel is a triple (B, G, R); each component is a 8-bit unsigned int...
Definition: PImage.h:66
ELabelColourScheme
Definition: PUtils.h:114
The PLogStream class represents a log stream used by log macros (should not be used directly...
Definition: PLog.h:263
White text on black background.
Definition: PUtils.h:116
EFont
All the available embedded fonts.
Definition: PImage.h:105
The PDetectionList class represents nothing more than a collection of detections (PDetection), Typically PDetectionList&#39;s are returned from a PDetector.
The PImage class represents a 2D-image; several pixel format and number of channels are supported (BG...
Definition: PImage.h:57
White text on silver background.
Definition: PUtils.h:119
static const PColour3i & Red()
Definition: PColour3i.h:126
The PResult class represents the result returned by most of Papillon functions; this class is used to...
Definition: PResult.h:159
White text on red background.
Definition: PUtils.h:117
static const PColour3i & Black()
Definition: PColour3i.h:110
The PDetection class represents something that has been detected by a PDetector.
Definition: PDetection.h:61
Class PImage: a 2D-image, mainly a buffer of pixels (available pixel formats are grey, BGR, RGB, RGBA, YUV, etc.)
The PUtils class is a toolbox of common helper functions.
Definition: PUtils.h:34
The PRectanglei class represents an axis-aligned rectangle with 32-bit int coordinates; PRectanglei i...
Definition: PRectanglei.h:33
Class PFrame: a PImage + PProperties to store optional properties (GUID of the source, timestamp, GPS location, etc.)
Class PString: an unicode character strings (use copy-on-write idiom).
White text on orange background.
Definition: PUtils.h:121
The PColour3i class represents a Red-Green-Blue color (RGB), each channel encoded with one 32-bit int...
Definition: PColour3i.h:25
Class PFeatureMap: a collection of PFeaturePoint.
static const PColour3i & White()
Definition: PColour3i.h:131
Class PColour3i: a Red-Green-Blue color (RGB), each channel encoded with one 32-bit int...
The PPoint2Di class represents a 2D-point with 32-bit int coordinates; PPoint2Di instances are immuta...
Definition: PPoint2Di.h:27
ELabelPosition
Definition: PUtils.h:107
The PFeatureMap class represents a collection of PFeaturePoint&#39;s or PFeatureRectangle&#39;s.
Definition: PFeatureMap.h:35
EPixelFormat
All the available pixel formats.
Definition: PImage.h:63