DeepSight SDK  3.0.0
DeepSight SDK - crowd face analysis
ds_help.h
Go to the documentation of this file.
1 /*
2  * DeepSight face analysis SDK
3  * Copyright (C) 2013-2023 Raydiant Inc. - All Rights Reserved
4  *
5  * This file is subject to the terms and conditions defined in
6  * the 'LICENSE.txt' file, which is part of this source code package.
7  *
8  */
9 
10 #ifndef DS_HELP_H
11 #define DS_HELP_H
12 
13 #include "ds_exports.h"
14 #include "ds_person.h"
15 
16 #include <chrono>
17 #include <vector>
18 #include <opencv2/core/core.hpp>
19 
20 namespace ds {
21 namespace help {
22 
23  // Fps counter
24  class DS_API Fps
25  {
26  public:
27  float operator()();
28  private:
29  std::chrono::high_resolution_clock::time_point mLastTick;
30  };
31 
32 
33  // Source Handler
35  {
36  public:
37  SourceHandler( int webcamIndex = 0, const cv::Size & resolution = { 0, 0 } ); // Use webcam
38  SourceHandler( const std::string & videoFilePath, bool loopVideo, bool processAllFrames ); // Use video file
39  SourceHandler( const std::string & videoStreamUrl ); // Use video stream
40  ~SourceHandler() noexcept;
41 
42  void useUsbCamera( int webcamIndex = 0, const cv::Size & resolution = { 0, 0 } );
43  void useVideoFile( const std::string & videoFilePath, bool loopVideo, bool processAllFrames );
44  void useVideoStream( const std::string & videoStreamUrl );
45 
46  void start();
47  void stop();
48  void pause();
49  void unpause();
50 
51  bool isUsbCamera() const;
52  bool isVideoFile() const;
53  bool isVideoStream() const;
54 
55  cv::Size getSourceResolution() const;
56  int getSourceFps() const;
57 
58  enum class Status : unsigned char { OK, NOT_INITIALIZED, NOT_READY, FAILURE, STREAM_RECONNECTING, VIDEO_ENDED };
59  std::tuple<cv::Mat, unsigned int, Status> getNextFrame();
60 
61  private:
62  class SourceHandlerImpl;
63  std::unique_ptr<SourceHandlerImpl> mSourceHandlerImpl;
64  };
65 
66 
67  // Pad (and clip overflow) a cv::Rect by padding factor
68  DS_API cv::Rect padRect( const cv::Rect & rect, float padFactor );
69  DS_API cv::Rect clipRect( const cv::Rect & rect, const cv::Mat & image );
70  DS_API cv::Rect padClipRect( const cv::Rect & rect, float padFactor, const cv::Mat & image );
71 
72  DS_API void drawHeadpose( cv::Mat & frame, const ds::Person & person );
73 
74  // Draw a ds::Person onto the input image
75  DS_API void drawPerson ( const ds::Person & person, cv::Mat & image );
76  DS_API void drawPersonNoLabel( const ds::Person & person, cv::Mat & image );
77  DS_API void drawPersonMinimal( const ds::Person & person, cv::Mat & image );
78  DS_API void drawPeople ( const std::vector<ds::Person> & people, cv::Mat & image );
79  DS_API void drawPeopleNoLabel( const std::vector<ds::Person> & people, cv::Mat & image );
80  DS_API void drawPeopleMinimal( const std::vector<ds::Person> & people, cv::Mat & image );
81 
82  // Draw a ds::Person onto the output image
83  DS_API cv::Mat drawPerson ( const ds::Person & person, const cv::Mat & image );
84  DS_API cv::Mat drawPersonNoLabel( const ds::Person & person, const cv::Mat & image );
85  DS_API cv::Mat drawPersonMinimal( const ds::Person & person, const cv::Mat & image );
86  DS_API cv::Mat drawPeople ( const std::vector<ds::Person> & people, const cv::Mat & image );
87  DS_API cv::Mat drawPeopleNoLabel( const std::vector<ds::Person> & people, const cv::Mat & image );
88  DS_API cv::Mat drawPeopleMinimal( const std::vector<ds::Person> & people, const cv::Mat & image );
89 
90  // Draw a ds::Body onto the input image
91  DS_API void drawBody ( const ds::Body & body, cv::Mat & image );
92  DS_API void drawBodies( const std::vector<ds::Body> & bodies, cv::Mat & image );
93 
94  // Draw a ds::Body onto the output image
95  DS_API cv::Mat drawBody ( const ds::Body & body, const cv::Mat & image );
96  DS_API cv::Mat drawBodies( const std::vector<ds::Body> & bodies, const cv::Mat & image );
97 
98  // Blur a ds::Person in the input image
99  DS_API void blurPerson( const ds::Person & person, cv::Mat & image );
100  DS_API void blurPeople( const std::vector<ds::Person> & people, cv::Mat & image );
101  DS_API void blurBox( const cv::Rect & box, cv::Mat & image );
102  DS_API void blurBoxes( const std::vector<cv::Rect> & boxes, cv::Mat & image );
103 
104  // Blur a ds::Person in the output image
105  DS_API cv::Mat blurPerson( const ds::Person & person, const cv::Mat & image );
106  DS_API cv::Mat blurPeople( const std::vector<ds::Person> & people, const cv::Mat & image );
107  DS_API cv::Mat blurBox( const cv::Rect & box, const cv::Mat & image );
108  DS_API cv::Mat blurBoxes( const std::vector<cv::Rect> & boxes, const cv::Mat & image );
109 
110  // Format a ds::Person info as a CSV line string
111  DS_API std::string personToCsvHeader();
112  DS_API std::string personToCsv( const ds::Person & person );
113  DS_API std::vector<std::string> peopleToCsv( const std::vector<ds::Person> & people );
114  // Format a ds::Person into a templated string
115  DS_API std::string formatPerson( const std::string & templateStr,
116  const ds::Person & person );
117 
118  // Format a ds::AggregatedPerson info as a CSV line string
119  DS_API std::string aggregatedPersonToCsvHeader();
120  DS_API std::string aggregatedPersonToCsv( const ds::AggregatedPerson & aggregatedPerson );
121  DS_API std::vector<std::string> aggregatedPeopleToCsv( const std::vector<ds::AggregatedPerson> & aggregatedPeople );
122  // Format a ds::Person into a templated string
123  DS_API std::string formatAggregatedPerson( const std::string & templateStr,
124  const ds::AggregatedPerson & aggregatedPerson );
125 
126  // Format a ds::Body info as a CSV line string
127  DS_API std::string bodyToCsvHeader();
128  DS_API std::string bodyToCsv( const ds::Body & body );
129  DS_API std::vector<std::string> bodiesToCsv( const std::vector<ds::Body> & bodies );
130  // Format a ds::Body into a templated string
131  DS_API std::string formatBody( const std::string & templateStr,
132  const ds::Body & body );
133 
134  // Format a ds::AggregatedBody info as a CSV line string
135  DS_API std::string aggregatedBodyToCsvHeader();
136  DS_API std::string aggregatedBodyToCsv( const ds::AggregatedBody & aggregatedBody );
137  DS_API std::vector<std::string> aggregatedBodiesToCsv( const std::vector<ds::AggregatedBody> & aggregatedBodies );
138  // Format a ds::Body into a templated string
139  DS_API std::string formatAggregatedBody( const std::string & templateStr,
140  const ds::AggregatedBody & aggregatedBody );
141 
142  DS_API std::string getMachineID( const std::string & licenseKey );
143 
144  DS_API std::string getOpenCLDebugString();
145 }
146 } /* namespace ds */
147 
148 #endif /* DS_HELP_H */
ds::AggregatedPerson
DeepSight SDK aggregated person class.
Definition: ds_person.h:65
ds::help::Fps
Helper class to keep track of analyzed frames per second.
Definition: ds_help.h:24
DS_API
#define DS_API
Controls the importing of the SDK symbols.
ds::help::SourceHandler
Helper class to handle different types of video input sources, like webcams, IP cameras or video file...
Definition: ds_help.h:34
ds::Person
DeepSight SDK person's face class.
Definition: ds_person.h:20
ds::AggregatedBody
DeepSight SDK aggregated body class.
Definition: ds_person.h:103
ds_person.h
ds::Body
DeepSight SDK person's body class.
Definition: ds_person.h:92
ds::help::SourceHandler::Status
Status
The status of the last frame retrieved from ds::help::SourceHandler::getNextFrame()
Definition: ds_help.h:58
ds_exports.h