Add person dataset assembler, restructure repo

This commit is contained in:
2024-04-05 12:46:06 +02:00
parent 81475815fb
commit 03e2b3119a
25 changed files with 172 additions and 15 deletions

46
SmartCrop/yolo.h Normal file
View File

@ -0,0 +1,46 @@
#pragma once
#include <fstream>
#include <vector>
#include <string>
#include <random>
#include <filesystem>
#include <opencv2/imgproc.hpp>
#include <opencv2/opencv.hpp>
#include <opencv2/dnn.hpp>
class Yolo
{
public:
struct Detection
{
int class_id = 0;
std::string className;
float confidence = 0.0;
int priority = -1;
cv::Scalar color;
cv::Rect box;
};
private:
static constexpr float modelConfidenceThreshold = 0.25;
static constexpr float modelScoreThreshold = 0.45;
static constexpr float modelNMSThreshold = 0.50;
std::string modelPath;
std::vector<std::pair<std::string, int>> classes;
cv::Size2f modelShape;
bool letterBoxForSquare = true;
cv::dnn::Net net;
void loadClasses(const std::string& classes);
void loadOnnxNetwork(const std::filesystem::path& path);
cv::Mat formatToSquare(const cv::Mat &source);
static void clampBox(cv::Rect& box, const cv::Size& size);
public:
Yolo(const std::filesystem::path &onnxModelPath = "", const cv::Size& modelInputShape = {640, 480},
const std::filesystem::path& classesTxtFilePath = "", bool runWithOCl = true);
std::vector<Detection> runInference(const cv::Mat &input);
int getClassForStr(const std::string& str) const;
};