Skip to content
This repository was archived by the owner on Aug 7, 2024. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
dynamic_vino_lib/html/*
dynamic_vino_lib/latex/*
.vscode
Binary file added data/images/bus.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 3 additions & 2 deletions vino_core_lib/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ project(vino_core_lib)

####################################
## uncomment below line to get verbose log
## add_definitions(-DLOG_LEVEL_DEBUG)
# add_definitions(-DLOG_LEVEL_DEBUG)
####################################

message(STATUS "Looking for inference engine configuration file at: ${CMAKE_PREFIX_PATH}")
Expand Down Expand Up @@ -180,7 +180,8 @@ add_library(${PROJECT_NAME} SHARED
src/models/face_detection_model.cpp
src/models/head_pose_detection_model.cpp
src/models/object_detection_ssd_model.cpp
# src/models/object_detection_yolov2voc_model.cpp
src/models/object_detection_yolov2voc_model.cpp
src/models/object_detection_yolov5_model.cpp
src/models/object_segmentation_model.cpp
src/models/person_reidentification_model.cpp
src/models/face_reidentification_model.cpp
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,12 +77,18 @@ class AgeGenderDetection : public BaseInference
{
public:
using Result = vino_core_lib::AgeGenderResult;
AgeGenderDetection();
~AgeGenderDetection() override;
AgeGenderDetection(){};
~AgeGenderDetection() override {};

/**
* @brief Load the face detection model.
*/
void loadNetwork(std::shared_ptr<Models::BaseModel>) override;

/**
* @brief Load the age gender detection model.
*/
void loadNetwork(std::shared_ptr<Models::AgeGenderDetectionModel>);
// void loadNetwork(std::shared_ptr<Models::AgeGenderDetectionModel>);
/**
* @brief Enqueue a frame to this class.
* The frame will be buffered but not infered yet.
Expand Down
10 changes: 10 additions & 0 deletions vino_core_lib/include/vino_core_lib/inferences/base_inference.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
#include <vector>

#include "vino_core_lib/engines/engine.h"
#include "vino_core_lib/vino_factory.h"
#include "vino_core_lib/models/base_model.h"
#include "vino_core_lib/slog.h"
#include "inference_engine.hpp"
Expand Down Expand Up @@ -106,6 +107,12 @@ class BaseInference
* running netwrok on target calculation device.
*/
void loadEngine(std::shared_ptr<Engines::Engine> engine);

/**
* @brief Load the face detection model.
*/
virtual void loadNetwork(std::shared_ptr<Models::BaseModel>) = 0;

/**
* @brief Get the loaded Engine instance.
* @return The loaded Engine instance.
Expand Down Expand Up @@ -215,4 +222,7 @@ class BaseInference
};
} // namespace vino_core_lib

#define REG_INFERENCE_FACTORY VinoFactory<std::string, vino_core_lib::BaseInference>
#define REG_INFERENCE(T, key) static REG_INFERENCE_FACTORY::TReg<vino_core_lib::T> gs_inference##_(key)

#endif // VINO_CORE_LIB__INFERENCES__BASE_INFERENCE_H
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ namespace Outputs
{
class BaseOuput;
}

namespace vino_core_lib
{
/**
Expand Down Expand Up @@ -68,12 +69,18 @@ class EmotionsDetection : public BaseInference
{
public:
using Result = vino_core_lib::EmotionsResult;
EmotionsDetection();
~EmotionsDetection() override;
EmotionsDetection() {};
~EmotionsDetection() override {};

/**
* @brief Load the face detection model.
*/
void loadNetwork(std::shared_ptr<Models::BaseModel>) override;

