init commit

This commit is contained in:
2024-07-13 13:15:28 +00:00
commit 157639e9e3
14 changed files with 1903 additions and 0 deletions

20
include/utils/augment.h Normal file
View File

@ -0,0 +1,20 @@
#pragma once
#include <opencv2/core/types.hpp>
void letterbox(const cv::Mat& image,
cv::Mat& outImage,
const cv::Size& newShape = cv::Size(640, 640),
cv::Scalar_<double> color = cv::Scalar(), bool auto_ = true,
bool scaleFill = false,
bool scaleUp = true,
int stride = 32
);
cv::Mat scale_image(const cv::Mat& resized_mask, const cv::Size& im0_shape, const std::pair<float,
cv::Point2f>& ratio_pad = std::make_pair(-1.0f, cv::Point2f(-1.0f, -1.0f)));
void scale_image2(
cv::Mat& scaled_mask, const cv::Mat& resized_mask, const cv::Size& im0_shape,
const std::pair<float, cv::Point2f>& ratio_pad = std::make_pair(-1.0f, cv::Point2f(-1.0f, -1.0f))
);

26
include/utils/common.h Normal file
View File

@ -0,0 +1,26 @@
#ifndef COMMON_UTILS_H
#define COMMON_UTILS_H
#include <chrono>
#include <string>
#include <unordered_map>
#include <vector>
class Timer {
public:
Timer(double& accumulator, bool isEnabled = true);
void Stop();
private:
double& accumulator;
bool isEnabled;
std::chrono::time_point<std::chrono::high_resolution_clock> start;
};
std::wstring get_win_path(const std::string& path);
std::vector<std::string> parseVectorString(const std::string& input);
std::vector<int> convertStringVectorToInts(const std::vector<std::string>& input);
std::unordered_map<int, std::string> parseNames(const std::string& input);
int64_t vector_product(const std::vector<int64_t>& vec);
#endif // COMMON_H COMMON_UTILS_H

44
include/utils/ops.h Normal file
View File

@ -0,0 +1,44 @@
#pragma once
#include <opencv2/core/types.hpp>
//cv::Rect scaleCoords(const cv::Size& imageShape, const cv::Rect& coords, const cv::Size& imageOriginalShape);
/**
* Scales a bounding box from the shape of the input image to the shape of an original image.
*
* @param img1_shape The shape (height, width) of the input image for the model.
* @param box The bounding box to be scaled, specified as cv::Rect_<float>.
* @param img0_shape The shape (height, width) of the original target image.
* @param ratio_pad An optional parameter that specifies scaling and padding factors as a pair of values.
* The first value (ratio) is used for scaling, and the second value (pad) is used for padding.
* If not provided, default values will be used.
* @param padding An optional boolean parameter that specifies whether padding should be applied.
* If set to true, padding will be applied to the bounding box.
*
* @return A scaled bounding box specified as cv::Rect_<float>.
*
* This function rescales a bounding box from the shape of the input image (img1_shape) to the shape of an original image (img0_shape).
*/
cv::Rect_<float> scale_boxes(const cv::Size& img1_shape, cv::Rect_<float>& box, const cv::Size& img0_shape, std::pair<float, cv::Point2f> ratio_pad = std::make_pair(-1.0f, cv::Point2f(-1.0f, -1.0f)), bool padding = true);
void clip_boxes(cv::Rect& box, const cv::Size& shape);
void clip_boxes(cv::Rect_<float>& box, const cv::Size& shape);
void clip_boxes(std::vector<cv::Rect>& boxes, const cv::Size& shape);
void clip_boxes(std::vector<cv::Rect_<float>>& boxes, const cv::Size& shape);
//void clip_coords(cv::Mat& coords, const cv::Size& shape);
//cv::Mat scale_coords(const cv::Size& img1_shape, cv::Mat& coords, const cv::Size& img0_shape);
void clip_coords(std::vector<float>& coords, const cv::Size& shape);
std::vector<float> scale_coords(const cv::Size& img1_shape, std::vector<float>& coords, const cv::Size& img0_shape);
cv::Mat crop_mask(const cv::Mat& mask, const cv::Rect& box);
struct NMSResult{
std::vector<cv::Rect> bboxes;
std::vector<float> confidences;
std::vector<int> classes;
std::vector<std::vector<float>> rest;
};
//std::tuple<std::vector<cv::Rect_<float>>, std::vector<float>, std::vector<int>, std::vector<std::vector<float>>>
std::tuple<std::vector<cv::Rect>, std::vector<float>, std::vector<int>, std::vector<std::vector<float>>>
non_max_suppression(const cv::Mat& output0, int class_names_num, int total_features_num, double conf_threshold, float iou_threshold);