Compare commits

...

2 Commits
master ... p450

Author SHA1 Message Date
Daniel fb2a60e3ca update. 2024-01-03 17:45:48 +08:00
Daniel ddb157b374 add a new drawTargetsInFrame() for single aruco tracking. 2023-12-28 12:20:14 +08:00
68 changed files with 1487 additions and 1501 deletions

View File

@ -103,7 +103,7 @@ void infer_seg(IExecutionContext& context, cudaStream_t& stream, void **buffers,
CUDA_CHECK(cudaMemcpyAsync(output2, buffers[2], batchSize * kOutputSize2 * sizeof(float), cudaMemcpyDeviceToHost, stream)); CUDA_CHECK(cudaMemcpyAsync(output2, buffers[2], batchSize * kOutputSize2 * sizeof(float), cudaMemcpyDeviceToHost, stream));
cudaStreamSynchronize(stream); cudaStreamSynchronize(stream);
} }
void CommonObjectDetectorCUDAImpl::_prepare_buffers(int input_h, int input_w, int batchsize) { void CommonObjectDetectorCUDAImpl::_prepare_buffers(int input_h, int input_w) {
assert(this->_engine->getNbBindings() == 2); assert(this->_engine->getNbBindings() == 2);
// In order to bind the buffers, we need to know the names of the input and output tensors. // In order to bind the buffers, we need to know the names of the input and output tensors.
// Note that indices are guaranteed to be less than IEngine::getNbBindings() // Note that indices are guaranteed to be less than IEngine::getNbBindings()
@ -112,12 +112,12 @@ void CommonObjectDetectorCUDAImpl::_prepare_buffers(int input_h, int input_w, in
assert(inputIndex == 0); assert(inputIndex == 0);
assert(outputIndex == 1); assert(outputIndex == 1);
// Create GPU buffers on device // Create GPU buffers on device
CUDA_CHECK(cudaMalloc((void**)&(this->_gpu_buffers[0]), batchsize * 3 * input_h * input_w * sizeof(float))); CUDA_CHECK(cudaMalloc((void**)&(this->_gpu_buffers[0]), kBatchSize * 3 * input_h * input_w * sizeof(float)));
CUDA_CHECK(cudaMalloc((void**)&(this->_gpu_buffers[1]), batchsize * kOutputSize * sizeof(float))); CUDA_CHECK(cudaMalloc((void**)&(this->_gpu_buffers[1]), kBatchSize * kOutputSize * sizeof(float)));
this->_cpu_output_buffer = new float[batchsize * kOutputSize]; this->_cpu_output_buffer = new float[kBatchSize * kOutputSize];
} }
void CommonObjectDetectorCUDAImpl::_prepare_buffers_seg(int input_h, int input_w, int batchsize) { void CommonObjectDetectorCUDAImpl::_prepare_buffers_seg(int input_h, int input_w) {
assert(this->_engine->getNbBindings() == 3); assert(this->_engine->getNbBindings() == 3);
// In order to bind the buffers, we need to know the names of the input and output tensors. // In order to bind the buffers, we need to know the names of the input and output tensors.
// Note that indices are guaranteed to be less than IEngine::getNbBindings() // Note that indices are guaranteed to be less than IEngine::getNbBindings()
@ -129,13 +129,13 @@ void CommonObjectDetectorCUDAImpl::_prepare_buffers_seg(int input_h, int input_w
assert(outputIndex2 == 2); assert(outputIndex2 == 2);
// Create GPU buffers on device // Create GPU buffers on device
CUDA_CHECK(cudaMalloc((void**)&(this->_gpu_buffers[0]), batchsize * 3 * input_h * input_w * sizeof(float))); CUDA_CHECK(cudaMalloc((void**)&(this->_gpu_buffers[0]), kBatchSize * 3 * input_h * input_w * sizeof(float)));
CUDA_CHECK(cudaMalloc((void**)&(this->_gpu_buffers[1]), batchsize * kOutputSize1 * sizeof(float))); CUDA_CHECK(cudaMalloc((void**)&(this->_gpu_buffers[1]), kBatchSize * kOutputSize1 * sizeof(float)));
CUDA_CHECK(cudaMalloc((void**)&(this->_gpu_buffers[2]), batchsize * kOutputSize2 * sizeof(float))); CUDA_CHECK(cudaMalloc((void**)&(this->_gpu_buffers[2]), kBatchSize * kOutputSize2 * sizeof(float)));
// Alloc CPU buffers // Alloc CPU buffers
this->_cpu_output_buffer1 = new float[batchsize * kOutputSize1]; this->_cpu_output_buffer1 = new float[kBatchSize * kOutputSize1];
this->_cpu_output_buffer2 = new float[batchsize * kOutputSize2]; this->_cpu_output_buffer2 = new float[kBatchSize * kOutputSize2];
} }
void deserialize_engine(std::string& engine_name, IRuntime** runtime, ICudaEngine** engine, IExecutionContext** context) { void deserialize_engine(std::string& engine_name, IRuntime** runtime, ICudaEngine** engine, IExecutionContext** context) {
std::ifstream file(engine_name, std::ios::binary); std::ifstream file(engine_name, std::ios::binary);
@ -172,8 +172,7 @@ void CommonObjectDetectorCUDAImpl::cudaDetect(
std::vector<float>& boxes_h_, std::vector<float>& boxes_h_,
std::vector<int>& boxes_label_, std::vector<int>& boxes_label_,
std::vector<float>& boxes_score_, std::vector<float>& boxes_score_,
std::vector<cv::Mat>& boxes_seg_, std::vector<cv::Mat>& boxes_seg_
bool input_4k_
) )
{ {
#ifdef WITH_CUDA #ifdef WITH_CUDA
@ -184,51 +183,9 @@ void CommonObjectDetectorCUDAImpl::cudaDetect(
double thrs_nms = base_->getThrsNms(); double thrs_nms = base_->getThrsNms();
std::vector<cv::Mat> img_batch; std::vector<cv::Mat> img_batch;
if (input_4k_)
{
if (img_.cols == 3840 && img_.rows == 2160)
{
cv::Mat patch1, patch2, patch3, patch4, patch5, patch6;
img_.colRange(200, 1480).rowRange(0, 1280).copyTo(patch1);
img_.colRange(1280, 2560).rowRange(0, 1280).copyTo(patch2);
img_.colRange(2360, 3640).rowRange(0, 1280).copyTo(patch3);
img_.colRange(200, 1480).rowRange(880, 2160).copyTo(patch4);
img_.colRange(1280, 2560).rowRange(880, 2160).copyTo(patch5);
img_.colRange(2360, 3640).rowRange(880, 2160).copyTo(patch6);
img_batch.push_back(patch1);
img_batch.push_back(patch2);
img_batch.push_back(patch3);
img_batch.push_back(patch4);
img_batch.push_back(patch5);
img_batch.push_back(patch6);
}
else
{
throw std::runtime_error("SpireCV (106) Input image is NOT 4K (3840 x 2160)!");
}
if (with_segmentation)
{
throw std::runtime_error("SpireCV (106) Resolution 4K DO NOT Support Segmentation!");
}
}
else
{
img_batch.push_back(img_); img_batch.push_back(img_);
}
if (input_4k_)
{
// Preprocess
cuda_batch_preprocess(img_batch, this->_gpu_buffers[0], 1280, 1280, this->_stream);
}
else
{
// Preprocess // Preprocess
cuda_batch_preprocess(img_batch, this->_gpu_buffers[0], input_w, input_h, this->_stream); cuda_batch_preprocess(img_batch, this->_gpu_buffers[0], input_w, input_h, this->_stream);
}
// Run inference // Run inference
if (with_segmentation) if (with_segmentation)
@ -236,16 +193,9 @@ void CommonObjectDetectorCUDAImpl::cudaDetect(
infer_seg(*this->_context, this->_stream, (void**)this->_gpu_buffers, this->_cpu_output_buffer1, this->_cpu_output_buffer2, kBatchSize); infer_seg(*this->_context, this->_stream, (void**)this->_gpu_buffers, this->_cpu_output_buffer1, this->_cpu_output_buffer2, kBatchSize);
} }
else else
{
if (input_4k_)
{
infer(*this->_context, this->_stream, (void**)this->_gpu_buffers, this->_cpu_output_buffer, 6);
}
else
{ {
infer(*this->_context, this->_stream, (void**)this->_gpu_buffers, this->_cpu_output_buffer, kBatchSize); infer(*this->_context, this->_stream, (void**)this->_gpu_buffers, this->_cpu_output_buffer, kBatchSize);
} }
}
// NMS // NMS
std::vector<std::vector<Detection>> res_batch; std::vector<std::vector<Detection>> res_batch;
@ -258,63 +208,6 @@ void CommonObjectDetectorCUDAImpl::cudaDetect(
batch_nms(res_batch, this->_cpu_output_buffer, img_batch.size(), kOutputSize, thrs_conf, thrs_nms); batch_nms(res_batch, this->_cpu_output_buffer, img_batch.size(), kOutputSize, thrs_conf, thrs_nms);
} }
if (input_4k_)
{
for (size_t k = 0; k < res_batch.size(); k++)
{
std::vector<Detection> res = res_batch[k];
for (size_t j = 0; j < res.size(); j++)
{
cv::Rect r = get_rect(img_batch[k], res[j].bbox, 1280, 1280);
if (r.x < 0) r.x = 0;
if (r.y < 0) r.y = 0;
if (r.x + r.width >= 1280) r.width = 1280 - r.x - 1;
if (r.y + r.height >= 1280) r.height = 1280 - r.y - 1;
if (r.width > 3 && r.height > 3)
{
if (0 == k)
{
boxes_x_.push_back(r.x + 200);
boxes_y_.push_back(r.y);
}
else if (1 == k)
{
boxes_x_.push_back(r.x + 1280);
boxes_y_.push_back(r.y);
}
else if (2 == k)
{
boxes_x_.push_back(r.x + 2360);
boxes_y_.push_back(r.y);
}
else if (3 == k)
{
boxes_x_.push_back(r.x + 200);
boxes_y_.push_back(r.y + 880);
}
else if (4 == k)
{
boxes_x_.push_back(r.x + 1280);
boxes_y_.push_back(r.y + 880);
}
else if (5 == k)
{
boxes_x_.push_back(r.x + 2360);
boxes_y_.push_back(r.y + 880);
}
boxes_w_.push_back(r.width);
boxes_h_.push_back(r.height);
boxes_label_.push_back((int)res[j].class_id);
boxes_score_.push_back(res[j].conf);
}
}
}
}
else
{
std::vector<Detection> res = res_batch[0]; std::vector<Detection> res = res_batch[0];
std::vector<cv::Mat> masks; std::vector<cv::Mat> masks;
if (with_segmentation) if (with_segmentation)
@ -322,8 +215,9 @@ void CommonObjectDetectorCUDAImpl::cudaDetect(
masks = process_mask(&(this->_cpu_output_buffer2[0]), kOutputSize2, res, input_h, input_w); masks = process_mask(&(this->_cpu_output_buffer2[0]), kOutputSize2, res, input_h, input_w);
} }
for (size_t j = 0; j < res.size(); j++)
{
for (size_t j = 0; j < res.size(); j++) {
cv::Rect r = get_rect(img_, res[j].bbox, input_h, input_w); cv::Rect r = get_rect(img_, res[j].bbox, input_h, input_w);
if (r.x < 0) r.x = 0; if (r.x < 0) r.x = 0;
if (r.y < 0) r.y = 0; if (r.y < 0) r.y = 0;
@ -349,11 +243,10 @@ void CommonObjectDetectorCUDAImpl::cudaDetect(
} }
} }
}
#endif #endif
} }
bool CommonObjectDetectorCUDAImpl::cudaSetup(CommonObjectDetectorBase* base_, bool input_4k_) bool CommonObjectDetectorCUDAImpl::cudaSetup(CommonObjectDetectorBase* base_)
{ {
#ifdef WITH_CUDA #ifdef WITH_CUDA
std::string dataset = base_->getDataset(); std::string dataset = base_->getDataset();
@ -380,11 +273,6 @@ bool CommonObjectDetectorCUDAImpl::cudaSetup(CommonObjectDetectorBase* base_, bo
throw std::runtime_error("SpireCV (104) Error loading the CommonObject TensorRT model (File Not Exist)"); throw std::runtime_error("SpireCV (104) Error loading the CommonObject TensorRT model (File Not Exist)");
} }
if (input_4k_ && with_segmentation)
{
throw std::runtime_error("SpireCV (106) Resolution 4K DO NOT Support Segmentation!");
}
deserialize_engine(engine_fn, &this->_runtime, &this->_engine, &this->_context); deserialize_engine(engine_fn, &this->_runtime, &this->_engine, &this->_context);
CUDA_CHECK(cudaStreamCreate(&this->_stream)); CUDA_CHECK(cudaStreamCreate(&this->_stream));
@ -394,20 +282,12 @@ bool CommonObjectDetectorCUDAImpl::cudaSetup(CommonObjectDetectorBase* base_, bo
if (with_segmentation) if (with_segmentation)
{ {
// Prepare cpu and gpu buffers // Prepare cpu and gpu buffers
this->_prepare_buffers_seg(input_h, input_w, 1); this->_prepare_buffers_seg(input_h, input_w);
}
else
{
if (input_4k_)
{
// Prepare cpu and gpu buffers
this->_prepare_buffers(input_h, input_w, 6);
} }
else else
{ {
// Prepare cpu and gpu buffers // Prepare cpu and gpu buffers
this->_prepare_buffers(input_h, input_w, 1); this->_prepare_buffers(input_h, input_w);
}
} }
return true; return true;
#endif #endif

View File

@ -26,7 +26,7 @@ public:
CommonObjectDetectorCUDAImpl(); CommonObjectDetectorCUDAImpl();
~CommonObjectDetectorCUDAImpl(); ~CommonObjectDetectorCUDAImpl();
bool cudaSetup(CommonObjectDetectorBase* base_, bool input_4k_); bool cudaSetup(CommonObjectDetectorBase* base_);
void cudaDetect( void cudaDetect(
CommonObjectDetectorBase* base_, CommonObjectDetectorBase* base_,
cv::Mat img_, cv::Mat img_,
@ -36,13 +36,12 @@ public:
std::vector<float>& boxes_h_, std::vector<float>& boxes_h_,
std::vector<int>& boxes_label_, std::vector<int>& boxes_label_,
std::vector<float>& boxes_score_, std::vector<float>& boxes_score_,
std::vector<cv::Mat>& boxes_seg_, std::vector<cv::Mat>& boxes_seg_
bool input_4k_
); );
#ifdef WITH_CUDA #ifdef WITH_CUDA
void _prepare_buffers_seg(int input_h, int input_w, int batchsize); void _prepare_buffers_seg(int input_h, int input_w);
void _prepare_buffers(int input_h, int input_w, int batchsize); void _prepare_buffers(int input_h, int input_w);
nvinfer1::IExecutionContext* _context; nvinfer1::IExecutionContext* _context;
nvinfer1::IRuntime* _runtime; nvinfer1::IRuntime* _runtime;
nvinfer1::ICudaEngine* _engine; nvinfer1::ICudaEngine* _engine;

View File

@ -12,9 +12,8 @@
namespace sv { namespace sv {
CommonObjectDetector::CommonObjectDetector(bool input_4k) CommonObjectDetector::CommonObjectDetector()
{ {
this->_input_4k = input_4k;
#ifdef WITH_CUDA #ifdef WITH_CUDA
this->_cuda_impl = new CommonObjectDetectorCUDAImpl; this->_cuda_impl = new CommonObjectDetectorCUDAImpl;
#endif #endif
@ -26,7 +25,7 @@ CommonObjectDetector::~CommonObjectDetector()
bool CommonObjectDetector::setupImpl() bool CommonObjectDetector::setupImpl()
{ {
#ifdef WITH_CUDA #ifdef WITH_CUDA
return this->_cuda_impl->cudaSetup(this, this->_input_4k); return this->_cuda_impl->cudaSetup(this);
#endif #endif
return false; return false;
} }
@ -52,8 +51,7 @@ void CommonObjectDetector::detectImpl(
boxes_h_, boxes_h_,
boxes_label_, boxes_label_,
boxes_score_, boxes_score_,
boxes_seg_, boxes_seg_
this->_input_4k
); );
#endif #endif
} }

View File

@ -39,8 +39,8 @@ bool SingleObjectTrackerOCV470Impl::ocv470Setup(SingleObjectTrackerBase* base_)
TrackerNano::Params nano_params; TrackerNano::Params nano_params;
nano_params.backbone = samples::findFile(backbone); nano_params.backbone = samples::findFile(backbone);
nano_params.neckhead = samples::findFile(neckhead); nano_params.neckhead = samples::findFile(neckhead);
nano_params.backend = this->_backend; nano_params.backend = cv::dnn::DNN_BACKEND_CUDA;
nano_params.target = this->_target; nano_params.target = cv::dnn::DNN_TARGET_CUDA;
_nano = TrackerNano::create(nano_params); _nano = TrackerNano::create(nano_params);
} }

File diff suppressed because it is too large Load Diff

0
build_on_jetson.sh Executable file → Normal file
View File

0
build_on_x86_cuda.sh Executable file → Normal file
View File

0
build_on_x86_intel.sh Executable file → Normal file
View File

0
gimbal_ctrl/IOs/serial/README.md Executable file → Normal file
View File

0
gimbal_ctrl/IOs/serial/include/serial/impl/unix.h Executable file → Normal file
View File

0
gimbal_ctrl/IOs/serial/include/serial/impl/win.h Executable file → Normal file
View File

0
gimbal_ctrl/IOs/serial/include/serial/serial.h Executable file → Normal file
View File

0
gimbal_ctrl/IOs/serial/include/serial/v8stdint.h Executable file → Normal file
View File

View File

View File

View File

0
gimbal_ctrl/IOs/serial/src/impl/unix.cc Executable file → Normal file
View File

0
gimbal_ctrl/IOs/serial/src/impl/win.cc Executable file → Normal file
View File

0
gimbal_ctrl/IOs/serial/src/serial.cc Executable file → Normal file
View File

0
gimbal_ctrl/driver/src/AT10/AT10_gimbal_crc32.h Executable file → Normal file
View File

0
gimbal_ctrl/driver/src/AT10/AT10_gimbal_driver.cpp Executable file → Normal file
View File

0
gimbal_ctrl/driver/src/AT10/AT10_gimbal_driver.h Executable file → Normal file
View File

0
gimbal_ctrl/driver/src/AT10/AT10_gimbal_funtion.cpp Executable file → Normal file
View File

0
gimbal_ctrl/driver/src/AT10/AT10_gimbal_struct.h Executable file → Normal file
View File

0
gimbal_ctrl/driver/src/CMakeLists.txt Executable file → Normal file
View File

0
gimbal_ctrl/driver/src/FIFO/CMakeLists.txt Executable file → Normal file
View File

0
gimbal_ctrl/driver/src/FIFO/Ring_Fifo.cpp Executable file → Normal file
View File

0
gimbal_ctrl/driver/src/FIFO/Ring_Fifo.h Executable file → Normal file
View File

0
gimbal_ctrl/driver/src/G1/g1_gimbal_crc32.h Executable file → Normal file
View File

0
gimbal_ctrl/driver/src/G1/g1_gimbal_driver.cpp Executable file → Normal file
View File

0
gimbal_ctrl/driver/src/G1/g1_gimbal_driver.h Executable file → Normal file
View File

0
gimbal_ctrl/driver/src/G1/g1_gimbal_funtion.cpp Executable file → Normal file
View File

0
gimbal_ctrl/driver/src/G1/g1_gimbal_struct.h Executable file → Normal file
View File

0
gimbal_ctrl/driver/src/Q10f/Q10f_gimbal_crc32.h Executable file → Normal file
View File

0
gimbal_ctrl/driver/src/Q10f/Q10f_gimbal_driver.cpp Executable file → Normal file
View File

0
gimbal_ctrl/driver/src/Q10f/Q10f_gimbal_driver.h Executable file → Normal file
View File

0
gimbal_ctrl/driver/src/Q10f/Q10f_gimbal_funtion.cpp Executable file → Normal file
View File

0
gimbal_ctrl/driver/src/Q10f/Q10f_gimbal_struct.h Executable file → Normal file
View File

0
gimbal_ctrl/driver/src/amov_gimbal.cpp Executable file → Normal file
View File

0
gimbal_ctrl/driver/src/amov_gimbal.h Executable file → Normal file
View File

0
gimbal_ctrl/driver/src/amov_gimbal_struct.h Executable file → Normal file
View File

View File

@ -104,6 +104,10 @@ public:
std::string getAlgorithm(); std::string getAlgorithm();
int getBackend(); int getBackend();
int getTarget(); int getTarget();
double getObjectWs();
double getObjectHs();
int useWidthOrHeight();
protected: protected:
virtual bool setupImpl(); virtual bool setupImpl();
virtual void initImpl(cv::Mat img_, const cv::Rect& bounding_box_); virtual void initImpl(cv::Mat img_, const cv::Rect& bounding_box_);
@ -113,6 +117,9 @@ protected:
std::string _algorithm; std::string _algorithm;
int _backend; int _backend;
int _target; int _target;
int _use_width_or_height;
double _object_ws;
double _object_hs;
}; };
@ -170,3 +177,4 @@ protected:
} }
#endif #endif