/**
* @brief Load the emotin detection model.
*/
void loadNetwork(std::shared_ptr<Models::EmotionDetectionModel>);
// void loadNetwork(std::shared_ptr<Models::EmotionDetectionModel>);
/**
* @brief Enqueue a frame to this class.
* The frame will be buffered but not infered yet.
Expand Down
167 changes: 163 additions & 4 deletions vino_core_lib/include/vino_core_lib/inferences/face_detection.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,10 @@
#include <object_msgs/ObjectInBox.h>
#include <object_msgs/ObjectsInBoxes.h>
#include <ros/ros.h>

#include <memory>
#include <string>
#include <vector>

#include <string>
#include <map>
#include "vino_core_lib/engines/engine.h"
#include "vino_core_lib/inferences/base_inference.h"
#include "vino_core_lib/inferences/object_detection.h"
Expand All @@ -47,17 +46,177 @@ namespace vino_core_lib
class FaceDetectionResult : public ObjectDetectionResult
{
public:
friend class ObjectDetection;
explicit FaceDetectionResult(const cv::Rect& location);

std::string getLabel() const
{
return label_;
}

void setLabel(const std::string& label)
{
label_ = label;
}
/**
* @brief Get the confidence that the detected area is a face.
* @return The confidence value.
*/
float getConfidence() const
{
return confidence_;
}

void setConfidence(const float& con)
{
confidence_ = con;
}

bool operator<(const FaceDetectionResult& s2) const
{
return this->confidence_ > s2.confidence_;
}

private:
std::string label_ = "";
float confidence_ = -1;
};

class FaceDetectionResultFilter : public BaseFilter
{
public:
using Result = vino_core_lib::FaceDetectionResult;

FaceDetectionResultFilter();

/**
* @brief Initiate the object detection result filter.
*/
void init() override;
/**
* @brief Set the object detection results into filter.
* @param[in] The object detection results.
*/
void acceptResults(const std::vector<Result>& results);
/**
* @brief Get the filtered results' ROIs.
* @return The filtered ROIs.
*/
std::vector<cv::Rect> getFilteredLocations() override;

private:
/**
* @brief Decide whether a result is valid for label filter condition.
* @param[in] Result to be decided, filter operator, target label value.
* @return True if valid, false if not.
*/
static bool isValidLabel(const Result& result, const std::string& op, const std::string& target);
/**
* @brief Decide whether a result is valid for confidence filter condition.
* @param[in] Result to be decided, filter operator, target confidence value.
* @return True if valid, false if not.
*/
static bool isValidConfidence(const Result& result, const std::string& op, const std::string& target);

/**
* @brief Decide whether a result is valid.
* @param[in] Result to be decided.
* @return True if valid, false if not.
*/
bool isValidResult(const Result& result);

std::map<std::string, bool (*)(const Result&, const std::string&, const std::string&)> key_to_function_;
std::vector<Result> results_;
};



/**
* @class FaceDetection
* @brief Class to load face detection model and perform face detection.
*/
class FaceDetection : public ObjectDetection
class FaceDetection : public BaseInference
{
public:
using Result = vino_core_lib::FaceDetectionResult;
using Filter = vino_core_lib::FaceDetectionResultFilter;
explicit FaceDetection(bool, double);
FaceDetection()
{
enable_roi_constraint_ = true;
show_output_thresh_ = 0.5;
result_filter_ = std::make_shared<Filter>();
result_filter_->init();
};

~FaceDetection() override {};

/**
* @brief Load the face detection model.
*/
void loadNetwork(std::shared_ptr<Models::BaseModel>) override;

/**
* @brief Load the face detection model.
*/
// void loadNetwork(std::shared_ptr<Models::FaceDetectionModel>);
/**
* @brief Enqueue a frame to this class.
* The frame will be buffered but not infered yet.
* @param[in] frame The frame to be enqueued.
* @param[in] input_frame_loc The location of the enqueued frame with respect
* to the frame generated by the input device.
* @return Whether this operation is successful.
*/
bool enqueue(const cv::Mat&, const cv::Rect&) override;

/**
* @brief This function will fetch the results of the previous inference and
* stores the results in a result buffer array. All buffered frames will be
* cleared.
* @return Whether the Inference object fetches a result this time
*/
bool fetchResults() override;
/**
* @brief Get the length of the buffer result array.
* @return The length of the buffer result array.
*/
int getResultsLength() const override;
/**
* @brief Get the location of result with respect
* to the frame generated by the input device.
* @param[in] idx The index of the result.
*/
const Result* getLocationResult(int idx) const override;
/**
* @brief Show the observed detection result either through image window
or ROS topic.
*/
void observeOutput(const std::shared_ptr<Outputs::BaseOutput>& output);
/**
* @brief Get the name of the Inference instance.
* @return The name of the Inference instance.
*/
const std::string getName() const override;

const std::vector<cv::Rect> getFilteredROIs(const std::string filter_conditions) const override;

/**
* @brief Calculate the IoU ratio for the given rectangles.
* @return IoU Ratio of the given rectangles.
*/
static double calcIoU(const cv::Rect& box_1, const cv::Rect& box_2);

private:
std::shared_ptr<Models::BaseModel> valid_model_;
std::shared_ptr<Filter> result_filter_;
std::vector<Result> results_;
int width_ = 0;
int height_ = 0;
int max_proposal_count_;
int object_size_;
double show_output_thresh_ = 0;
bool enable_roi_constraint_ = false;
};
} // namespace vino_core_lib
#endif // VINO_CORE_LIB__INFERENCES__FACE_DETECTION_H
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,18 @@ class FaceReidentification : public BaseInference
public:
using Result = vino_core_lib::FaceReidentificationResult;
explicit FaceReidentification(double);
FaceReidentification() {};
~FaceReidentification() override;

