add mot & tracking -> sot
This commit is contained in:
parent
01fb11377a
commit
52258249b9
|
@ -71,7 +71,7 @@ include_directories(
|
||||||
${CMAKE_CURRENT_SOURCE_DIR}/gimbal_ctrl
|
${CMAKE_CURRENT_SOURCE_DIR}/gimbal_ctrl
|
||||||
${CMAKE_CURRENT_SOURCE_DIR}/algorithm/common_det/cuda
|
${CMAKE_CURRENT_SOURCE_DIR}/algorithm/common_det/cuda
|
||||||
${CMAKE_CURRENT_SOURCE_DIR}/algorithm/landing_det/cuda
|
${CMAKE_CURRENT_SOURCE_DIR}/algorithm/landing_det/cuda
|
||||||
${CMAKE_CURRENT_SOURCE_DIR}/algorithm/tracking/ocv470
|
${CMAKE_CURRENT_SOURCE_DIR}/algorithm/sot/ocv470
|
||||||
${CMAKE_CURRENT_SOURCE_DIR}/algorithm/color_line
|
${CMAKE_CURRENT_SOURCE_DIR}/algorithm/color_line
|
||||||
${CMAKE_CURRENT_SOURCE_DIR}/video_io
|
${CMAKE_CURRENT_SOURCE_DIR}/video_io
|
||||||
${CMAKE_CURRENT_SOURCE_DIR}/algorithm/ellipse_det
|
${CMAKE_CURRENT_SOURCE_DIR}/algorithm/ellipse_det
|
||||||
|
@ -111,7 +111,8 @@ set(
|
||||||
include/sv_algorithm_base.h
|
include/sv_algorithm_base.h
|
||||||
include/sv_common_det.h
|
include/sv_common_det.h
|
||||||
include/sv_landing_det.h
|
include/sv_landing_det.h
|
||||||
include/sv_tracking.h
|
include/sv_sot.h
|
||||||
|
include/sv_mot.h
|
||||||
include/sv_color_line.h
|
include/sv_color_line.h
|
||||||
include/sv_video_input.h
|
include/sv_video_input.h
|
||||||
include/sv_video_output.h
|
include/sv_video_output.h
|
||||||
|
@ -152,11 +153,12 @@ set(spirecv_SRCS
|
||||||
algorithm/ellipse_det/ellipse_detector.cpp
|
algorithm/ellipse_det/ellipse_detector.cpp
|
||||||
algorithm/common_det/sv_common_det.cpp
|
algorithm/common_det/sv_common_det.cpp
|
||||||
algorithm/landing_det/sv_landing_det.cpp
|
algorithm/landing_det/sv_landing_det.cpp
|
||||||
algorithm/tracking/sv_tracking.cpp
|
algorithm/sot/sv_sot.cpp
|
||||||
|
algorithm/mot/sv_mot.cpp
|
||||||
algorithm/color_line/sv_color_line.cpp
|
algorithm/color_line/sv_color_line.cpp
|
||||||
)
|
)
|
||||||
|
|
||||||
file(GLOB ALG_SRC_FILES ${CMAKE_CURRENT_SOURCE_DIR}/algorithm/tracking/ocv470/*.cpp)
|
file(GLOB ALG_SRC_FILES ${CMAKE_CURRENT_SOURCE_DIR}/algorithm/sot/ocv470/*.cpp)
|
||||||
list(APPEND spirecv_SRCS ${ALG_SRC_FILES})
|
list(APPEND spirecv_SRCS ${ALG_SRC_FILES})
|
||||||
file(GLOB ALG_SRC_FILES ${CMAKE_CURRENT_SOURCE_DIR}/algorithm/color_line/*.cpp)
|
file(GLOB ALG_SRC_FILES ${CMAKE_CURRENT_SOURCE_DIR}/algorithm/color_line/*.cpp)
|
||||||
list(APPEND spirecv_SRCS ${ALG_SRC_FILES})
|
list(APPEND spirecv_SRCS ${ALG_SRC_FILES})
|
||||||
|
@ -249,6 +251,8 @@ add_executable(LandingMarkerDetection samples/demo/landing_marker_detection.cpp)
|
||||||
target_link_libraries(LandingMarkerDetection sv_world)
|
target_link_libraries(LandingMarkerDetection sv_world)
|
||||||
add_executable(SingleObjectTracking samples/demo/single_object_tracking.cpp)
|
add_executable(SingleObjectTracking samples/demo/single_object_tracking.cpp)
|
||||||
target_link_libraries(SingleObjectTracking sv_world)
|
target_link_libraries(SingleObjectTracking sv_world)
|
||||||
|
add_executable(MultipleObjectTracking samples/demo/multiple_object_tracking.cpp)
|
||||||
|
target_link_libraries(MultipleObjectTracking sv_world)
|
||||||
add_executable(ColorLineDetection samples/demo/color_line_detect.cpp)
|
add_executable(ColorLineDetection samples/demo/color_line_detect.cpp)
|
||||||
target_link_libraries(ColorLineDetection sv_world)
|
target_link_libraries(ColorLineDetection sv_world)
|
||||||
add_executable(UdpDetectionInfoReceiver samples/demo/udp_detection_info_receiver.cpp)
|
add_executable(UdpDetectionInfoReceiver samples/demo/udp_detection_info_receiver.cpp)
|
||||||
|
|
|
@ -0,0 +1,98 @@
|
||||||
|
#include "sv_mot.h"
|
||||||
|
#include <cmath>
|
||||||
|
#include <fstream>
|
||||||
|
#include "gason.h"
|
||||||
|
#include "sv_util.h"
|
||||||
|
|
||||||
|
|
||||||
|
namespace sv {
|
||||||
|
|
||||||
|
|
||||||
|
MultipleObjectTracker::MultipleObjectTracker()
|
||||||
|
{
|
||||||
|
this->_params_loaded = false;
|
||||||
|
}
|
||||||
|
MultipleObjectTracker::~MultipleObjectTracker()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
void MultipleObjectTracker::track(cv::Mat img_, TargetsInFrame& tgts_)
|
||||||
|
{
|
||||||
|
if (!this->_params_loaded)
|
||||||
|
{
|
||||||
|
this->_load();
|
||||||
|
this->_params_loaded = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void MultipleObjectTracker::init()
|
||||||
|
{
|
||||||
|
if (!this->_params_loaded)
|
||||||
|
{
|
||||||
|
this->_load();
|
||||||
|
this->_params_loaded = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void MultipleObjectTracker::_load()
|
||||||
|
{
|
||||||
|
JsonValue all_value;
|
||||||
|
JsonAllocator allocator;
|
||||||
|
_load_all_json(this->alg_params_fn, all_value, allocator);
|
||||||
|
|
||||||
|
JsonValue tracker_params_value;
|
||||||
|
_parser_algorithm_params("MultipleObjectTracker", all_value, tracker_params_value);
|
||||||
|
|
||||||
|
for (auto i : tracker_params_value) {
|
||||||
|
if ("algorithm" == std::string(i->key)) {
|
||||||
|
this->_algorithm = i->value.toString();
|
||||||
|
std::cout << "algorithm: " << this->_algorithm << std::endl;
|
||||||
|
}
|
||||||
|
else if ("with_reid" == std::string(i->key)) {
|
||||||
|
if (i->value.getTag() == JSON_TRUE)
|
||||||
|
this->_with_reid = true;
|
||||||
|
else
|
||||||
|
this->_with_reid = false;
|
||||||
|
|
||||||
|
std::cout << "with_reid: " << this->_with_reid << std::endl;
|
||||||
|
}
|
||||||
|
else if ("reid_input_size" == std::string(i->key) && i->value.getTag() == JSON_ARRAY) {
|
||||||
|
int jcnt = 0;
|
||||||
|
for (auto j : i->value) {
|
||||||
|
if (jcnt == 0) {
|
||||||
|
this->_reid_input_w = j->value.toNumber();
|
||||||
|
}
|
||||||
|
if (jcnt == 1) {
|
||||||
|
this->_reid_input_h = j->value.toNumber();
|
||||||
|
}
|
||||||
|
jcnt += 1;
|
||||||
|
}
|
||||||
|
std::cout << "reid_input_w: " << this->_reid_input_w << std::endl;
|
||||||
|
std::cout << "reid_input_h: " << this->_reid_input_h << std::endl;
|
||||||
|
}
|
||||||
|
else if ("reid_num_samples" == std::string(i->key)) {
|
||||||
|
this->_reid_num_samples = i->value.toNumber();
|
||||||
|
std::cout << "reid_num_samples: " << this->_reid_num_samples << std::endl;
|
||||||
|
}
|
||||||
|
else if ("reid_match_thres" == std::string(i->key)) {
|
||||||
|
this->_reid_match_thres = i->value.toNumber();
|
||||||
|
std::cout << "reid_match_thres: " << this->_reid_match_thres << std::endl;
|
||||||
|
}
|
||||||
|
else if ("iou_thres" == std::string(i->key)) {
|
||||||
|
this->_iou_thres = i->value.toNumber();
|
||||||
|
std::cout << "iou_thres: " << this->_iou_thres << std::endl;
|
||||||
|
}
|
||||||
|
else if ("max_age" == std::string(i->key)) {
|
||||||
|
this->_max_age = i->value.toNumber();
|
||||||
|
std::cout << "max_age: " << this->_max_age << std::endl;
|
||||||
|
}
|
||||||
|
else if ("min_hits" == std::string(i->key)) {
|
||||||
|
this->_min_hits = i->value.toNumber();
|
||||||
|
std::cout << "min_hits: " << this->_min_hits << std::endl;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
#include "tracking_ocv470_impl.h"
|
#include "sot_ocv470_impl.h"
|
||||||
#include <cmath>
|
#include <cmath>
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
#include "sv_tracking.h"
|
#include "sv_sot.h"
|
||||||
#include <cmath>
|
#include <cmath>
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
#include "tracking_ocv470_impl.h"
|
#include "sot_ocv470_impl.h"
|
||||||
|
|
||||||
|
|
||||||
namespace sv {
|
namespace sv {
|
|
@ -0,0 +1,42 @@
|
||||||
|
#ifndef __SV_MOT__
|
||||||
|
#define __SV_MOT__
|
||||||
|
|
||||||
|
#include "sv_core.h"
|
||||||
|
#include <opencv2/opencv.hpp>
|
||||||
|
#include <opencv2/aruco.hpp>
|
||||||
|
#include <opencv2/tracking.hpp>
|
||||||
|
#include <string>
|
||||||
|
#include <chrono>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
namespace sv {
|
||||||
|
|
||||||
|
|
||||||
|
class MultipleObjectTracker : public CameraAlgorithm
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
MultipleObjectTracker();
|
||||||
|
~MultipleObjectTracker();
|
||||||
|
|
||||||
|
void init();
|
||||||
|
void track(cv::Mat img_, TargetsInFrame& tgts_);
|
||||||
|
|
||||||
|
private:
|
||||||
|
void _load();
|
||||||
|
bool _params_loaded;
|
||||||
|
|
||||||
|
std::string _algorithm;
|
||||||
|
bool _with_reid;
|
||||||
|
int _reid_input_h;
|
||||||
|
int _reid_input_w;
|
||||||
|
int _reid_num_samples;
|
||||||
|
double _reid_match_thres;
|
||||||
|
double _iou_thres;
|
||||||
|
int _max_age;
|
||||||
|
int _min_hits;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
#endif
|
|
@ -4,7 +4,8 @@
|
||||||
#include "sv_core.h"
|
#include "sv_core.h"
|
||||||
#include "sv_common_det.h"
|
#include "sv_common_det.h"
|
||||||
#include "sv_landing_det.h"
|
#include "sv_landing_det.h"
|
||||||
#include "sv_tracking.h"
|
#include "sv_sot.h"
|
||||||
|
#include "sv_mot.h"
|
||||||
#include "sv_color_line.h"
|
#include "sv_color_line.h"
|
||||||
#include "sv_video_input.h"
|
#include "sv_video_input.h"
|
||||||
#include "sv_video_output.h"
|
#include "sv_video_output.h"
|
||||||
|
|
|
@ -116,6 +116,16 @@
|
||||||
"backend": 0,
|
"backend": 0,
|
||||||
"target": 0
|
"target": 0
|
||||||
},
|
},
|
||||||
|
"MultipleObjectTracker": {
|
||||||
|
"algorithm": "sort",
|
||||||
|
"with_reid": false,
|
||||||
|
"reid_input_size": [128, 128],
|
||||||
|
"reid_num_samples": 10,
|
||||||
|
"reid_match_thres": 2.0,
|
||||||
|
"iou_thres": 0.5,
|
||||||
|
"max_age": 10,
|
||||||
|
"min_hits": 3
|
||||||
|
},
|
||||||
"LandingMarkerDetector": {
|
"LandingMarkerDetector": {
|
||||||
"labels": ["h"],
|
"labels": ["h"],
|
||||||
"maxCandidates": 5
|
"maxCandidates": 5
|
||||||
|
|
|
@ -116,6 +116,16 @@
|
||||||
"backend": 0,
|
"backend": 0,
|
||||||
"target": 0
|
"target": 0
|
||||||
},
|
},
|
||||||
|
"MultipleObjectTracker": {
|
||||||
|
"algorithm": "sort",
|
||||||
|
"with_reid": false,
|
||||||
|
"reid_input_size": [128, 128],
|
||||||
|
"reid_num_samples": 10,
|
||||||
|
"reid_match_thres": 2.0,
|
||||||
|
"iou_thres": 0.5,
|
||||||
|
"max_age": 10,
|
||||||
|
"min_hits": 3
|
||||||
|
},
|
||||||
"LandingMarkerDetector": {
|
"LandingMarkerDetector": {
|
||||||
"labels": ["x", "h"],
|
"labels": ["x", "h"],
|
||||||
"maxCandidates": 5
|
"maxCandidates": 5
|
||||||
|
|
|
@ -116,6 +116,16 @@
|
||||||
"backend": 0,
|
"backend": 0,
|
||||||
"target": 0
|
"target": 0
|
||||||
},
|
},
|
||||||
|
"MultipleObjectTracker": {
|
||||||
|
"algorithm": "sort",
|
||||||
|
"with_reid": false,
|
||||||
|
"reid_input_size": [128, 128],
|
||||||
|
"reid_num_samples": 10,
|
||||||
|
"reid_match_thres": 2.0,
|
||||||
|
"iou_thres": 0.5,
|
||||||
|
"max_age": 10,
|
||||||
|
"min_hits": 3
|
||||||
|
},
|
||||||
"LandingMarkerDetector": {
|
"LandingMarkerDetector": {
|
||||||
"labels": ["x", "h"],
|
"labels": ["x", "h"],
|
||||||
"maxCandidates": 5
|
"maxCandidates": 5
|
||||||
|
|
|
@ -116,6 +116,16 @@
|
||||||
"backend": 0,
|
"backend": 0,
|
||||||
"target": 0
|
"target": 0
|
||||||
},
|
},
|
||||||
|
"MultipleObjectTracker": {
|
||||||
|
"algorithm": "sort",
|
||||||
|
"with_reid": false,
|
||||||
|
"reid_input_size": [128, 128],
|
||||||
|
"reid_num_samples": 10,
|
||||||
|
"reid_match_thres": 2.0,
|
||||||
|
"iou_thres": 0.5,
|
||||||
|
"max_age": 10,
|
||||||
|
"min_hits": 3
|
||||||
|
},
|
||||||
"LandingMarkerDetector": {
|
"LandingMarkerDetector": {
|
||||||
"labels": ["x", "h"],
|
"labels": ["x", "h"],
|
||||||
"maxCandidates": 5
|
"maxCandidates": 5
|
||||||
|
|
|
@ -116,6 +116,16 @@
|
||||||
"backend": 0,
|
"backend": 0,
|
||||||
"target": 0
|
"target": 0
|
||||||
},
|
},
|
||||||
|
"MultipleObjectTracker": {
|
||||||
|
"algorithm": "sort",
|
||||||
|
"with_reid": false,
|
||||||
|
"reid_input_size": [128, 128],
|
||||||
|
"reid_num_samples": 10,
|
||||||
|
"reid_match_thres": 2.0,
|
||||||
|
"iou_thres": 0.5,
|
||||||
|
"max_age": 10,
|
||||||
|
"min_hits": 3
|
||||||
|
},
|
||||||
"LandingMarkerDetector": {
|
"LandingMarkerDetector": {
|
||||||
"labels": ["x", "h"],
|
"labels": ["x", "h"],
|
||||||
"maxCandidates": 5
|
"maxCandidates": 5
|
||||||
|
|
|
@ -116,6 +116,16 @@
|
||||||
"backend": 0,
|
"backend": 0,
|
||||||
"target": 0
|
"target": 0
|
||||||
},
|
},
|
||||||
|
"MultipleObjectTracker": {
|
||||||
|
"algorithm": "sort",
|
||||||
|
"with_reid": false,
|
||||||
|
"reid_input_size": [128, 128],
|
||||||
|
"reid_num_samples": 10,
|
||||||
|
"reid_match_thres": 2.0,
|
||||||
|
"iou_thres": 0.5,
|
||||||
|
"max_age": 10,
|
||||||
|
"min_hits": 3
|
||||||
|
},
|
||||||
"LandingMarkerDetector": {
|
"LandingMarkerDetector": {
|
||||||
"labels": ["x", "h"],
|
"labels": ["x", "h"],
|
||||||
"maxCandidates": 5
|
"maxCandidates": 5
|
||||||
|
|
|
@ -116,6 +116,16 @@
|
||||||
"backend": 0,
|
"backend": 0,
|
||||||
"target": 0
|
"target": 0
|
||||||
},
|
},
|
||||||
|
"MultipleObjectTracker": {
|
||||||
|
"algorithm": "sort",
|
||||||
|
"with_reid": false,
|
||||||
|
"reid_input_size": [128, 128],
|
||||||
|
"reid_num_samples": 10,
|
||||||
|
"reid_match_thres": 2.0,
|
||||||
|
"iou_thres": 0.5,
|
||||||
|
"max_age": 10,
|
||||||
|
"min_hits": 3
|
||||||
|
},
|
||||||
"LandingMarkerDetector": {
|
"LandingMarkerDetector": {
|
||||||
"labels": ["x", "h"],
|
"labels": ["x", "h"],
|
||||||
"maxCandidates": 5
|
"maxCandidates": 5
|
||||||
|
|
|
@ -116,6 +116,16 @@
|
||||||
"backend": 0,
|
"backend": 0,
|
||||||
"target": 0
|
"target": 0
|
||||||
},
|
},
|
||||||
|
"MultipleObjectTracker": {
|
||||||
|
"algorithm": "sort",
|
||||||
|
"with_reid": false,
|
||||||
|
"reid_input_size": [128, 128],
|
||||||
|
"reid_num_samples": 10,
|
||||||
|
"reid_match_thres": 2.0,
|
||||||
|
"iou_thres": 0.5,
|
||||||
|
"max_age": 10,
|
||||||
|
"min_hits": 3
|
||||||
|
},
|
||||||
"LandingMarkerDetector": {
|
"LandingMarkerDetector": {
|
||||||
"labels": ["x", "h"],
|
"labels": ["x", "h"],
|
||||||
"maxCandidates": 5
|
"maxCandidates": 5
|
||||||
|
|
|
@ -116,6 +116,16 @@
|
||||||
"backend": 0,
|
"backend": 0,
|
||||||
"target": 0
|
"target": 0
|
||||||
},
|
},
|
||||||
|
"MultipleObjectTracker": {
|
||||||
|
"algorithm": "sort",
|
||||||
|
"with_reid": false,
|
||||||
|
"reid_input_size": [128, 128],
|
||||||
|
"reid_num_samples": 10,
|
||||||
|
"reid_match_thres": 2.0,
|
||||||
|
"iou_thres": 0.5,
|
||||||
|
"max_age": 10,
|
||||||
|
"min_hits": 3
|
||||||
|
},
|
||||||
"LandingMarkerDetector": {
|
"LandingMarkerDetector": {
|
||||||
"labels": ["x", "h"],
|
"labels": ["x", "h"],
|
||||||
"maxCandidates": 5
|
"maxCandidates": 5
|
||||||
|
|
|
@ -116,6 +116,16 @@
|
||||||
"backend": 0,
|
"backend": 0,
|
||||||
"target": 0
|
"target": 0
|
||||||
},
|
},
|
||||||
|
"MultipleObjectTracker": {
|
||||||
|
"algorithm": "sort",
|
||||||
|
"with_reid": false,
|
||||||
|
"reid_input_size": [128, 128],
|
||||||
|
"reid_num_samples": 10,
|
||||||
|
"reid_match_thres": 2.0,
|
||||||
|
"iou_thres": 0.5,
|
||||||
|
"max_age": 10,
|
||||||
|
"min_hits": 3
|
||||||
|
},
|
||||||
"LandingMarkerDetector": {
|
"LandingMarkerDetector": {
|
||||||
"labels": ["x", "h"],
|
"labels": ["x", "h"],
|
||||||
"maxCandidates": 5
|
"maxCandidates": 5
|
||||||
|
|
|
@ -0,0 +1,41 @@
|
||||||
|
#include <iostream>
|
||||||
|
#include <string>
|
||||||
|
// 包含SpireCV SDK头文件
|
||||||
|
#include <sv_world.h>
|
||||||
|
|
||||||
|
using namespace std;
|
||||||
|
|
||||||
|
int main(int argc, char *argv[]) {
|
||||||
|
// 实例化
|
||||||
|
sv::MultipleObjectTracker mot;
|
||||||
|
// 手动导入相机参数,如果使用Amov的G1等吊舱或相机,则可以忽略该步骤,将自动下载相机参数文件
|
||||||
|
mot.loadCameraParams(sv::get_home() + "/SpireCV/calib_webcam_640x480.yaml");
|
||||||
|
|
||||||
|
// 打开摄像头
|
||||||
|
sv::Camera cap;
|
||||||
|
// cap.setWH(640, 480);
|
||||||
|
// cap.setFps(30);
|
||||||
|
cap.open(sv::CameraType::WEBCAM, 0); // CameraID 0
|
||||||
|
// 实例化OpenCV的Mat类,用于内存单帧图像
|
||||||
|
cv::Mat img;
|
||||||
|
int frame_id = 0;
|
||||||
|
while (1)
|
||||||
|
{
|
||||||
|
// 实例化SpireCV的 单帧检测结果 接口类 TargetsInFrame
|
||||||
|
sv::TargetsInFrame tgts(frame_id++);
|
||||||
|
// 读取一帧图像到img
|
||||||
|
cap.read(img);
|
||||||
|
cv::resize(img, img, cv::Size(mot.image_width, mot.image_height));
|
||||||
|
|
||||||
|
// 执行通用目标检测
|
||||||
|
mot.track(img, tgts);
|
||||||
|
// 可视化检测结果,叠加到img上
|
||||||
|
sv::drawTargetsInFrame(img, tgts);
|
||||||
|
|
||||||
|
// 显示检测结果img
|
||||||
|
cv::imshow("img", img);
|
||||||
|
cv::waitKey(10);
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
Loading…
Reference in New Issue