feat: initial HSAP platform
Huaxu Sentinel Active Safety Platform with embedded algorithm code, Docker Compose setup, and vendored dataset scaffolds for clone-and-run. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
47
algorithms/lane_ufld/code/UFLD/evaluation/culane/include/counter.hpp
Executable file
47
algorithms/lane_ufld/code/UFLD/evaluation/culane/include/counter.hpp
Executable file
@@ -0,0 +1,47 @@
|
||||
#ifndef COUNTER_HPP
|
||||
#define COUNTER_HPP
|
||||
|
||||
#include "lane_compare.hpp"
|
||||
#include "hungarianGraph.hpp"
|
||||
#include <iostream>
|
||||
#include <algorithm>
|
||||
#include <tuple>
|
||||
#include <vector>
|
||||
#include <opencv2/core.hpp>
|
||||
|
||||
using namespace std;
|
||||
using namespace cv;
|
||||
|
||||
// before coming to use functions of this class, the lanes should resize to im_width and im_height using resize_lane() in lane_compare.hpp
|
||||
class Counter
|
||||
{
|
||||
public:
|
||||
Counter(int _im_width, int _im_height, double _iou_threshold=0.4, int _lane_width=10):tp(0),fp(0),fn(0){
|
||||
im_width = _im_width;
|
||||
im_height = _im_height;
|
||||
sim_threshold = _iou_threshold;
|
||||
lane_compare = new LaneCompare(_im_width, _im_height, _lane_width, LaneCompare::IOU);
|
||||
};
|
||||
double get_precision(void);
|
||||
double get_recall(void);
|
||||
long getTP(void);
|
||||
long getFP(void);
|
||||
long getFN(void);
|
||||
void setTP(long);
|
||||
void setFP(long);
|
||||
void setFN(long);
|
||||
// direct add tp, fp, tn and fn
|
||||
// first match with hungarian
|
||||
tuple<vector<int>, long, long, long, long> count_im_pair(const vector<vector<Point2f> > &anno_lanes, const vector<vector<Point2f> > &detect_lanes);
|
||||
void makeMatch(const vector<vector<double> > &similarity, vector<int> &match1, vector<int> &match2);
|
||||
|
||||
private:
|
||||
double sim_threshold;
|
||||
int im_width;
|
||||
int im_height;
|
||||
long tp;
|
||||
long fp;
|
||||
long fn;
|
||||
LaneCompare *lane_compare;
|
||||
};
|
||||
#endif
|
||||
71
algorithms/lane_ufld/code/UFLD/evaluation/culane/include/hungarianGraph.hpp
Executable file
71
algorithms/lane_ufld/code/UFLD/evaluation/culane/include/hungarianGraph.hpp
Executable file
@@ -0,0 +1,71 @@
|
||||
#ifndef HUNGARIAN_GRAPH_HPP
|
||||
#define HUNGARIAN_GRAPH_HPP
|
||||
#include <vector>
|
||||
using namespace std;
|
||||
|
||||
struct pipartiteGraph {
|
||||
vector<vector<double> > mat;
|
||||
vector<bool> leftUsed, rightUsed;
|
||||
vector<double> leftWeight, rightWeight;
|
||||
vector<int>rightMatch, leftMatch;
|
||||
int leftNum, rightNum;
|
||||
bool matchDfs(int u) {
|
||||
leftUsed[u] = true;
|
||||
for (int v = 0; v < rightNum; v++) {
|
||||
if (!rightUsed[v] && fabs(leftWeight[u] + rightWeight[v] - mat[u][v]) < 1e-2) {
|
||||
rightUsed[v] = true;
|
||||
if (rightMatch[v] == -1 || matchDfs(rightMatch[v])) {
|
||||
rightMatch[v] = u;
|
||||
leftMatch[u] = v;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
void resize(int leftNum, int rightNum) {
|
||||
this->leftNum = leftNum;
|
||||
this->rightNum = rightNum;
|
||||
leftMatch.resize(leftNum);
|
||||
rightMatch.resize(rightNum);
|
||||
leftUsed.resize(leftNum);
|
||||
rightUsed.resize(rightNum);
|
||||
leftWeight.resize(leftNum);
|
||||
rightWeight.resize(rightNum);
|
||||
mat.resize(leftNum);
|
||||
for (int i = 0; i < leftNum; i++) mat[i].resize(rightNum);
|
||||
}
|
||||
void match() {
|
||||
for (int i = 0; i < leftNum; i++) leftMatch[i] = -1;
|
||||
for (int i = 0; i < rightNum; i++) rightMatch[i] = -1;
|
||||
for (int i = 0; i < rightNum; i++) rightWeight[i] = 0;
|
||||
for (int i = 0; i < leftNum; i++) {
|
||||
leftWeight[i] = -1e5;
|
||||
for (int j = 0; j < rightNum; j++) {
|
||||
if (leftWeight[i] < mat[i][j]) leftWeight[i] = mat[i][j];
|
||||
}
|
||||
}
|
||||
|
||||
for (int u = 0; u < leftNum; u++) {
|
||||
while (1) {
|
||||
for (int i = 0; i < leftNum; i++) leftUsed[i] = false;
|
||||
for (int i = 0; i < rightNum; i++) rightUsed[i] = false;
|
||||
if (matchDfs(u)) break;
|
||||
double d = 1e10;
|
||||
for (int i = 0; i < leftNum; i++) {
|
||||
if (leftUsed[i] ) {
|
||||
for (int j = 0; j < rightNum; j++) {
|
||||
if (!rightUsed[j]) d = min(d, leftWeight[i] + rightWeight[j] - mat[i][j]);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (d == 1e10) return ;
|
||||
for (int i = 0; i < leftNum; i++) if (leftUsed[i]) leftWeight[i] -= d;
|
||||
for (int i = 0; i < rightNum; i++) if (rightUsed[i]) rightWeight[i] += d;
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
#endif // HUNGARIAN_GRAPH_HPP
|
||||
37
algorithms/lane_ufld/code/UFLD/evaluation/culane/include/lane_compare.hpp
Executable file
37
algorithms/lane_ufld/code/UFLD/evaluation/culane/include/lane_compare.hpp
Executable file
@@ -0,0 +1,37 @@
|
||||
#ifndef LANE_COMPARE_HPP
|
||||
#define LANE_COMPARE_HPP
|
||||
|
||||
#include "spline.hpp"
|
||||
#include <vector>
|
||||
#include <iostream>
|
||||
#include <opencv2/core.hpp>
|
||||
#include <opencv2/imgproc.hpp>
|
||||
|
||||
using namespace std;
|
||||
using namespace cv;
|
||||
|
||||
class LaneCompare{
|
||||
public:
|
||||
enum CompareMode{
|
||||
IOU,
|
||||
Caltech
|
||||
};
|
||||
|
||||
LaneCompare(int _im_width, int _im_height, int _lane_width = 10, CompareMode _compare_mode = IOU){
|
||||
im_width = _im_width;
|
||||
im_height = _im_height;
|
||||
compare_mode = _compare_mode;
|
||||
lane_width = _lane_width;
|
||||
}
|
||||
|
||||
double get_lane_similarity(const vector<Point2f> &lane1, const vector<Point2f> &lane2);
|
||||
void resize_lane(vector<Point2f> &curr_lane, int curr_width, int curr_height);
|
||||
private:
|
||||
CompareMode compare_mode;
|
||||
int im_width;
|
||||
int im_height;
|
||||
int lane_width;
|
||||
Spline splineSolver;
|
||||
};
|
||||
|
||||
#endif
|
||||
28
algorithms/lane_ufld/code/UFLD/evaluation/culane/include/spline.hpp
Executable file
28
algorithms/lane_ufld/code/UFLD/evaluation/culane/include/spline.hpp
Executable file
@@ -0,0 +1,28 @@
|
||||
#ifndef SPLINE_HPP
|
||||
#define SPLINE_HPP
|
||||
#include <vector>
|
||||
#include <cstdio>
|
||||
#include <math.h>
|
||||
#include <opencv2/core.hpp>
|
||||
|
||||
using namespace cv;
|
||||
using namespace std;
|
||||
|
||||
struct Func {
|
||||
double a_x;
|
||||
double b_x;
|
||||
double c_x;
|
||||
double d_x;
|
||||
double a_y;
|
||||
double b_y;
|
||||
double c_y;
|
||||
double d_y;
|
||||
double h;
|
||||
};
|
||||
class Spline {
|
||||
public:
|
||||
vector<Point2f> splineInterpTimes(const vector<Point2f> &tmp_line, int times);
|
||||
vector<Point2f> splineInterpStep(vector<Point2f> tmp_line, double step);
|
||||
vector<Func> cal_fun(const vector<Point2f> &point_v);
|
||||
};
|
||||
#endif
|
||||
Reference in New Issue
Block a user