/**
* @brief Load the face detection model.
*/
void loadNetwork(std::shared_ptr<Models::BaseModel>) override;

/**
* @brief Load the face reidentification model.
*/
void loadNetwork(std::shared_ptr<Models::FaceReidentificationModel>);
// void loadNetwork(std::shared_ptr<Models::FaceReidentificationModel>);
/**
* @brief Enqueue a frame to this class.
* The frame will be buffered but not infered yet.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,12 +81,18 @@ class HeadPoseDetection : public BaseInference
{
public:
using Result = vino_core_lib::HeadPoseResult;
HeadPoseDetection();
~HeadPoseDetection() override;
HeadPoseDetection() {};
~HeadPoseDetection() override {};

/**
* @brief Load the face detection model.
*/
void loadNetwork(std::shared_ptr<Models::BaseModel>) override;

/**
* @brief Load the headpose detection model.
*/
void loadNetwork(std::shared_ptr<Models::HeadPoseDetectionModel>);
// void loadNetwork(std::shared_ptr<Models::HeadPoseDetectionModel>);
/**
* @brief Enqueue a frame to this class.
* The frame will be buffered but not infered yet.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,12 +54,18 @@ class LandmarksDetection : public BaseInference
{
public:
using Result = vino_core_lib::LandmarksDetectionResult;
LandmarksDetection();
~LandmarksDetection() override;
LandmarksDetection() {};
~LandmarksDetection() override {};

/**
* @brief Load the face detection model.
*/
void loadNetwork(std::shared_ptr<Models::BaseModel>) override;

/**
* @brief Load the landmarks detection model.
*/
void loadNetwork(std::shared_ptr<Models::LandmarksDetectionModel>);
// void loadNetwork(std::shared_ptr<Models::LandmarksDetectionModel>);
/**
* @brief Enqueue a frame to this class.
* The frame will be buffered but not infered yet.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,12 +54,18 @@ class LicensePlateDetection : public BaseInference
{
public:
using Result = vino_core_lib::LicensePlateDetectionResult;
LicensePlateDetection();
~LicensePlateDetection() override;
LicensePlateDetection() {};
~LicensePlateDetection() override {};

/**
* @brief Load the face detection model.
*/
void loadNetwork(std::shared_ptr<Models::BaseModel>) override;

/**
* @brief Load the license plate detection model.
*/
void loadNetwork(std::shared_ptr<Models::LicensePlateDetectionModel>);
// void loadNetwork(std::shared_ptr<Models::LicensePlateDetectionModel>);
/**
* @brief Enqueue a frame to this class.
* The frame will be buffered but not infered yet.
Expand Down
Loading