View File

@ -16,7 +16,7 @@ class CommonObjectDetectorCUDAImpl;
class CommonObjectDetector : public CommonObjectDetectorBase class CommonObjectDetector : public CommonObjectDetectorBase
{ {
public: public:
CommonObjectDetector(bool input_4k=false); CommonObjectDetector();
~CommonObjectDetector(); ~CommonObjectDetector();
protected: protected:
bool setupImpl(); bool setupImpl();
@ -32,7 +32,6 @@ protected:
); );
CommonObjectDetectorCUDAImpl* _cuda_impl; CommonObjectDetectorCUDAImpl* _cuda_impl;
bool _input_4k;
}; };

View File

@ -12,6 +12,9 @@
#include <arpa/inet.h> #include <arpa/inet.h>
#include <netinet/in.h> // for sockaddr_in #include <netinet/in.h> // for sockaddr_in
#include <mutex>
#include <condition_variable>
#define SV_RAD2DEG 57.2957795 #define SV_RAD2DEG 57.2957795
// #define X86_PLATFORM // #define X86_PLATFORM
// #define JETSON_PLATFORM // #define JETSON_PLATFORM
@ -358,7 +361,15 @@ protected:
void _run(); void _run();
bool _is_running; bool _is_running;
// new mutex
std::mutex _frame_mutex;
std::condition_variable_any _frame_empty;
//old flag
bool _is_updated; bool _is_updated;
std::thread _tt; std::thread _tt;
cv::VideoCapture _cap; cv::VideoCapture _cap;
cv::Mat _frame; cv::Mat _frame;
@ -377,6 +388,21 @@ protected:
double _exposure; double _exposure;
}; };
void drawTargetsInFrame(
cv::Mat& img_,
const TargetsInFrame& tgts_,
int aruco_track_id,
bool with_all=true,
bool with_category=false,
bool with_tid=false,
bool with_seg=false,
bool with_box=false,
bool with_ell=false,
bool with_aruco=false,
bool with_yaw=false
);
void drawTargetsInFrame( void drawTargetsInFrame(
cv::Mat& img_, cv::Mat& img_,
@ -397,3 +423,4 @@ void list_dir(std::string dir, std::vector<std::string>& files, std::string suff
} }
#endif #endif

View File

@ -1,11 +1,11 @@
{ {
"CommonObjectDetector": { "CommonObjectDetector": {
"dataset": "COCO", "dataset": "CAR",
"inputSize": 640, "inputSize": 640,
"nmsThrs": 0.6, "nmsThrs": 0.6,
"scoreThrs": 0.4, "scoreThrs": 0.6,
"useWidthOrHeight": 1, "useWidthOrHeight": 1,
"withSegmentation": true, "withSegmentation": false,
"datasetPersonVehicle": { "datasetPersonVehicle": {
"person": [0.5, 1.8], "person": [0.5, 1.8],
"car": [4.1, 1.5], "car": [4.1, 1.5],
@ -19,6 +19,9 @@
"datasetDrone": { "datasetDrone": {
"drone": [0.4, 0.2] "drone": [0.4, 0.2]
}, },
"datasetCAR": {
"car": [0.12, 0.1]
},
"datasetCOCO": { "datasetCOCO": {
"person": [-1, -1], "person": [-1, -1],
"bicycle": [-1, -1], "bicycle": [-1, -1],
@ -114,7 +117,10 @@
"SingleObjectTracker": { "SingleObjectTracker": {
"algorithm": "nano", "algorithm": "nano",
"backend": 0, "backend": 0,
"target": 0 "target": 0,
"useWidthOrHeight": 0,
"sigleobjectW":0.126,
"sigleobjectH":-1
}, },
"MultipleObjectTracker": { "MultipleObjectTracker": {
"algorithm": "sort", "algorithm": "sort",
@ -151,7 +157,7 @@
"ArucoDetector": { "ArucoDetector": {
"dictionaryId": 10, "dictionaryId": 10,
"markerIds": [-1], "markerIds": [-1],
"markerLengths": [0.2], "markerLengths": [0.17],
"adaptiveThreshConstant": 7, "adaptiveThreshConstant": 7,
"adaptiveThreshWinSizeMax": 23, "adaptiveThreshWinSizeMax": 23,
"adaptiveThreshWinSizeMin": 3, "adaptiveThreshWinSizeMin": 3,

View File

@ -124,7 +124,9 @@ int main(int argc, char *argv[]) {
inputVideo.open(video); inputVideo.open(video);
waitTime = 0; waitTime = 0;
} else { } else {
inputVideo.open(camId); char pipe[512];
sprintf(pipe, "rtsp://192.168.2.64:554/H264?W=1280&H=720&FPS=30&BR=4000000");
inputVideo.open(pipe);
waitTime = 10; waitTime = 10;
} }

View File

@ -9,13 +9,13 @@ int main(int argc, char *argv[]) {
// 实例化Aruco检测器类 // 实例化Aruco检测器类
sv::ArucoDetector ad; sv::ArucoDetector ad;
// 手动导入相机参数如果使用Amov的G1等吊舱或相机则可以忽略该步骤将自动下载相机参数文件 // 手动导入相机参数如果使用Amov的G1等吊舱或相机则可以忽略该步骤将自动下载相机参数文件
ad.loadCameraParams(sv::get_home() + "/SpireCV/calib_webcam_640x480.yaml"); ad.loadCameraParams(sv::get_home() + "/SpireCV/calib_webcam_1280x720.yaml");
// 打开摄像头 // 打开摄像头
sv::Camera cap; sv::Camera cap;
// cap.setWH(640, 480); cap.setWH(1280, 720);
// cap.setFps(30); cap.setFps(30);
cap.open(sv::CameraType::WEBCAM, 0); // CameraID 0 cap.open(sv::CameraType::WEBCAM, 4); // CameraID 0
// 实例化OpenCV的Mat类用于内存单帧图像 // 实例化OpenCV的Mat类用于内存单帧图像
cv::Mat img; cv::Mat img;
int frame_id = 0; int frame_id = 0;

View File

@ -40,18 +40,18 @@ int main(int argc, char *argv[]) {
// 实例化 框选目标跟踪类 // 实例化 框选目标跟踪类
sv::SingleObjectTracker sot; sv::SingleObjectTracker sot;
// 手动导入相机参数如果使用Amov的G1等吊舱或相机则可以忽略该步骤将自动下载相机参数文件 // 手动导入相机参数如果使用Amov的G1等吊舱或相机则可以忽略该步骤将自动下载相机参数文件
sot.loadCameraParams(sv::get_home() + "/SpireCV/calib_webcam_640x480.yaml"); sot.loadCameraParams(sv::get_home() + "/SpireCV/calib_webcam_1280x720.yaml");
sv::CommonObjectDetector cod; sv::CommonObjectDetector cod;
cod.loadCameraParams(sv::get_home() + "/SpireCV/calib_webcam_640x480.yaml"); cod.loadCameraParams(sv::get_home() + "/SpireCV/calib_webcam_1280x720.yaml");
// 打开摄像头 // 打开摄像头
sv::Camera cap; sv::Camera cap;
// cap.setWH(640, 480); cap.setWH(1280, 720);
// cap.setFps(30); cap.setFps(30);
cap.open(sv::CameraType::WEBCAM, 0); // CameraID 0 cap.open(sv::CameraType::WEBCAM, 4); // CameraID 0
// cv::VideoCapture cap("/home/amov/SpireCV/test/tracking_1280x720.mp4"); // cv::VideoCapture cap("/home/amov/SpireCV/test/tracking_1280x720.mp4");
// 实例化OpenCV的Mat类用于内存单帧图像 // 实例化OpenCV的Mat类用于内存单帧图像
cv::Mat img; cv::Mat img;

View File

@ -9,13 +9,13 @@ int main(int argc, char *argv[]) {
// 实例化 椭圆 检测器类 // 实例化 椭圆 检测器类
sv::EllipseDetector ed; sv::EllipseDetector ed;
// 手动导入相机参数如果使用Amov的G1等吊舱或相机则可以忽略该步骤将自动下载相机参数文件 // 手动导入相机参数如果使用Amov的G1等吊舱或相机则可以忽略该步骤将自动下载相机参数文件
ed.loadCameraParams(sv::get_home() + "/SpireCV/calib_webcam_640x480.yaml"); ed.loadCameraParams(sv::get_home() + "/SpireCV/calib_webcam_1280x720.yaml");
// 打开摄像头 // 打开摄像头
sv::Camera cap; sv::Camera cap;
// cap.setWH(640, 480); cap.setWH(1280, 720);
// cap.setFps(30); cap.setFps(30);
cap.open(sv::CameraType::WEBCAM, 0); // CameraID 0 cap.open(sv::CameraType::WEBCAM, 4); // CameraID 0
// 实例化OpenCV的Mat类用于内存单帧图像 // 实例化OpenCV的Mat类用于内存单帧图像
cv::Mat img; cv::Mat img;
int frame_id = 0; int frame_id = 0;

View File

@ -66,7 +66,7 @@ int main(int argc, char *argv[])
// 设置获取画面分辨率为720P // 设置获取画面分辨率为720P
cap.setWH(1280, 720); cap.setWH(1280, 720);
// 设置视频帧率为30帧 // 设置视频帧率为30帧
cap.setFps(30); cap.setFps(60);
// 开启相机 // 开启相机
cap.open(sv::CameraType::G1); cap.open(sv::CameraType::G1);
@ -77,10 +77,10 @@ int main(int argc, char *argv[])
// 实例化 框选目标跟踪类 // 实例化 框选目标跟踪类
sv::SingleObjectTracker sot; sv::SingleObjectTracker sot;
// 手动导入相机参数如果使用Amov的G1等吊舱或相机则可以忽略该步骤将自动下载相机参数文件 // 手动导入相机参数如果使用Amov的G1等吊舱或相机则可以忽略该步骤将自动下载相机参数文件
sot.loadCameraParams(sv::get_home() + "/SpireCV/calib_webcam_640x480.yaml"); sot.loadCameraParams(sv::get_home() + "/SpireCV/calib_webcam_1280x720.yaml");
sv::CommonObjectDetector cod; sv::CommonObjectDetector cod;
cod.loadCameraParams(sv::get_home() + "/SpireCV/calib_webcam_640x480.yaml"); cod.loadCameraParams(sv::get_home() + "/SpireCV/calib_webcam_1280x720.yaml");
// 实例化OpenCV的Mat类用于内存单帧图像 // 实例化OpenCV的Mat类用于内存单帧图像
cv::Mat img; cv::Mat img;

View File

@ -3,7 +3,7 @@
// 包含SpireCV SDK头文件 // 包含SpireCV SDK头文件
#include <sv_world.h> #include <sv_world.h>
// #include "gimbal_tools.hpp" // #include "gimbal_tools.hpp"
#include <chrono>
using namespace std; using namespace std;
// 云台 // 云台
@ -43,11 +43,11 @@ int main(int argc, char *argv[])
// 定义相机 // 定义相机
sv::Camera cap; sv::Camera cap;
// 设置相机流媒体地址为 192.168.2.64 // 设置相机流媒体地址为 192.168.2.64
cap.setIp("192.168.2.64"); cap.setIp("192.168.1.64");
// 设置获取画面分辨率为720P // 设置获取画面分辨率为720P
cap.setWH(1280, 720); cap.setWH(640, 480);
// 设置视频帧率为30帧 // 设置视频帧率为30帧
cap.setFps(30); cap.setFps(120);
// 开启相机 // 开启相机
cap.open(sv::CameraType::G1); cap.open(sv::CameraType::G1);
@ -58,56 +58,63 @@ int main(int argc, char *argv[])
// 实例化 圆形降落标志 检测器类 // 实例化 圆形降落标志 检测器类
sv::LandingMarkerDetector lmd; sv::LandingMarkerDetector lmd;
// 手动导入相机参数如果使用Amov的G1等吊舱或相机则可以忽略该步骤将自动下载相机参数文件 // 手动导入相机参数如果使用Amov的G1等吊舱或相机则可以忽略该步骤将自动下载相机参数文件
lmd.loadCameraParams(sv::get_home() + "/SpireCV/calib_webcam_1280x720.yaml"); lmd.loadCameraParams(sv::get_home() + "/SpireCV/calib_webcam_640x480.yaml");
// 实例化OpenCV的Mat类用于内存单帧图像 // 实例化OpenCV的Mat类用于内存单帧图像
cv::Mat img; cv::Mat img;
int frame_id = 0; int frame_id = 0;
while (1) while (1)
{ {
auto time1 = std::chrono::duration_cast<std::chrono::nanoseconds>(std::chrono::system_clock::now().time_since_epoch()).count();
// 实例化SpireCV的 单帧检测结果 接口类 TargetsInFrame // 实例化SpireCV的 单帧检测结果 接口类 TargetsInFrame
for(uint j = 0; j < 60; j++)
{
sv::TargetsInFrame tgts(frame_id++); sv::TargetsInFrame tgts(frame_id++);
// 读取一帧图像到img // 读取一帧图像到img
cap.read(img); cap.read(img);
cv::resize(img, img, cv::Size(lmd.image_width, lmd.image_height)); //cv::resize(img, img, cv::Size(lmd.image_width, lmd.image_height));
// 执行 降落标志 检测 // 执行 降落标志 检测
lmd.detect(img, tgts); lmd.detect(img, tgts);
// 可视化检测结果叠加到img上 // 可视化检测结果叠加到img上
sv::drawTargetsInFrame(img, tgts); //sv::drawTargetsInFrame(img, tgts);
// 控制台打印 降落标志 检测结果 // 控制台打印 降落标志 检测结果
printf("Frame-[%d]\n", frame_id); //printf("Frame-[%d]\n", frame_id);
// 打印当前检测的FPS // 打印当前检测的FPS
printf(" FPS = %.2f\n", tgts.fps); printf(" FPS = %.2f\n", tgts.fps);
// 打印当前相机的视场角degree // 打印当前相机的视场角degree
printf(" FOV (fx, fy) = (%.2f, %.2f)\n", tgts.fov_x, tgts.fov_y); //printf(" FOV (fx, fy) = (%.2f, %.2f)\n", tgts.fov_x, tgts.fov_y);
for (int i = 0; i < tgts.targets.size(); i++) //for (int i = 0; i < tgts.targets.size(); i++)
{ //{
// 仅追踪 X 类型的标靶 // 仅追踪 X 类型的标靶
if (tgts.targets[i].category_id == 2) //if (tgts.targets[i].category_id == 2)
{ //{
gimbalTrack(tgts.targets[0].cx - 0.5f, tgts.targets[0].cy - 0.5f); //gimbalTrack(tgts.targets[0].cx - 0.5f, tgts.targets[0].cy - 0.5f);
} //}
printf("Frame-[%d], Marker-[%d]\n", frame_id, i); //printf("Frame-[%d], Marker-[%d]\n", frame_id, i);
// 打印每个 降落标志 的中心位置cxcy的值域为[0, 1] // 打印每个 降落标志 的中心位置cxcy的值域为[0, 1]
printf(" Marker Center (cx, cy) = (%.3f, %.3f)\n", tgts.targets[i].cx, tgts.targets[i].cy); //printf(" Marker Center (cx, cy) = (%.3f, %.3f)\n", tgts.targets[i].cx, tgts.targets[i].cy);
// 打印每个 降落标志 的外接矩形框的宽度、高度wh的值域为(0, 1] // 打印每个 降落标志 的外接矩形框的宽度、高度wh的值域为(0, 1]
printf(" Marker Size (w, h) = (%.3f, %.3f)\n", tgts.targets[i].w, tgts.targets[i].h); //printf(" Marker Size (w, h) = (%.3f, %.3f)\n", tgts.targets[i].w, tgts.targets[i].h);
// 打印每个 降落标志 的置信度 // 打印每个 降落标志 的置信度
printf(" Marker Score = %.3f\n", tgts.targets[i].score); //printf(" Marker Score = %.3f\n", tgts.targets[i].score);
// 打印每个 降落标志 的类别,字符串类型,"h"、"x"、"1"、"2"、"3"... // 打印每个 降落标志 的类别,字符串类型,"h"、"x"、"1"、"2"、"3"...
printf(" Marker Category = %s, Category ID = %d\n", tgts.targets[i].category.c_str(), tgts.targets[i].category_id); //printf(" Marker Category = %s, Category ID = %d\n", tgts.targets[i].category.c_str(), tgts.targets[i].category_id);
// 打印每个 降落标志 的视线角,跟相机视场相关 // 打印每个 降落标志 的视线角,跟相机视场相关
printf(" Marker Line-of-sight (ax, ay) = (%.3f, %.3f)\n", tgts.targets[i].los_ax, tgts.targets[i].los_ay); //printf(" Marker Line-of-sight (ax, ay) = (%.3f, %.3f)\n", tgts.targets[i].los_ax, tgts.targets[i].los_ay);
// 打印每个 降落标志 的3D位置在相机坐标系下跟降落标志实际半径、相机参数相关 // 打印每个 降落标志 的3D位置在相机坐标系下跟降落标志实际半径、相机参数相关
printf(" Marker Position = (x, y, z) = (%.3f, %.3f, %.3f)\n", tgts.targets[i].px, tgts.targets[i].py, tgts.targets[i].pz); //printf(" Marker Position = (x, y, z) = (%.3f, %.3f, %.3f)\n", tgts.targets[i].px, tgts.targets[i].py, //tgts.targets[i].pz);
} //}
// 显示检测结果img // 显示检测结果img
cv::imshow(RGB_WINDOW, img); cv::imshow(RGB_WINDOW, img);
cv::waitKey(10); cv::waitKey(1);
}
auto time2 = std::chrono::duration_cast<std::chrono::nanoseconds>(std::chrono::system_clock::now().time_since_epoch()).count();
auto Ts = time2 - time1;
std::cout << "Ts = " << Ts / (1000) << "us" << std::endl;
} }
return 0; return 0;

View File

@ -79,6 +79,7 @@ int main(int argc, char *argv[])
sv::TargetsInFrame tgts(frame_id++); sv::TargetsInFrame tgts(frame_id++);
// 读取一帧图像到img // 读取一帧图像到img
cap.read(img); cap.read(img);
continue;
// 执行Aruco二维码检测 // 执行Aruco二维码检测
ad.detect(img, tgts); ad.detect(img, tgts);

View File

@ -2,7 +2,7 @@
#include <string> #include <string>
// 包含SpireCV SDK头文件 // 包含SpireCV SDK头文件
#include <sv_world.h> #include <sv_world.h>
#include <chrono>
using namespace std; using namespace std;
int main(int argc, char *argv[]) { int main(int argc, char *argv[]) {
@ -13,14 +13,18 @@ int main(int argc, char *argv[]) {
// 打开摄像头 // 打开摄像头
sv::Camera cap; sv::Camera cap;
// cap.setWH(640, 480); cap.setWH(640, 480);
// cap.setFps(30); cap.setFps(60);
cap.open(sv::CameraType::WEBCAM, 0); // CameraID 0 cap.open(sv::CameraType::WEBCAM, 4); // CameraID 0
// 实例化OpenCV的Mat类用于内存单帧图像 // 实例化OpenCV的Mat类用于内存单帧图像
cv::Mat img; cv::Mat img;
int frame_id = 0; int frame_id = 0;
while (1) while (1)
{ {
auto time1 = std::chrono::duration_cast<std::chrono::nanoseconds>(std::chrono::system_clock::now().time_since_epoch()).count();
// 实例化SpireCV的 单帧检测结果 接口类 TargetsInFrame
for(uint j = 0; j < 60; j++)
{
// 实例化SpireCV的 单帧检测结果 接口类 TargetsInFrame // 实例化SpireCV的 单帧检测结果 接口类 TargetsInFrame
sv::TargetsInFrame tgts(frame_id++); sv::TargetsInFrame tgts(frame_id++);
// 读取一帧图像到img // 读取一帧图像到img
@ -33,40 +37,44 @@ int main(int argc, char *argv[]) {
sv::drawTargetsInFrame(img, tgts); sv::drawTargetsInFrame(img, tgts);
// 控制台打印 降落标志 检测结果 // 控制台打印 降落标志 检测结果
printf("Frame-[%d]\n", frame_id); //printf("Frame-[%d]\n", frame_id);
// 打印当前检测的FPS // 打印当前检测的FPS
printf(" FPS = %.2f\n", tgts.fps); printf(" FPS = %.2f\n", tgts.fps);
// 打印当前相机的视场角degree // 打印当前相机的视场角degree
printf(" FOV (fx, fy) = (%.2f, %.2f)\n", tgts.fov_x, tgts.fov_y); //printf(" FOV (fx, fy) = (%.2f, %.2f)\n", tgts.fov_x, tgts.fov_y);
// 打印当前输入图像的像素宽度和高度 // 打印当前输入图像的像素宽度和高度
printf(" Frame Size (width, height) = (%d, %d)\n", tgts.width, tgts.height); //printf(" Frame Size (width, height) = (%d, %d)\n", tgts.width, tgts.height);
for (int i=0; i<tgts.targets.size(); i++) for (int i=0; i<tgts.targets.size(); i++)
{ {
printf("Frame-[%d], Marker-[%d]\n", frame_id, i); //printf("Frame-[%d], Marker-[%d]\n", frame_id, i);
// 打印每个 降落标志 的中心位置cxcy的值域为[0, 1]以及cxcy的像素值 // 打印每个 降落标志 的中心位置cxcy的值域为[0, 1]以及cxcy的像素值
printf(" Marker Center (cx, cy) = (%.3f, %.3f), in Pixels = ((%d, %d))\n", //printf(" Marker Center (cx, cy) = (%.3f, %.3f), in Pixels = ((%d, %d))\n",
tgts.targets[i].cx, tgts.targets[i].cy, //tgts.targets[i].cx, tgts.targets[i].cy,
int(tgts.targets[i].cx * tgts.width), //int(tgts.targets[i].cx * tgts.width),
int(tgts.targets[i].cy * tgts.height)); //int(tgts.targets[i].cy * tgts.height));
// 打印每个 降落标志 的外接矩形框的宽度、高度wh的值域为(0, 1]以及wh的像素值 // 打印每个 降落标志 的外接矩形框的宽度、高度wh的值域为(0, 1]以及wh的像素值
printf(" Marker Size (w, h) = (%.3f, %.3f), in Pixels = ((%d, %d))\n", //printf(" Marker Size (w, h) = (%.3f, %.3f), in Pixels = ((%d, %d))\n",
tgts.targets[i].w, tgts.targets[i].h, //tgts.targets[i].w, tgts.targets[i].h,
int(tgts.targets[i].w * tgts.width), //int(tgts.targets[i].w * tgts.width),
int(tgts.targets[i].h * tgts.height)); //int(tgts.targets[i].h * tgts.height));
// 打印每个 降落标志 的置信度 // 打印每个 降落标志 的置信度
printf(" Marker Score = %.3f\n", tgts.targets[i].score); // printf(" Marker Score = %.3f\n", tgts.targets[i].score);
// 打印每个 降落标志 的类别,字符串类型,"h"、"x"、"1"、"2"、"3"... // 打印每个 降落标志 的类别,字符串类型,"h"、"x"、"1"、"2"、"3"...
printf(" Marker Category = %s, Category ID = %d\n", tgts.targets[i].category.c_str(), tgts.targets[i].category_id); //printf(" Marker Category = %s, Category ID = %d\n", tgts.targets[i].category.c_str(), tgts.targets[i].category_id);
// 打印每个 降落标志 的视线角,跟相机视场相关 // 打印每个 降落标志 的视线角,跟相机视场相关
printf(" Marker Line-of-sight (ax, ay) = (%.3f, %.3f)\n", tgts.targets[i].los_ax, tgts.targets[i].los_ay); //printf(" Marker Line-of-sight (ax, ay) = (%.3f, %.3f)\n", tgts.targets[i].los_ax, tgts.targets[i].los_ay);
// 打印每个 降落标志 的3D位置在相机坐标系下跟降落标志实际半径、相机参数相关 // 打印每个 降落标志 的3D位置在相机坐标系下跟降落标志实际半径、相机参数相关
printf(" Marker Position = (x, y, z) = (%.3f, %.3f, %.3f)\n", tgts.targets[i].px, tgts.targets[i].py, tgts.targets[i].pz); // printf(" Marker Position = (x, y, z) = (%.3f, %.3f, %.3f)\n", tgts.targets[i].px, tgts.targets[i].py, tgts.targets[i].pz);
} }
// 显示检测结果img // 显示检测结果img
cv::imshow("img", img); cv::imshow("img", img);
cv::waitKey(10); cv::waitKey(10);
} }
auto time2 = std::chrono::duration_cast<std::chrono::nanoseconds>(std::chrono::system_clock::now().time_since_epoch()).count();
auto Ts = time2 - time1;
std::cout << "Ts = " << Ts / (1000) << "us" << std::endl;
}
return 0; return 0;
} }

View File

@ -28,15 +28,16 @@ int main(int argc, char *argv[]) {
// 实例化 框选目标跟踪类 // 实例化 框选目标跟踪类
sv::SingleObjectTracker sot; sv::SingleObjectTracker sot;
// 手动导入相机参数如果使用Amov的G1等吊舱或相机则可以忽略该步骤将自动下载相机参数文件 // 手动导入相机参数如果使用Amov的G1等吊舱或相机则可以忽略该步骤将自动下载相机参数文件
sot.loadCameraParams(sv::get_home() + "/SpireCV/calib_webcam_640x480.yaml"); //sot.loadCameraParams(sv::get_home() + "/SpireCV/calib_webcam_640x480.yaml");
// sot.loadCameraParams(sv::get_home() + "/SpireCV/calib_webcam_1280x720.yaml"); sot.loadCameraParams(sv::get_home() + "/SpireCV/calib_webcam_1280x720.yaml");
// sot.loadCameraParams(sv::get_home() + "/SpireCV/calib_webcam_1920x1080.yaml"); // sot.loadCameraParams(sv::get_home() + "/SpireCV/calib_webcam_1920x1080.yaml");
// 打开摄像头 // 打开摄像头
sv::Camera cap; sv::Camera cap;
// cap.setWH(640, 480); cap.setWH(1280, 720);
// cap.setFps(30); cap.setFps(30);
cap.open(sv::CameraType::WEBCAM, 0); // CameraID 0 cap.open(sv::CameraType::WEBCAM, 4); // CameraID 0
// cv::VideoCapture cap("/home/amov/SpireCV/test/tracking_1280x720.mp4"); // cv::VideoCapture cap("/home/amov/SpireCV/test/tracking_1280x720.mp4");
// 实例化OpenCV的Mat类用于内存单帧图像 // 实例化OpenCV的Mat类用于内存单帧图像
cv::Mat img; cv::Mat img;

View File

@ -0,0 +1,34 @@
#include <sv_world.h>
#include <iostream>
#include <string>
#include <chrono>
int main(int argc, char *argv[])
{
sv::Camera cap;
cap.setIp(argv[1]);
cap.setWH(640, 480);
cap.setFps(60);
cap.open(sv::CameraType::G1);
//cap.open(sv::CameraType::WEBCAM, 4);
cv::Mat img;
//auto time1,time2;
while (1)
{
auto time1 = std::chrono::duration_cast<std::chrono::nanoseconds>(std::chrono::system_clock::now().time_since_epoch()).count();
//for (uint16_t i = 0; i < 120; i++)
//{
cap.read(img);
cv::imshow("TEST",img);
cv::waitKey(1);
//}
auto time2 = std::chrono::duration_cast<std::chrono::nanoseconds>(std::chrono::system_clock::now().time_since_epoch()).count();
auto Ts = time2 - time1;
std::cout << "read 120 count;Ts = " << Ts / (1000) << "us" << std::endl;
std::cout << "average FPS = " << (1000 * 1000 * 1000) / (Ts / 120) << std::endl;
}
}

View File

@ -1,39 +0,0 @@
#!/bin/bash -e
root_dir=${HOME}"/SpireCV/models"
root_server="https://download.amovlab.com/model"
sv_params1=${HOME}"/SpireCV/sv_algorithm_params.json"
sv_params2=${HOME}"/SpireCV/sv_algorithm_params_coco_640.json"
sv_params3=${HOME}"/SpireCV/sv_algorithm_params_coco_1280.json"
camera_params1=${HOME}"/SpireCV/calib_webcam_640x480.yaml"
camera_params2=${HOME}"/SpireCV/calib_webcam_1280x720.yaml"
if [ ! -d ${root_dir} ]; then
echo -e "\033[32m[INFO]: ${root_dir} not exist, creating it ... \033[0m"
mkdir -p ${root_dir}
fi
if [ ! -f ${sv_params1} ]; then
echo -e "\033[32m[INFO]: ${sv_params1} not exist, downloading ... \033[0m"
wget -O ${sv_params1} ${root_server}/install/a-params/sv_algorithm_params.json
fi
if [ ! -f ${sv_params2} ]; then
echo -e "\033[32m[INFO]: ${sv_params2} not exist, downloading ... \033[0m"
wget -O ${sv_params2} ${root_server}/install/a-params/sv_algorithm_params_coco_640.json
fi
if [ ! -f ${sv_params3} ]; then
echo -e "\033[32m[INFO]: ${sv_params3} not exist, downloading ... \033[0m"
wget -O ${sv_params3} ${root_server}/install/a-params/sv_algorithm_params_coco_1280.json
fi
if [ ! -f ${camera_params1} ]; then
echo -e "\033[32m[INFO]: ${camera_params1} not exist, downloading ... \033[0m"
wget -O ${camera_params1} ${root_server}/install/c-params/calib_webcam_640x480.yaml
fi
if [ ! -f ${camera_params2} ]; then
echo -e "\033[32m[INFO]: ${camera_params2} not exist, downloading ... \033[0m"
wget -O ${camera_params2} ${root_server}/install/c-params/calib_webcam_1280x720.yaml
fi

View File

@ -2,7 +2,7 @@
sudo apt install -y \ sudo apt install -y \
build-essential yasm cmake libtool libc6 libc6-dev unzip wget libeigen3-dev libfmt-dev \ build-essential yasm cmake libtool libc6 libc6-dev unzip wget libfmt-dev \
libnuma1 libnuma-dev libx264-dev libx265-dev libfaac-dev libssl-dev libnuma1 libnuma-dev libx264-dev libx265-dev libfaac-dev libssl-dev
root_dir=${HOME}"/SpireCV" root_dir=${HOME}"/SpireCV"

View File

@ -8,7 +8,6 @@ sudo apt install -y gstreamer1.0-tools gstreamer1.0-x gstreamer1.0-alsa
sudo apt install -y gstreamer1.0-gl gstreamer1.0-gtk3 gstreamer1.0-qt5 sudo apt install -y gstreamer1.0-gl gstreamer1.0-gtk3 gstreamer1.0-qt5
sudo apt install -y gstreamer1.0-pulseaudio sudo apt install -y gstreamer1.0-pulseaudio
sudo apt install -y gtk-doc-tools sudo apt install -y gtk-doc-tools
sudo apt install -y libeigen3-dev libfmt-dev
sudo apt -y install autotools-dev automake m4 perl sudo apt -y install autotools-dev automake m4 perl
sudo apt -y install libtool sudo apt -y install libtool

View File

@ -8,7 +8,6 @@ sudo apt install -y gstreamer1.0-tools gstreamer1.0-x gstreamer1.0-alsa
sudo apt install -y gstreamer1.0-gl gstreamer1.0-gtk3 gstreamer1.0-qt5 sudo apt install -y gstreamer1.0-gl gstreamer1.0-gtk3 gstreamer1.0-qt5
sudo apt install -y gstreamer1.0-pulseaudio sudo apt install -y gstreamer1.0-pulseaudio
sudo apt install -y gtk-doc-tools sudo apt install -y gtk-doc-tools
sudo apt install -y libeigen3-dev libfmt-dev
git clone https://gitee.com/jario-jin/gst-rtsp-server-b18.git git clone https://gitee.com/jario-jin/gst-rtsp-server-b18.git
cd gst-rtsp-server-b18 cd gst-rtsp-server-b18

View File

@ -1,54 +0,0 @@
#!/bin/sh
wget https://download.amovlab.com/model/deps/opencv-4.7.0.zip
wget https://download.amovlab.com/model/deps/opencv_contrib-4.7.0.zip
wget https://download.amovlab.com/model/deps/opencv_cache-4.7.0.zip
package_dir="."
mkdir ~/opencv_build
if [ ! -d ""$package_dir"" ];then
echo "\033[31m[ERROR]: $package_dir not exist!: \033[0m"
exit 1
fi
sudo apt update
sudo apt install -y build-essential
sudo apt install -y cmake git libgtk2.0-dev pkg-config libavcodec-dev libavformat-dev libswscale-dev
sudo apt install -y libjasper1 libjasper-dev
sudo apt install -y python3-dev python3-numpy libtbb2 libtbb-dev libjpeg-dev libpng-dev libtiff-dev
sudo apt install -y libdc1394-22-dev
echo "\033[32m[INFO]:\033[0m unzip opencv-4.7.0.zip ..."
unzip -q -o $package_dir/opencv-4.7.0.zip -d ~/opencv_build
echo "\033[32m[INFO]:\033[0m unzip opencv_contrib-4.7.0.zip ..."
unzip -q -o $package_dir/opencv_contrib-4.7.0.zip -d ~/opencv_build
echo "\033[32m[INFO]:\033[0m unzip opencv_cache-4.7.0.zip ..."
unzip -q -o $package_dir/opencv_cache-4.7.0.zip -d ~/opencv_build
sudo rm opencv-4.7.0.zip
sudo rm opencv_contrib-4.7.0.zip
sudo rm opencv_cache-4.7.0.zip
cd ~/opencv_build/opencv-4.7.0
mkdir .cache
cp -r ~/opencv_build/opencv_cache-4.7.0/* ~/opencv_build/opencv-4.7.0/.cache/
mkdir build
cd build
cmake -D CMAKE_BUILD_TYPE=Release -D WITH_CUDA=ON -D CUDA_ARCH_BIN=8.7 -D WITH_CUDNN=ON -D OPENCV_DNN_CUDA=ON -D WITH_CUBLAS=ON -D CUDA_TOOLKIT_ROOT_DIR=/usr/local/cuda -D OPENCV_ENABLE_NONFREE=ON -D CMAKE_INSTALL_PREFIX=/usr/local -D OPENCV_EXTRA_MODULES_PATH=../../opencv_contrib-4.7.0/modules ..
make -j2
sudo make install
cd
sudo rm -r ~/opencv_build

0
scripts/test/test_fps.sh Executable file → Normal file
View File

0
scripts/test/test_gimbal.sh Executable file → Normal file
View File

1
scripts/x86-cuda/x86-gst-install.sh Executable file → Normal file
View File

@ -8,7 +8,6 @@ sudo apt install -y gstreamer1.0-tools gstreamer1.0-x gstreamer1.0-alsa
sudo apt install -y gstreamer1.0-gl gstreamer1.0-gtk3 gstreamer1.0-qt5 sudo apt install -y gstreamer1.0-gl gstreamer1.0-gtk3 gstreamer1.0-qt5
sudo apt install -y gstreamer1.0-pulseaudio sudo apt install -y gstreamer1.0-pulseaudio
sudo apt install -y gtk-doc-tools sudo apt install -y gtk-doc-tools
sudo apt install -y libeigen3-dev libfmt-dev
git clone https://gitee.com/jario-jin/gst-rtsp-server-b18.git git clone https://gitee.com/jario-jin/gst-rtsp-server-b18.git
cd gst-rtsp-server-b18 cd gst-rtsp-server-b18

View File

@ -1,69 +0,0 @@
#!/bin/sh
wget https://download.amovlab.com/model/deps/opencv-4.7.0.zip
wget https://download.amovlab.com/model/deps/opencv_contrib-4.7.0.zip
wget https://download.amovlab.com/model/deps/opencv_cache_x86-4.7.0.zip
package_dir="."
mkdir ~/opencv_build
if [ ! -d ""$package_dir"" ];then
echo "\033[31m[ERROR]: $package_dir not exist!: \033[0m"
exit 1
fi
# sudo add-apt-repository "deb http://security.ubuntu.com/ubuntu xenial-security main"
# sudo add-apt-repository "deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu-ports/ xenial main multiverse restricted universe"
sudo apt update
sudo apt install -y build-essential
sudo apt install -y cmake git libgtk2.0-dev pkg-config libavcodec-dev libavformat-dev libswscale-dev
sudo add-apt-repository "deb http://security.ubuntu.com/ubuntu xenial-security main"
sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 3B4FE6ACC0B21F32
sudo apt update
sudo apt install -y libjasper1 libjasper-dev
sudo apt install -y python3-dev python3-numpy libtbb2 libtbb-dev libjpeg-dev libpng-dev libtiff-dev
sudo apt install -y libdc1394-22-dev
echo "\033[32m[INFO]:\033[0m unzip opencv-4.7.0.zip ..."
unzip -q -o $package_dir/opencv-4.7.0.zip -d ~/opencv_build
echo "\033[32m[INFO]:\033[0m unzip opencv_contrib-4.7.0.zip ..."
unzip -q -o $package_dir/opencv_contrib-4.7.0.zip -d ~/opencv_build
echo "\033[32m[INFO]:\033[0m unzip opencv_cache_x86-4.7.0.zip ..."
unzip -q -o $package_dir/opencv_cache_x86-4.7.0.zip -d ~/opencv_build
sudo rm opencv-4.7.0.zip
sudo rm opencv_contrib-4.7.0.zip
sudo rm opencv_cache_x86-4.7.0.zip
cd ~/opencv_build/opencv-4.7.0
mkdir .cache
cp -r ~/opencv_build/opencv_cache_x86-4.7.0/* ~/opencv_build/opencv-4.7.0/.cache/
mkdir build
cd build
cmake -D CMAKE_BUILD_TYPE=Release \
-D WITH_CUDA=ON \
-D WITH_CUDNN=ON \
-D OPENCV_DNN_CUDA=ON \
-D WITH_CUBLAS=ON \
-D CUDA_TOOLKIT_ROOT_DIR=/usr/local/cuda \
-D OPENCV_ENABLE_NONFREE=ON \
-D CMAKE_INSTALL_PREFIX=/usr/local \
-D OPENCV_EXTRA_MODULES_PATH=../../opencv_contrib-4.7.0/modules ..
make -j2
sudo make install
cd
sudo rm -r ~/opencv_build

5
scripts/x86-cuda/x86-opencv470-install.sh Executable file → Normal file
View File

@ -20,12 +20,7 @@ fi
sudo apt update sudo apt update
sudo apt install -y build-essential sudo apt install -y build-essential
sudo apt install -y cmake git libgtk2.0-dev pkg-config libavcodec-dev libavformat-dev libswscale-dev sudo apt install -y cmake git libgtk2.0-dev pkg-config libavcodec-dev libavformat-dev libswscale-dev
sudo add-apt-repository "deb http://security.ubuntu.com/ubuntu xenial-security main"
sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 3B4FE6ACC0B21F32
sudo apt update
sudo apt install -y libjasper1 libjasper-dev sudo apt install -y libjasper1 libjasper-dev
sudo apt install -y python3-dev python3-numpy libtbb2 libtbb-dev libjpeg-dev libpng-dev libtiff-dev sudo apt install -y python3-dev python3-numpy libtbb2 libtbb-dev libjpeg-dev libpng-dev libtiff-dev
sudo apt install -y libdc1394-22-dev sudo apt install -y libdc1394-22-dev

0
scripts/x86-cuda/x86-ubuntu2004-cuda-cudnn-11-6.sh Executable file → Normal file
View File

View File

@ -368,6 +368,58 @@ void UDPServer::send(const TargetsInFrame& tgts_)
} }
void drawTargetsInFrame(
cv::Mat& img_,
const TargetsInFrame& tgts_,
int aruco_track_id,
bool with_all,
bool with_category,
bool with_tid,
bool with_seg,
bool with_box,
bool with_ell,
bool with_aruco,
bool with_yaw
)
{
if (tgts_.rois.size() > 0 )
{
cv::Mat image_ret;
cv::addWeighted(img_, 0.5, cv::Mat::zeros(cv::Size(img_.cols, img_.rows), CV_8UC3), 0, 0, image_ret);
cv::Rect roi = cv::Rect(tgts_.rois[0].x1, tgts_.rois[0].y1, tgts_.rois[0].x2 - tgts_.rois[0].x1, tgts_.rois[0].y2 - tgts_.rois[0].y1);
img_(roi).copyTo(image_ret(roi));
image_ret.copyTo(img_);
}
std::vector<std::vector<cv::Point2f> > aruco_corners;
std::vector<int> aruco_ids;
for (Target tgt : tgts_.targets)
{
if ((with_all || with_aruco) && tgt.has_aruco && (tgt.tracked_id == aruco_track_id))
{
std::vector<cv::Point2f> a_corners;
int a_id;
if (tgt.getAruco(a_id, a_corners)) { aruco_ids.push_back(a_id); aruco_corners.push_back(a_corners); }
cv::circle(img_, cv::Point(int(tgt.cx * tgts_.width), int(tgt.cy * tgts_.height)), 4, cv::Scalar(0,255,0), 2);
}
if ((with_all || with_box) && tgt.has_box && (tgt.tracked_id == aruco_track_id))
{
Box b;
tgt.getBox(b);
cv::rectangle(img_, cv::Rect(b.x1, b.y1, b.x2-b.x1+1, b.y2-b.y1+1), cv::Scalar(0,0,255), 1, 1, 0);
if ((with_all || with_category) && tgt.has_category)
{
cv::putText(img_, tgt.category, cv::Point(b.x1, b.y1-4), cv::FONT_HERSHEY_DUPLEX, 0.4, cv::Scalar(255,0,0));
}
}
}
if ((with_all || with_aruco) && aruco_ids.size() > 0)
{
cv::aruco::drawDetectedMarkers(img_, aruco_corners, aruco_ids);
}
}
void drawTargetsInFrame( void drawTargetsInFrame(
cv::Mat& img_, cv::Mat& img_,
const TargetsInFrame& tgts_, const TargetsInFrame& tgts_,
@ -809,7 +861,7 @@ VideoWriterBase::VideoWriterBase()
VideoWriterBase::~VideoWriterBase() VideoWriterBase::~VideoWriterBase()
{ {
this->release(); this->release();
// this->_tt.join(); this->_tt.join();
} }
cv::Size VideoWriterBase::getSize() cv::Size VideoWriterBase::getSize()
{ {
@ -991,7 +1043,7 @@ CameraBase::CameraBase(CameraType type, int id)
CameraBase::~CameraBase() CameraBase::~CameraBase()
{ {
this->_is_running = false; this->_is_running = false;
// this->_tt.join(); this->_tt.join();
} }
void CameraBase::setWH(int width, int height) void CameraBase::setWH(int width, int height)
{ {
@ -1103,13 +1155,37 @@ void CameraBase::_run()
{ {
while (this->_is_running && this->_cap.isOpened()) while (this->_is_running && this->_cap.isOpened())
{ {
this->_cap >> this->_frame; //this->_cap >> this->_frame;
this->_is_updated = true; //this->_is_updated = true;
std::this_thread::sleep_for(std::chrono::milliseconds(2)); //std::this_thread::sleep_for(std::chrono::milliseconds(2));
if(this->_cap.grab())
{
std::lock_guard<std::mutex> locker(this->_frame_mutex);
this->_cap.retrieve(this->_frame);
this->_frame_empty.notify_all();
}
std::this_thread::sleep_for(std::chrono::milliseconds(1));
} }
} }
bool CameraBase::read(cv::Mat& image) bool CameraBase::read(cv::Mat& image)
{ {
bool ret = false;
if (this->_type == CameraType::WEBCAM || this->_type == CameraType::G1 || this->_type == CameraType::MIPI)
{
std::lock_guard<std::mutex> locker(this->_frame_mutex);
if(this->_frame_empty.wait_for(this->_frame_mutex,std::chrono::milliseconds(2000)) == std::cv_status::no_timeout)
{
this->_frame.copyTo(image);
ret = true;
}
else
{
throw std::runtime_error("SpireCV (101) Camera cannot OPEN, check CAMERA_ID!");
}
}
return ret;
if (this->_type == CameraType::WEBCAM || this->_type == CameraType::G1 || this->_type == CameraType::MIPI) if (this->_type == CameraType::WEBCAM || this->_type == CameraType::G1 || this->_type == CameraType::MIPI)
{ {
int n_try = 0; int n_try = 0;
@ -1121,7 +1197,7 @@ bool CameraBase::read(cv::Mat& image)
this->_frame.copyTo(image); this->_frame.copyTo(image);
break; break;
} }
std::this_thread::sleep_for(std::chrono::milliseconds(20)); std::this_thread::sleep_for(std::chrono::milliseconds(10));
n_try ++; n_try ++;
} }
} }

View File

@ -79,6 +79,7 @@ void Camera::openImpl()
else if (this->_type == CameraType::MIPI) else if (this->_type == CameraType::MIPI)
{ {
char pipe[512]; char pipe[512];
this->_cap.open(this->_camera_id);
if (this->_width <= 0 || this->_height <= 0) if (this->_width <= 0 || this->_height <= 0)
{ {
this->_width = 1280; this->_width = 1280;
@ -89,7 +90,7 @@ void Camera::openImpl()
this->_fps = 30; this->_fps = 30;
} }
sprintf(pipe, "nvarguscamerasrc sensor-id=%d ! video/x-raw(memory:NVMM), width=(int)%d, height=(int)%d, format=(string)NV12, framerate=(fraction)%d/1 ! nvvidconv flip-method=0 ! video/x-raw, width=(int)%d, height=(int)%d, format=(string)BGRx ! videoconvert ! video/x-raw, format=(string)BGR ! appsink", this->_camera_id, this->_width, this->_height, this->_fps, this->_width, this->_height); sprintf(pipe, "nvarguscamerasrc framerate=(fraction)%d/1 ! nvvidconv flip-method=0 ! video/x-raw, width=(int)%d, height=(int)%d, format=(string)BGRx ! videoconvert ! video/x-raw, format=(string)BGR ! appsink",this->_fps,this->_width,this->_height);
this->_cap.open(pipe, cv::CAP_GSTREAMER); this->_cap.open(pipe, cv::CAP_GSTREAMER);
} }
} }