rmcv  v0.1.0
A library for RoboMaster computer vision based on OpenCV.
utils.h
1 //
2 // Created by yaione on 3/3/2022.
3 //
4 
5 #ifndef RMCV_UTILS_H
6 #define RMCV_UTILS_H
7 
8 #include <cmath>
9 #include <vector>
10 #include <string>
11 #include <sys/stat.h>
12 #include <dirent.h>
13 #include <filesystem>
14 #include <sys/io.h>
15 #include <cstring>
16 #include "opencv2/opencv.hpp"
17 
18 namespace rm {
19  enum RectType {
20  RECT_TALL = 0, RECT_SIDE = 1
21  };
22 
23  enum FileType {
24  FILETYPE_REGULAR_FILE = 0,
25  FILETYPE_DIRECTORY = 1,
26  FILETYPE_SYMBOLIC_LINK = 2,
27  FILETYPE_SOCKET = 3,
28  FILETYPE_UNKNOWN = -1
29  };
30 
31  rm::FileType GetFileType(const char *filename);
32 
33  bool ListFiles(const char *path, std::vector<std::string> &filenames);
34 
35  cv::Rect
36  GetROI(cv::Point2f *imagePoints, int pointsCount, float scaleFactor = 1.0f, const cv::Size &frameSize = {-1, -1},
37  const cv::Rect &previous = {0, 0, 0, 0});
38 
39  cv::Rect GetROI(cv::Point2f *imagePoints, int pointsCount, const cv::Size2f &scaleFactor = {1, 1},
40  const cv::Size &frameSize = {-1, -1}, const cv::Rect &previous = {0, 0, 0, 0});
41 
46  void VerticesRectify(cv::RotatedRect &input, cv::Point2f *output, RectType type);
47 
52  void CalcPerspective(cv::Point2f input[4], cv::Point2f output[4], float outRatio = 1.0f);
53 
60  double NewtonIteration(double (*fd)(double), double x0 = 0, double error = 0.0001, int cycle = 1024);
61 
69  double
70  NewtonIteration(double (*fd)(double, std::vector<double>), const std::vector<double> &literals, double x0 = 0,
71  double error = 0.0001, int cycle = 1024);
72 
77  double ProjectileMotionFD(double theta, std::vector<double> literals);
78 
79 
80 
85  float PointDistance(const cv::Point2f &pt1, const cv::Point2f &pt2);
86 
91  float PointDistance(const cv::Point2i &pt1, const cv::Point2i &pt2);
92 
97  cv::Point2f LineCenter(const cv::Point2f &pt1, const cv::Point2f &pt2);
98 
105  void
106  ExtendCord(const cv::Point2f &pt1, const cv::Point2f &pt2, float deltaLen, cv::Point2f &dst1, cv::Point2f &dst2);
107 
108  std::string PathCombine(const std::string &path1, const std::string &path2);
109 
110  std::string int2str(int number);
111 }
112 
113 #endif //RMCV_UTILS_H
rm::NewtonIteration
double NewtonIteration(double(*fd)(double), double x0=0, double error=0.0001, int cycle=1024)
Definition: utils.cpp:108
rm::VerticesRectify
void VerticesRectify(cv::RotatedRect &input, cv::Point2f *output, RectType type)
Definition: utils.cpp:90
rm::PointDistance
float PointDistance(const cv::Point2f &pt1, const cv::Point2f &pt2)
Definition: utils.cpp:154
rm::CalcPerspective
void CalcPerspective(cv::Point2f input[4], cv::Point2f output[4], float outRatio=1.0f)
Definition: utils.cpp:241
rm
Main modules.
Definition: daheng.h:17
rm::LineCenter
cv::Point2f LineCenter(const cv::Point2f &pt1, const cv::Point2f &pt2)
Definition: utils.cpp:259
rm::ExtendCord
void ExtendCord(const cv::Point2f &pt1, const cv::Point2f &pt2, float deltaLen, cv::Point2f &dst1, cv::Point2f &dst2)
Definition: utils.cpp:163
rm::ProjectileMotionFD
double ProjectileMotionFD(double theta, std::vector< double > literals)
Definition: utils.cpp:137