├── .gitignore ├── CMakeLists.txt ├── LICENSE ├── README.en.md ├── README.md ├── algorithm ├── color_line │ └── sv_color_line.cpp ├── common_det │ ├── cuda │ │ ├── common_det_cuda_impl.cpp │ │ ├── common_det_cuda_impl.h │ │ └── yolov7 │ │ │ ├── calibrator.cpp │ │ │ ├── calibrator.h │ │ │ ├── config.h │ │ │ ├── cuda_utils.h │ │ │ ├── logging.h │ │ │ ├── macros.h │ │ │ ├── model.cpp │ │ │ ├── model.h │ │ │ ├── postprocess.cpp │ │ │ ├── postprocess.h │ │ │ ├── preprocess.cu │ │ │ ├── preprocess.h │ │ │ ├── types.h │ │ │ ├── utils.h │ │ │ ├── yololayer.cu │ │ │ └── yololayer.h │ ├── intel │ │ ├── common_det_intel_impl.cpp │ │ └── common_det_intel_impl.h │ └── sv_common_det.cpp ├── ellipse_det │ ├── ellipse_detector.cpp │ └── ellipse_detector.h ├── landing_det │ ├── cuda │ │ ├── landing_det_cuda_impl.cpp │ │ └── landing_det_cuda_impl.h │ ├── intel │ │ ├── landing_det_intel_impl.cpp │ │ └── landing_det_intel_impl.h │ └── sv_landing_det.cpp ├── mde │ ├── cuda │ │ ├── depth_est_cuda_impl.cpp │ │ ├── depth_est_cuda_impl.h │ │ ├── utils.cpp │ │ └── utils.h │ └── sv_depth_est.cpp ├── mot │ ├── bytetrack │ │ ├── BYTETracker.cpp │ │ ├── BYTETracker.h │ │ ├── BytekalmanFilter.cpp │ │ ├── BytekalmanFilter.h │ │ ├── STrack.cpp │ │ ├── STrack.h │ │ ├── dataType.h │ │ ├── lapjv.cpp │ │ ├── lapjv.h │ │ └── utils.cpp │ ├── sort │ │ ├── sort.cpp │ │ └── sort.h │ └── sv_mot.cpp ├── sot │ ├── ocv470 │ │ ├── sot_ocv470_impl.cpp │ │ └── sot_ocv470_impl.h │ └── sv_sot.cpp ├── sv_algorithm_base.cpp └── veri │ ├── cuda │ ├── veri_det_cuda_impl.cpp │ └── veri_det_cuda_impl.h │ ├── intel │ ├── veri_det_intel_impl.cpp │ └── veri_det_intel_impl.h │ └── sv_veri_det.cpp ├── build_on_jetson.sh ├── build_on_x86_cuda.sh ├── build_on_x86_intel.sh ├── gimbal_ctrl ├── IOs │ └── serial │ │ ├── README.md │ │ ├── include │ │ └── serial │ │ │ ├── impl │ │ │ ├── unix.h │ │ │ └── win.h │ │ │ ├── serial.h │ │ │ └── v8stdint.h │ │ └── src │ │ ├── impl │ │ ├── list_ports │ │ │ ├── list_ports_linux.cc │ │ │ ├── list_ports_osx.cc │ │ │ └── list_ports_win.cc │ │ ├── unix.cc │ │ └── win.cc │ │ └── serial.cc ├── driver │ └── src │ │ ├── AT10 │ │ ├── AT10_gimbal_crc32.h │ │ ├── AT10_gimbal_driver.cpp │ │ ├── AT10_gimbal_driver.h │ │ ├── AT10_gimbal_funtion.cpp │ │ └── AT10_gimbal_struct.h │ │ ├── FIFO │ │ ├── Ring_Fifo.cpp │ │ └── Ring_Fifo.h │ │ ├── G1 │ │ ├── g1_gimbal_crc32.h │ │ ├── g1_gimbal_driver.cpp │ │ ├── g1_gimbal_driver.h │ │ ├── g1_gimbal_funtion.cpp │ │ └── g1_gimbal_struct.h │ │ ├── GX40 │ │ ├── GX40_gimbal_crc16.h │ │ ├── GX40_gimbal_driver.cpp │ │ ├── GX40_gimbal_driver.h │ │ ├── GX40_gimbal_funtion.cpp │ │ └── GX40_gimbal_struct.h │ │ ├── Q10f │ │ ├── Q10f_gimbal_crc32.h │ │ ├── Q10f_gimbal_driver.cpp │ │ ├── Q10f_gimbal_driver.h │ │ ├── Q10f_gimbal_funtion.cpp │ │ └── Q10f_gimbal_struct.h │ │ ├── SU17-G │ │ ├── SU17_gimbal_crc.h │ │ ├── SU17_gimbal_driver.cpp │ │ ├── SU17_gimbal_driver.h │ │ ├── SU17_gimbal_funtion.cpp │ │ └── SU17_gimbal_struct.h │ │ ├── amovGimbal │ │ ├── amov_gimbal.h │ │ ├── amov_gimbal_c.h │ │ └── amov_gimbal_struct.h │ │ ├── amov_gimbal_factory.cpp │ │ ├── amov_gimbal_interface.cpp │ │ ├── amov_gimbal_interface_c.cpp │ │ ├── amov_gimbal_private.h │ │ ├── amov_gimbal_realize.cpp │ │ └── amov_tool.h ├── sv_gimbal.cpp └── sv_gimbal_io.hpp ├── include ├── sv_algorithm_base.h ├── sv_color_line.h ├── sv_common_det.h ├── sv_core.h ├── sv_depth_est.h ├── sv_gimbal.h ├── sv_landing_det.h ├── sv_mot.h ├── sv_sot.h ├── sv_veri_det.h ├── sv_video_base.h ├── sv_video_input.h ├── sv_video_output.h └── sv_world.h ├── params ├── a-params │ ├── sv_algorithm_params.json │ ├── sv_algorithm_params_1280_wo_mask.json │ ├── sv_algorithm_params_640_w_mask.json │ ├── sv_algorithm_params_640_wo_mask.json │ ├── sv_algorithm_params_coco_1280.json │ ├── sv_algorithm_params_coco_640.json │ ├── sv_algorithm_params_csrt.json │ ├── sv_algorithm_params_kcf.json │ ├── sv_algorithm_params_nano.json │ └── sv_algorithm_params_siamrpn.json └── c-params │ ├── calib_webcam_1280x720.yaml │ ├── calib_webcam_1920x1080.yaml │ └── calib_webcam_640x480.yaml ├── samples ├── SpireCVDet.cpp ├── SpireCVSeg.cpp ├── calib │ ├── aruco_samples_utility.hpp │ ├── calibrate_camera_charuco.cpp │ └── create_marker.cpp ├── demo │ ├── aruco_detection.cpp │ ├── camera_reading.cpp │ ├── color_line_detect.cpp │ ├── common_object_detection.cpp │ ├── detection_with_clicked_tracking.cpp │ ├── ellipse_detection.cpp │ ├── eval_MOT_metric.cpp │ ├── gimbal_aruco_detection.cpp │ ├── gimbal_detection_with_clicked_tracking.cpp │ ├── gimbal_landing_marker_detection.cpp │ ├── gimbal_udp_detection_info_sender.cpp │ ├── landing_marker_detection.cpp │ ├── mon_depth_estimation.cpp │ ├── multiple_object_tracking.cpp │ ├── single_object_tracking.cpp │ ├── udp_detection_info_receiver.cpp │ ├── udp_detection_info_receiver_by_airborne.cpp │ ├── udp_detection_info_sender.cpp │ ├── veri.cpp │ ├── video_saving.cpp │ └── video_streaming.cpp └── test │ ├── eval_fps_on_video.cpp │ ├── eval_mAP_on_coco_val │ ├── coco_eval.py │ ├── eval_mAP_on_coco_val.cpp │ └── pd2cocojson.py │ ├── gimbal_test.cpp │ └── mot_metrics │ ├── eval_mot_metric_gt.sh │ ├── run_mot_challenge.py │ └── write_val_seqmap.py ├── scripts ├── common │ ├── configs-downloading.sh │ ├── download_test_videos.sh │ ├── ffmpeg425-install.sh │ ├── gst-install-orin.sh │ ├── gst-install.sh │ ├── models-converting.sh │ ├── models-downloading.sh │ └── opencv470-install.sh ├── jetson │ ├── configs-downloading.sh │ ├── gst-install-orin.sh │ ├── gst-install.sh │ ├── opencv470-install.sh │ ├── opencv470-jetpack511-cuda-install.sh │ └── opencv470-jetpack511-install.sh ├── model_sync.py ├── test │ ├── test_fps.sh │ └── test_gimbal.sh ├── x86-cuda │ ├── configs-downloading.sh │ ├── ffmpeg425-install.sh │ ├── gst-install.sh │ ├── opencv470-cuda-install.sh │ ├── opencv470-install.sh │ ├── ubuntu1804-cuda-cudnn-11-1.sh │ ├── ubuntu2004-cuda-cudnn-11-6.sh │ └── ubuntu2004-cudnn-12-0-for40series.sh └── x86-intel │ ├── configs-downloading.sh │ ├── ffmpeg-install.sh │ ├── gst-install.sh │ ├── libva-install-gst.sh │ ├── libva-install.sh │ ├── opencl-vaapi-install.sh │ ├── opencv470-intel-install.sh │ ├── openvino-install.sh │ └── zlm-server-install.sh ├── utils ├── gason.cpp ├── gason.h ├── sv_crclib.cpp ├── sv_crclib.h ├── sv_util.cpp └── sv_util.h └── video_io ├── ffmpeg ├── x86_cuda │ ├── bs_common.h │ ├── bs_push_streamer.cpp │ ├── bs_push_streamer.h │ ├── bs_video_saver.cpp │ └── bs_video_saver.h └── x86_intel │ ├── bs_common.h │ ├── bs_push_streamer.cpp │ ├── bs_push_streamer.h │ ├── bs_video_saver.cpp │ └── bs_video_saver.h ├── gstreamer ├── streamer_gstreamer_impl.cpp ├── streamer_gstreamer_impl.h ├── writer_gstreamer_impl.cpp └── writer_gstreamer_impl.h ├── sv_video_base.cpp ├── sv_video_input.cpp └── sv_video_output.cpp /.gitignore: -------------------------------------------------------------------------------- 1 | # Distribution / packaging 2 | .Python 3 | build/ 4 | models/ 5 | confs/ 6 | ZLM/ 7 | ZLMediaKit/ 8 | ffmpeg-4.2.5/ 9 | nv-codec-headers/ 10 | *.bz2 11 | develop-eggs/ 12 | dist/ 13 | eggs/ 14 | .eggs/ 15 | parts/ 16 | sdist/ 17 | var/ 18 | wheels/ 19 | share/python-wheels/ 20 | *.egg-info/ 21 | .installed.cfg 22 | *.egg 23 | MANIFEST 24 | .idea/ 25 | calib_webcam_1280x720.yaml 26 | calib_webcam_640x480.yaml 27 | sv_algorithm_params.json 28 | sv_algorithm_params_coco_1280.json 29 | sv_algorithm_params_coco_640.json 30 | 31 | # Prerequisites 32 | *.d 33 | 34 | # Compiled Object files 35 | *.slo 36 | *.lo 37 | *.o 38 | *.obj 39 | 40 | # Precompiled Headers 41 | *.gch 42 | *.pch 43 | 44 | # Compiled Dynamic libraries 45 | *.so 46 | *.dylib 47 | *.dll 48 | 49 | # Fortran module files 50 | *.mod 51 | *.smod 52 | 53 | # Compiled Static libraries 54 | *.lai 55 | *.la 56 | *.a 57 | *.lib 58 | 59 | # Executables 60 | *.exe 61 | *.out 62 | *.app 63 | 64 | # Byte-compiled / optimized / DLL files 65 | __pycache__/ 66 | *.py[cod] 67 | *$py.class 68 | 69 | # PyInstaller 70 | # Usually these files are written by a python script from a template 71 | # before PyInstaller builds the exe, so as to inject date/other infos into it. 72 | *.manifest 73 | *.spec 74 | 75 | # Environments 76 | .env 77 | .venv 78 | env/ 79 | venv/ 80 | ENV/ 81 | env.bak/ 82 | venv.bak/ 83 | 84 | # VSCode Editor 85 | .vscode/ 86 | 87 | -------------------------------------------------------------------------------- /README.en.md: -------------------------------------------------------------------------------- 1 | SpireCV logo 2 | 3 | # SpireCV Intelligent perception algorithm library 4 | 5 | ## Overview 6 | 7 | SpireCV is an **real-time edge perception SDK** built for **intelligent unmanned systems**, with main functions including **camera/pod control**, **video saving and push streaming**, **target detection and tracking**, and **edge data management**. It aims to provide mobile robot developers with high-performance, high-reliability, simple interface and feature-rich visual perception capabilities. 8 | 9 | - Github:https://github.com/amov-lab/SpireCV 10 | - Gitee:https://gitee.com/amovlab/SpireCV 11 | - **Maintaining an open-source project is not easy, please click star to support us, thanks! ** 12 | 13 | ## Quick start 14 | 15 | - Installation and use: [SpireCV user manual](https://docs.amovlab.com/Spire_CV_Amov/#/)、[SpireCV developer kit guide](https://docs.amovlab.com/spirecvkit/#/) 16 | - Basic knowledge of C++ language and CMake compilation tool is required 17 | - Need to master the foundation of OpenCV vision library and understand the computational libraries such as CUDA, OpenVINO, RKNN and CANN 18 | - Need to understand the basic concepts and basic operation of ROS 19 | 20 | - Q&A and communication: 21 | - Q&A forum (official regular Q&A, recommended): [Amovlab Community - SpireCV Q&A Zone](https://bbs.amovlab.com/) 22 | - Add WeChat yinyue199506 (note: SpireCV) into the SpireCV intelligent perception algorithm library exchange group 23 | - Search and subscribe "Amovlab" on YouTube.com, we will update the video from time to time 24 | 25 | ## Framework 26 | 27 | #### The main framework is shown in the figure: 28 | 29 | 30 | 31 | #### Current support: 32 | - **Functional level**: 33 | - [x] Video algorithm module (providing perceptual algorithms with unified interfaces, efficient performance and diverse functions) 34 | - [x] Video input, save and push stream module (to provide stable, cross-platform video reading and writing capabilities) 35 | - [x] Camera and pod control module (for the typical hardware ecology to open the interface, easy to use) 36 | - [x] Sensing information interaction module (providing UDP communication protocol) 37 | - [x] [ROS interface](https://gitee.com/amovlab1/spirecv-ros.git) 38 | - **Platform level**: 39 | - [x] X86 + Nvidia GPUs (10 series, 20 series, and 30 series graphics cards recommended) 40 | - [x] Jetson (AGX Orin/Xavier、Orin NX/Nano、Xavier NX) 41 | - [x] Intel CPU 42 | - [ ] HUAWEI Ascend (coming soon) 43 | - [ ] Rockchip (coming soon) 44 | 45 | ## Demos 46 | - **QR code detection** 47 | 48 | 49 | - **Landing mark detection** 50 | 51 | 52 | - **Ellipse detection** 53 | 54 | 55 | - **Target click tracking (including target detection and tracking)** 56 | 57 | 58 | - **Low latency push streaming** 59 | 60 | 61 | 62 | ## Copyright statement 63 | 64 | - SpireCV is protected under the Apache License 2.0. 65 | - SpireCV is for personal use only, please do NOT use it for commercial purposes. 66 | - If this project is used for profit, Amovlab will pursue infringement. 67 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | SpireCV logo 2 | 3 | # SpireCV 智能感知算法库 4 | 5 | ## 项目概况 6 | 7 | SpireCV是一个专为**智能无人系统**打造的**边缘实时感知SDK**,主要功能包括**相机/吊舱控制**、**视频保存与推流**、**目标探测识别与跟踪**、**边缘数据管理迭代**等。旨在为移动机器人开发者提供高性能、高可靠、接口简洁、功能丰富的视觉感知能力。 8 | 9 | - Github:https://github.com/amov-lab/SpireCV 10 | - Gitee:https://gitee.com/amovlab/SpireCV 11 | - **开源项目,维护不易,还烦请点一个star收藏,谢谢支持!** 12 | 13 | ## 快速入门 14 | 15 | - 安装及使用:[SpireCV使用手册](https://docs.amovlab.com/Spire_CV_Amov/#/)([wolai版本](https://www.wolai.com/4qWFM6aZmtpQE6jj7hnNMW))、[SpireCV开发者套件指南](https://docs.amovlab.com/spirecvkit/#/) 16 | - 需掌握C++语言基础、CMake编译工具基础。 17 | - 需要掌握OpenCV视觉库基础,了解CUDA、OpenVINO、RKNN和CANN等计算库。 18 | - 需要了解ROS基本概念及基本操作。 19 | 20 | - 答疑及交流: 21 | - 答疑论坛(官方定期答疑,推荐):[阿木社区-SpireCV问答专区](https://bbs.amovlab.com/) 22 | - 添加微信yinyue199506(备注消息:SpireCV)进入SpireCV智能感知算法库交流群。 23 | - B站搜索并关注“阿木社区”,开发团队定期直播答疑。 24 | 25 | ## 项目框架 26 | 27 | #### 主要框架如图所示: 28 | 29 | 30 | 31 | #### 目前支持情况: 32 | - **功能层**: 33 | - [x] 视频算法模块(提供接口统一、性能高效、功能多样的感知算法) 34 | - [x] 视频输入、保存与推流模块(提供稳定、跨平台的视频读写能力) 35 | - [x] 相机、吊舱控制模块(针对典型硬件生态打通接口,易使用) 36 | - [x] 感知信息交互模块(提供UDP通信协议) 37 | - [x] [ROS接口](https://gitee.com/amovlab1/spirecv-ros.git) 38 | - **平台层**: 39 | - [x] X86+Nvidia GPU(推荐10系、20系、30系显卡) 40 | - [x] Jetson(AGX Orin/Xavier、Orin NX/Nano、Xavier NX) 41 | - [x] Intel CPU 42 | - [ ] HUAWEI Ascend(推进中) 43 | - [ ] Rockchip(推进中) 44 | 45 | ## 功能展示 46 | - **二维码检测** 47 | 48 | 49 | - **起降标志检测** 50 | 51 | 52 | - **椭圆检测** 53 | 54 | 55 | - **目标点击跟踪(含目标检测、目标跟踪)** 56 | 57 | 58 | - **低延迟推流** 59 | 60 | 61 | 62 | ## 版权声明 63 | 64 | - 本项目受 Apache License 2.0 协议保护。 65 | - 本项目仅限个人使用,请勿用于商业用途。 66 | - 如利用本项目进行营利活动,阿木实验室将追究侵权行为。 67 | -------------------------------------------------------------------------------- /algorithm/common_det/cuda/common_det_cuda_impl.h: -------------------------------------------------------------------------------- 1 | #ifndef __SV_COMMON_DET_CUDA__ 2 | #define __SV_COMMON_DET_CUDA__ 3 | 4 | #include "sv_core.h" 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | 11 | 12 | 13 | #ifdef WITH_CUDA 14 | #include 15 | #include 16 | #endif 17 | 18 | 19 | 20 | namespace sv { 21 | 22 | 23 | class CommonObjectDetectorCUDAImpl 24 | { 25 | public: 26 | CommonObjectDetectorCUDAImpl(); 27 | ~CommonObjectDetectorCUDAImpl(); 28 | 29 | bool cudaSetup(CommonObjectDetectorBase* base_, bool input_4k_); 30 | void cudaDetect( 31 | CommonObjectDetectorBase* base_, 32 | cv::Mat img_, 33 | std::vector& boxes_x_, 34 | std::vector& boxes_y_, 35 | std::vector& boxes_w_, 36 | std::vector& boxes_h_, 37 | std::vector& boxes_label_, 38 | std::vector& boxes_score_, 39 | std::vector& boxes_seg_, 40 | bool input_4k_ 41 | ); 42 | 43 | #ifdef WITH_CUDA 44 | void _prepare_buffers_seg(int input_h, int input_w, int batchsize); 45 | void _prepare_buffers(int input_h, int input_w, int batchsize); 46 | nvinfer1::IExecutionContext* _context; 47 | nvinfer1::IRuntime* _runtime; 48 | nvinfer1::ICudaEngine* _engine; 49 | cudaStream_t _stream; 50 | float* _gpu_buffers[3]; 51 | float* _cpu_output_buffer; 52 | float* _cpu_output_buffer1; 53 | float* _cpu_output_buffer2; 54 | #endif 55 | }; 56 | 57 | 58 | } 59 | #endif 60 | -------------------------------------------------------------------------------- /algorithm/common_det/cuda/yolov7/calibrator.cpp: -------------------------------------------------------------------------------- 1 | #include "calibrator.h" 2 | #include "cuda_utils.h" 3 | #include "utils.h" 4 | 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | 11 | static cv::Mat preprocess_img(cv::Mat& img, int input_w, int input_h) { 12 | int w, h, x, y; 13 | float r_w = input_w / (img.cols * 1.0); 14 | float r_h = input_h / (img.rows * 1.0); 15 | if (r_h > r_w) { 16 | w = input_w; 17 | h = r_w * img.rows; 18 | x = 0; 19 | y = (input_h - h) / 2; 20 | } else { 21 | w = r_h * img.cols; 22 | h = input_h; 23 | x = (input_w - w) / 2; 24 | y = 0; 25 | } 26 | cv::Mat re(h, w, CV_8UC3); 27 | cv::resize(img, re, re.size(), 0, 0, cv::INTER_LINEAR); 28 | cv::Mat out(input_h, input_w, CV_8UC3, cv::Scalar(128, 128, 128)); 29 | re.copyTo(out(cv::Rect(x, y, re.cols, re.rows))); 30 | return out; 31 | } 32 | 33 | Int8EntropyCalibrator2::Int8EntropyCalibrator2(int batchsize, int input_w, int input_h, const char* img_dir, const char* calib_table_name, const char* input_blob_name, bool read_cache) 34 | : batchsize_(batchsize), 35 | input_w_(input_w), 36 | input_h_(input_h), 37 | img_idx_(0), 38 | img_dir_(img_dir), 39 | calib_table_name_(calib_table_name), 40 | input_blob_name_(input_blob_name), 41 | read_cache_(read_cache) { 42 | input_count_ = 3 * input_w * input_h * batchsize; 43 | CUDA_CHECK(cudaMalloc(&device_input_, input_count_ * sizeof(float))); 44 | read_files_in_dir(img_dir, img_files_); 45 | } 46 | 47 | Int8EntropyCalibrator2::~Int8EntropyCalibrator2() { 48 | CUDA_CHECK(cudaFree(device_input_)); 49 | } 50 | 51 | int Int8EntropyCalibrator2::getBatchSize() const TRT_NOEXCEPT { 52 | return batchsize_; 53 | } 54 | 55 | bool Int8EntropyCalibrator2::getBatch(void* bindings[], const char* names[], int nbBindings) TRT_NOEXCEPT { 56 | if (img_idx_ + batchsize_ > (int)img_files_.size()) { 57 | return false; 58 | } 59 | 60 | std::vector input_imgs_; 61 | for (int i = img_idx_; i < img_idx_ + batchsize_; i++) { 62 | std::cout << img_files_[i] << " " << i << std::endl; 63 | cv::Mat temp = cv::imread(img_dir_ + img_files_[i]); 64 | if (temp.empty()) { 65 | std::cerr << "Fatal error: image cannot open!" << std::endl; 66 | return false; 67 | } 68 | cv::Mat pr_img = preprocess_img(temp, input_w_, input_h_); 69 | input_imgs_.push_back(pr_img); 70 | } 71 | img_idx_ += batchsize_; 72 | cv::Mat blob = cv::dnn::blobFromImages(input_imgs_, 1.0 / 255.0, cv::Size(input_w_, input_h_), cv::Scalar(0, 0, 0), true, false); 73 | 74 | CUDA_CHECK(cudaMemcpy(device_input_, blob.ptr(0), input_count_ * sizeof(float), cudaMemcpyHostToDevice)); 75 | assert(!strcmp(names[0], input_blob_name_)); 76 | bindings[0] = device_input_; 77 | return true; 78 | } 79 | 80 | const void* Int8EntropyCalibrator2::readCalibrationCache(size_t& length) TRT_NOEXCEPT { 81 | std::cout << "reading calib cache: " << calib_table_name_ << std::endl; 82 | calib_cache_.clear(); 83 | std::ifstream input(calib_table_name_, std::ios::binary); 84 | input >> std::noskipws; 85 | if (read_cache_ && input.good()) { 86 | std::copy(std::istream_iterator(input), std::istream_iterator(), std::back_inserter(calib_cache_)); 87 | } 88 | length = calib_cache_.size(); 89 | return length ? calib_cache_.data() : nullptr; 90 | } 91 | 92 | void Int8EntropyCalibrator2::writeCalibrationCache(const void* cache, size_t length) TRT_NOEXCEPT { 93 | std::cout << "writing calib cache: " << calib_table_name_ << " size: " << length << std::endl; 94 | std::ofstream output(calib_table_name_, std::ios::binary); 95 | output.write(reinterpret_cast(cache), length); 96 | } 97 | 98 | -------------------------------------------------------------------------------- /algorithm/common_det/cuda/yolov7/calibrator.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "macros.h" 4 | #include 5 | #include 6 | 7 | //! \class Int8EntropyCalibrator2 8 | //! 9 | //! \brief Implements Entropy calibrator 2. 10 | //! CalibrationAlgoType is kENTROPY_CALIBRATION_2. 11 | //! 12 | class Int8EntropyCalibrator2 : public nvinfer1::IInt8EntropyCalibrator2 { 13 | public: 14 | Int8EntropyCalibrator2(int batchsize, int input_w, int input_h, const char* img_dir, const char* calib_table_name, const char* input_blob_name, bool read_cache = true); 15 | 16 | virtual ~Int8EntropyCalibrator2(); 17 | int getBatchSize() const TRT_NOEXCEPT override; 18 | bool getBatch(void* bindings[], const char* names[], int nbBindings) TRT_NOEXCEPT override; 19 | const void* readCalibrationCache(size_t& length) TRT_NOEXCEPT override; 20 | void writeCalibrationCache(const void* cache, size_t length) TRT_NOEXCEPT override; 21 | 22 | private: 23 | int batchsize_; 24 | int input_w_; 25 | int input_h_; 26 | int img_idx_; 27 | std::string img_dir_; 28 | std::vector img_files_; 29 | size_t input_count_; 30 | std::string calib_table_name_; 31 | const char* input_blob_name_; 32 | bool read_cache_; 33 | void* device_input_; 34 | std::vector calib_cache_; 35 | }; 36 | 37 | -------------------------------------------------------------------------------- /algorithm/common_det/cuda/yolov7/config.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | /* -------------------------------------------------------- 4 | * These configs are related to tensorrt model, if these are changed, 5 | * please re-compile and re-serialize the tensorrt model. 6 | * --------------------------------------------------------*/ 7 | 8 | // For INT8, you need prepare the calibration dataset, please refer to 9 | // https://github.com/wang-xinyu/tensorrtx/tree/master/yolov5#int8-quantization 10 | #define USE_FP16 // set USE_INT8 or USE_FP16 or USE_FP32 11 | 12 | // These are used to define input/output tensor names, 13 | // you can set them to whatever you want. 14 | const static char* kInputTensorName = "data"; 15 | const static char* kOutputTensorName = "prob"; 16 | 17 | // Detection model and Segmentation model' number of classes 18 | // constexpr static int kNumClass = 80; 19 | 20 | // Classfication model's number of classes 21 | constexpr static int kClsNumClass = 1000; 22 | 23 | constexpr static int kBatchSize = 1; 24 | 25 | // Yolo's input width and height must by divisible by 32 26 | // constexpr static int kInputH = 640; 27 | // constexpr static int kInputW = 640; 28 | 29 | // Classfication model's input shape 30 | constexpr static int kClsInputH = 224; 31 | constexpr static int kClsInputW = 224; 32 | 33 | // Maximum number of output bounding boxes from yololayer plugin. 34 | // That is maximum number of output bounding boxes before NMS. 35 | constexpr static int kMaxNumOutputBbox = 1000; 36 | 37 | constexpr static int kNumAnchor = 3; 38 | 39 | // The bboxes whose confidence is lower than kIgnoreThresh will be ignored in yololayer plugin. 40 | constexpr static float kIgnoreThresh = 0.1f; 41 | 42 | /* -------------------------------------------------------- 43 | * These configs are NOT related to tensorrt model, if these are changed, 44 | * please re-compile, but no need to re-serialize the tensorrt model. 45 | * --------------------------------------------------------*/ 46 | 47 | // NMS overlapping thresh and final detection confidence thresh 48 | const static float kNmsThresh = 0.45f; 49 | const static float kConfThresh = 0.5f; 50 | 51 | const static int kGpuId = 0; 52 | 53 | // If your image size is larger than 4096 * 3112, please increase this value 54 | const static int kMaxInputImageSize = 4096 * 3112; 55 | 56 | -------------------------------------------------------------------------------- /algorithm/common_det/cuda/yolov7/cuda_utils.h: -------------------------------------------------------------------------------- 1 | #ifndef TRTX_CUDA_UTILS_H_ 2 | #define TRTX_CUDA_UTILS_H_ 3 | 4 | #include 5 | 6 | #ifndef CUDA_CHECK 7 | #define CUDA_CHECK(callstr)\ 8 | {\ 9 | cudaError_t error_code = callstr;\ 10 | if (error_code != cudaSuccess) {\ 11 | std::cerr << "CUDA error " << error_code << " at " << __FILE__ << ":" << __LINE__;\ 12 | assert(0);\ 13 | }\ 14 | } 15 | #endif // CUDA_CHECK 16 | 17 | #endif // TRTX_CUDA_UTILS_H_ 18 | 19 | -------------------------------------------------------------------------------- /algorithm/common_det/cuda/yolov7/macros.h: -------------------------------------------------------------------------------- 1 | #ifndef __MACROS_H 2 | #define __MACROS_H 3 | 4 | #include 5 | 6 | #ifdef API_EXPORTS 7 | #if defined(_MSC_VER) 8 | #define API __declspec(dllexport) 9 | #else 10 | #define API __attribute__((visibility("default"))) 11 | #endif 12 | #else 13 | 14 | #if defined(_MSC_VER) 15 | #define API __declspec(dllimport) 16 | #else 17 | #define API 18 | #endif 19 | #endif // API_EXPORTS 20 | 21 | #if NV_TENSORRT_MAJOR >= 8 22 | #define TRT_NOEXCEPT noexcept 23 | #define TRT_CONST_ENQUEUE const 24 | #else 25 | #define TRT_NOEXCEPT 26 | #define TRT_CONST_ENQUEUE 27 | #endif 28 | 29 | #endif // __MACROS_H 30 | -------------------------------------------------------------------------------- /algorithm/common_det/cuda/yolov7/model.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | 6 | nvinfer1::ICudaEngine* build_det_engine(unsigned int maxBatchSize, nvinfer1::IBuilder* builder, 7 | nvinfer1::IBuilderConfig* config, nvinfer1::DataType dt, 8 | float& gd, float& gw, std::string& wts_name, int input_h, int input_w, int n_classes); 9 | 10 | nvinfer1::ICudaEngine* build_det_p6_engine(unsigned int maxBatchSize, nvinfer1::IBuilder* builder, 11 | nvinfer1::IBuilderConfig* config, nvinfer1::DataType dt, 12 | float& gd, float& gw, std::string& wts_name, int input_h, int input_w, int n_classes); 13 | 14 | nvinfer1::ICudaEngine* build_cls_engine(unsigned int maxBatchSize, nvinfer1::IBuilder* builder, nvinfer1::IBuilderConfig* config, nvinfer1::DataType dt, float& gd, float& gw, std::string& wts_name); 15 | 16 | nvinfer1::ICudaEngine* build_seg_engine(unsigned int maxBatchSize, nvinfer1::IBuilder* builder, nvinfer1::IBuilderConfig* config, nvinfer1::DataType dt, float& gd, float& gw, std::string& wts_name, int input_h, int input_w, int n_classes); 17 | -------------------------------------------------------------------------------- /algorithm/common_det/cuda/yolov7/postprocess.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "types.h" 4 | #include 5 | 6 | cv::Rect get_rect(cv::Mat& img, float bbox[4], int input_h, int input_w); 7 | 8 | void nms(std::vector& res, float *output, float conf_thresh, float nms_thresh = 0.5); 9 | 10 | void batch_nms(std::vector>& batch_res, float *output, int batch_size, int output_size, float conf_thresh, float nms_thresh = 0.5); 11 | 12 | void draw_bbox(std::vector& img_batch, std::vector>& res_batch, int input_h, int input_w); 13 | 14 | std::vector process_mask(const float* proto, int proto_size, std::vector& dets, int input_h, int input_w); 15 | 16 | void draw_mask_bbox(cv::Mat& img, std::vector& dets, std::vector& masks, std::unordered_map& labels_map, int input_h, int input_w); 17 | -------------------------------------------------------------------------------- /algorithm/common_det/cuda/yolov7/preprocess.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | #include 6 | 7 | void cuda_preprocess_init(int max_image_size); 8 | void cuda_preprocess_destroy(); 9 | void cuda_preprocess(uint8_t* src, int src_width, int src_height, 10 | float* dst, int dst_width, int dst_height, 11 | cudaStream_t stream); 12 | void cuda_batch_preprocess(std::vector& img_batch, 13 | float* dst, int dst_width, int dst_height, 14 | cudaStream_t stream); 15 | 16 | -------------------------------------------------------------------------------- /algorithm/common_det/cuda/yolov7/types.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "config.h" 4 | 5 | struct YoloKernel { 6 | int width; 7 | int height; 8 | float anchors[kNumAnchor * 2]; 9 | }; 10 | 11 | struct alignas(float) Detection { 12 | float bbox[4]; // center_x center_y w h 13 | float conf; // bbox_conf * cls_conf 14 | float class_id; 15 | float mask[32]; 16 | }; 17 | 18 | -------------------------------------------------------------------------------- /algorithm/common_det/cuda/yolov7/utils.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | 11 | static inline int read_files_in_dir(const char* p_dir_name, std::vector& file_names) { 12 | DIR *p_dir = opendir(p_dir_name); 13 | if (p_dir == nullptr) { 14 | return -1; 15 | } 16 | 17 | struct dirent* p_file = nullptr; 18 | while ((p_file = readdir(p_dir)) != nullptr) { 19 | if (strcmp(p_file->d_name, ".") != 0 && 20 | strcmp(p_file->d_name, "..") != 0) { 21 | //std::string cur_file_name(p_dir_name); 22 | //cur_file_name += "/"; 23 | //cur_file_name += p_file->d_name; 24 | std::string cur_file_name(p_file->d_name); 25 | file_names.push_back(cur_file_name); 26 | } 27 | } 28 | 29 | closedir(p_dir); 30 | return 0; 31 | } 32 | 33 | // Function to trim leading and trailing whitespace from a string 34 | static inline std::string trim_leading_whitespace(const std::string& str) { 35 | size_t first = str.find_first_not_of(' '); 36 | if (std::string::npos == first) { 37 | return str; 38 | } 39 | size_t last = str.find_last_not_of(' '); 40 | return str.substr(first, (last - first + 1)); 41 | } 42 | 43 | // Src: https://stackoverflow.com/questions/16605967 44 | static inline std::string to_string_with_precision(const float a_value, const int n = 2) { 45 | std::ostringstream out; 46 | out.precision(n); 47 | out << std::fixed << a_value; 48 | return out.str(); 49 | } 50 | 51 | static inline int read_labels(const std::string labels_filename, std::unordered_map& labels_map) { 52 | 53 | std::ifstream file(labels_filename); 54 | // Read each line of the file 55 | std::string line; 56 | int index = 0; 57 | while (std::getline(file, line)) { 58 | // Strip the line of any leading or trailing whitespace 59 | line = trim_leading_whitespace(line); 60 | 61 | // Add the stripped line to the labels_map, using the loop index as the key 62 | labels_map[index] = line; 63 | index++; 64 | } 65 | // Close the file 66 | file.close(); 67 | 68 | return 0; 69 | } 70 | 71 | -------------------------------------------------------------------------------- /algorithm/common_det/intel/common_det_intel_impl.h: -------------------------------------------------------------------------------- 1 | #ifndef __SV_COMMON_DET_INTEL__ 2 | #define __SV_COMMON_DET_INTEL__ 3 | 4 | #include "sv_core.h" 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | 13 | #ifdef WITH_INTEL 14 | #include 15 | #endif 16 | 17 | struct Resize 18 | { 19 | cv::Mat resized_image; 20 | int dw; 21 | int dh; 22 | }; 23 | 24 | struct Detection 25 | { 26 | int class_id; 27 | float confidence; 28 | cv::Rect box; 29 | }; 30 | 31 | namespace sv 32 | { 33 | 34 | class CommonObjectDetectorIntelImpl 35 | { 36 | public: 37 | CommonObjectDetectorIntelImpl(); 38 | ~CommonObjectDetectorIntelImpl(); 39 | 40 | bool intelSetup(CommonObjectDetectorBase *base_, bool input_4k_); 41 | void intelDetect( 42 | CommonObjectDetectorBase *base_, 43 | cv::Mat img_, 44 | std::vector &boxes_x_, 45 | std::vector &boxes_y_, 46 | std::vector &boxes_w_, 47 | std::vector &boxes_h_, 48 | std::vector &boxes_label_, 49 | std::vector &boxes_score_, 50 | std::vector &boxes_seg_, 51 | bool input_4k_); 52 | void preprocess_img(cv::Mat &img_); 53 | void preprocess_img_seg(cv::Mat &img_, std::vector &paddings); 54 | void postprocess_img_seg(cv::Mat &img_, 55 | std::vector &paddings, 56 | std::vector &boxes_x_, 57 | std::vector &boxes_y_, 58 | std::vector &boxes_w_, 59 | std::vector &boxes_h_, 60 | std::vector &boxes_label_, 61 | std::vector &boxes_score_, 62 | std::vector &boxes_seg_, 63 | double &thrs_conf, 64 | double &thrs_nms); 65 | 66 | void postprocess_img(std::vector &boxes_x_, 67 | std::vector &boxes_y_, 68 | std::vector &boxes_w_, 69 | std::vector &boxes_h_, 70 | std::vector &boxes_label_, 71 | std::vector &boxes_score_, 72 | double &thrs_conf, 73 | double &thrs_nms); 74 | 75 | #ifdef WITH_INTEL 76 | int inpWidth; 77 | int inpHeight; 78 | bool with_segmentation; 79 | float rx; // the width ratio of original image and resized image 80 | float ry; // the height ratio of original image and resized image 81 | Resize resize; 82 | ov::Tensor input_tensor; 83 | ov::InferRequest infer_request; 84 | ov::CompiledModel compiled_model; 85 | #endif 86 | }; 87 | 88 | } 89 | #endif 90 | -------------------------------------------------------------------------------- /algorithm/common_det/sv_common_det.cpp: -------------------------------------------------------------------------------- 1 | #include "sv_common_det.h" 2 | #include 3 | #include 4 | 5 | #ifdef WITH_CUDA 6 | #include 7 | #include 8 | #include "common_det_cuda_impl.h" 9 | #endif 10 | 11 | #ifdef WITH_INTEL 12 | #include 13 | #include "common_det_intel_impl.h" 14 | #endif 15 | 16 | namespace sv { 17 | 18 | 19 | CommonObjectDetector::CommonObjectDetector(bool input_4k) 20 | { 21 | this->_input_4k = input_4k; 22 | #ifdef WITH_CUDA 23 | this->_cuda_impl = new CommonObjectDetectorCUDAImpl; 24 | #endif 25 | 26 | #ifdef WITH_INTEL 27 | this->_intel_impl = new CommonObjectDetectorIntelImpl; 28 | #endif 29 | } 30 | CommonObjectDetector::~CommonObjectDetector() 31 | { 32 | } 33 | 34 | bool CommonObjectDetector::setupImpl() 35 | { 36 | #ifdef WITH_CUDA 37 | return this->_cuda_impl->cudaSetup(this, this->_input_4k); 38 | #endif 39 | 40 | #ifdef WITH_INTEL 41 | return this->_intel_impl->intelSetup(this, this->_input_4k); 42 | #endif 43 | return false; 44 | } 45 | 46 | void CommonObjectDetector::detectImpl( 47 | cv::Mat img_, 48 | std::vector& boxes_x_, 49 | std::vector& boxes_y_, 50 | std::vector& boxes_w_, 51 | std::vector& boxes_h_, 52 | std::vector& boxes_label_, 53 | std::vector& boxes_score_, 54 | std::vector& boxes_seg_ 55 | ) 56 | { 57 | #ifdef WITH_CUDA 58 | this->_cuda_impl->cudaDetect( 59 | this, 60 | img_, 61 | boxes_x_, 62 | boxes_y_, 63 | boxes_w_, 64 | boxes_h_, 65 | boxes_label_, 66 | boxes_score_, 67 | boxes_seg_, 68 | this->_input_4k); 69 | #endif 70 | 71 | #ifdef WITH_INTEL 72 | this->_intel_impl->intelDetect( 73 | this, 74 | img_, 75 | boxes_x_, 76 | boxes_y_, 77 | boxes_w_, 78 | boxes_h_, 79 | boxes_label_, 80 | boxes_score_, 81 | boxes_seg_, 82 | this->_input_4k); 83 | #endif 84 | } 85 | 86 | } 87 | 88 | -------------------------------------------------------------------------------- /algorithm/landing_det/cuda/landing_det_cuda_impl.h: -------------------------------------------------------------------------------- 1 | #ifndef __SV_LANDING_DET_CUDA__ 2 | #define __SV_LANDING_DET_CUDA__ 3 | 4 | #include "sv_core.h" 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | 11 | 12 | 13 | #ifdef WITH_CUDA 14 | #include 15 | #include 16 | #endif 17 | 18 | 19 | 20 | namespace sv { 21 | 22 | 23 | class LandingMarkerDetectorCUDAImpl 24 | { 25 | public: 26 | LandingMarkerDetectorCUDAImpl(); 27 | ~LandingMarkerDetectorCUDAImpl(); 28 | 29 | bool cudaSetup(); 30 | void cudaRoiCNN( 31 | std::vector& input_rois_, 32 | std::vector& output_labels_ 33 | ); 34 | 35 | #ifdef WITH_CUDA 36 | float *_p_data; 37 | float *_p_prob; 38 | nvinfer1::IExecutionContext *_trt_context; 39 | int _input_index; 40 | int _output_index; 41 | void *_p_buffers[2]; 42 | cudaStream_t _cu_stream; 43 | #endif 44 | }; 45 | 46 | 47 | } 48 | #endif 49 | -------------------------------------------------------------------------------- /algorithm/landing_det/intel/landing_det_intel_impl.cpp: -------------------------------------------------------------------------------- 1 | #include "landing_det_intel_impl.h" 2 | #include 3 | #include 4 | #include "sv_util.h" 5 | 6 | #define SV_MODEL_DIR "/SpireCV/models/" 7 | #define SV_ROOT_DIR "/SpireCV/" 8 | 9 | namespace sv 10 | { 11 | 12 | #ifdef WITH_INTEL 13 | using namespace cv; 14 | using namespace std; 15 | using namespace dnn; 16 | #endif 17 | 18 | LandingMarkerDetectorIntelImpl::LandingMarkerDetectorIntelImpl() 19 | { 20 | } 21 | 22 | LandingMarkerDetectorIntelImpl::~LandingMarkerDetectorIntelImpl() 23 | { 24 | } 25 | 26 | bool LandingMarkerDetectorIntelImpl::intelSetup() 27 | { 28 | #ifdef WITH_INTEL 29 | std::string onnx_model_fn = get_home() + SV_MODEL_DIR + "LandingMarker.onnx"; 30 | std::vector files; 31 | list_dir(get_home() + SV_MODEL_DIR, files, "-online.onnx", "Int-LandingMarker-resnet34"); 32 | if (files.size() > 0) 33 | { 34 | std::sort(files.rbegin(), files.rend(), _comp_str_lesser); 35 | onnx_model_fn = get_home() + SV_MODEL_DIR + files[0]; 36 | } 37 | 38 | if (!is_file_exist(onnx_model_fn)) 39 | { 40 | throw std::runtime_error("SpireCV (104) Error loading the LandingMarker ONNX model (File Not Exist)"); 41 | } 42 | 43 | // OpenVINO 44 | ov::Core core; 45 | std::shared_ptr model = core.read_model(onnx_model_fn); 46 | ov::preprocess::PrePostProcessor ppp = ov::preprocess::PrePostProcessor(model); 47 | ppp.input().tensor().set_element_type(ov::element::u8).set_layout("NHWC").set_color_format(ov::preprocess::ColorFormat::RGB); 48 | ppp.input().preprocess().convert_element_type(ov::element::f32).convert_color(ov::preprocess::ColorFormat::RGB).scale({255, 255, 255}); // .scale({ 112, 112, 112 }); 49 | ppp.input().model().set_layout("NCHW"); 50 | ppp.output().tensor().set_element_type(ov::element::f32); 51 | model = ppp.build(); 52 | this->compiled_model = core.compile_model(model, "GPU"); 53 | this->infer_request = compiled_model.create_infer_request(); 54 | 55 | return true; 56 | #endif 57 | return false; 58 | } 59 | 60 | void LandingMarkerDetectorIntelImpl::intelRoiCNN( 61 | std::vector &input_rois_, 62 | std::vector &output_labels_) 63 | { 64 | #ifdef WITH_INTEL 65 | output_labels_.clear(); 66 | 67 | for (int i = 0; i < input_rois_.size(); i++) 68 | { 69 | cv::Mat e_roi = input_rois_[i]; 70 | 71 | // Get input port for model with one input 72 | auto input_port = compiled_model.input(); 73 | // Create tensor from external memory 74 | ov::Tensor input_tensor(input_port.get_element_type(), input_port.get_shape(), e_roi.ptr(0)); 75 | // Set input tensor for model with one input 76 | infer_request.set_input_tensor(input_tensor); 77 | //preprocess_img(e_roi); 78 | 79 | // infer_request.infer(); 80 | infer_request.start_async(); 81 | infer_request.wait(); 82 | 83 | const ov::Tensor &output_tensor = infer_request.get_output_tensor(); 84 | ov::Shape output_shape = output_tensor.get_shape(); 85 | this->_p_prob = output_tensor.data(); 86 | 87 | // Find max index 88 | double max = 0; 89 | int label = 0; 90 | for (int i = 0; i < 11; ++i) 91 | { 92 | if (max < this->_p_prob[i]) 93 | { 94 | max = this->_p_prob[i]; 95 | label = i; 96 | } 97 | } 98 | output_labels_.push_back(label); 99 | } 100 | 101 | #endif 102 | } 103 | 104 | } 105 | -------------------------------------------------------------------------------- /algorithm/landing_det/intel/landing_det_intel_impl.h: -------------------------------------------------------------------------------- 1 | #ifndef __SV_LANDING_DET_INTEL__ 2 | #define __SV_LANDING_DET_INTEL__ 3 | 4 | #include "sv_core.h" 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | 11 | #ifdef WITH_INTEL 12 | #include 13 | #endif 14 | 15 | namespace sv 16 | { 17 | class LandingMarkerDetectorIntelImpl 18 | { 19 | public: 20 | LandingMarkerDetectorIntelImpl(); 21 | ~LandingMarkerDetectorIntelImpl(); 22 | 23 | bool intelSetup(); 24 | void intelRoiCNN( 25 | std::vector &input_rois_, 26 | std::vector &output_labels_); 27 | 28 | #ifdef WITH_INTEL 29 | float *_p_prob; 30 | 31 | ov::Tensor input_tensor; 32 | ov::InferRequest infer_request; 33 | ov::CompiledModel compiled_model; 34 | #endif 35 | }; 36 | } 37 | #endif 38 | -------------------------------------------------------------------------------- /algorithm/landing_det/sv_landing_det.cpp: -------------------------------------------------------------------------------- 1 | #include "sv_landing_det.h" 2 | #include 3 | #include 4 | #ifdef WITH_CUDA 5 | #include 6 | #include 7 | #include "landing_det_cuda_impl.h" 8 | #endif 9 | 10 | #ifdef WITH_INTEL 11 | #include 12 | #include "landing_det_intel_impl.h" 13 | #endif 14 | 15 | namespace sv { 16 | 17 | 18 | LandingMarkerDetector::LandingMarkerDetector() 19 | { 20 | #ifdef WITH_CUDA 21 | this->_cuda_impl = new LandingMarkerDetectorCUDAImpl; 22 | #endif 23 | 24 | #ifdef WITH_INTEL 25 | this->_intel_impl = new LandingMarkerDetectorIntelImpl; 26 | #endif 27 | } 28 | LandingMarkerDetector::~LandingMarkerDetector() 29 | { 30 | } 31 | 32 | bool LandingMarkerDetector::setupImpl() 33 | { 34 | #ifdef WITH_CUDA 35 | return this->_cuda_impl->cudaSetup(); 36 | #endif 37 | 38 | #ifdef WITH_INTEL 39 | return this->_intel_impl->intelSetup(); 40 | #endif 41 | return false; 42 | } 43 | 44 | void LandingMarkerDetector::roiCNN( 45 | std::vector& input_rois_, 46 | std::vector& output_labels_ 47 | ) 48 | { 49 | #ifdef WITH_CUDA 50 | this->_cuda_impl->cudaRoiCNN( 51 | input_rois_, 52 | output_labels_ 53 | ); 54 | #endif 55 | 56 | #ifdef WITH_INTEL 57 | this->_intel_impl->intelRoiCNN( 58 | input_rois_, 59 | output_labels_ 60 | ); 61 | #endif 62 | } 63 | } 64 | 65 | -------------------------------------------------------------------------------- /algorithm/mde/cuda/depth_est_cuda_impl.h: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include "utils.h" 9 | #include "sv_core.h" 10 | 11 | #ifdef WITH_CUDA 12 | #include 13 | #include 14 | #endif 15 | 16 | namespace sv 17 | { 18 | class DepthEstimationCUDAImpl 19 | { 20 | public: 21 | DepthEstimationCUDAImpl(); 22 | ~DepthEstimationCUDAImpl(); 23 | 24 | void predict(cv::Mat& img_, cv::Mat& mde_); 25 | bool cudaSetup(MonocularDepthEstimationBase* base_); 26 | 27 | private: 28 | int input_w = 406; 29 | int input_h = 406; 30 | float mean[3] = { 123.675, 116.28, 103.53 }; 31 | float std[3] = { 58.395, 57.12, 57.375 }; 32 | 33 | std::vector offset; 34 | 35 | nvinfer1::IRuntime* runtime; 36 | nvinfer1::ICudaEngine* engine; 37 | nvinfer1::IExecutionContext* context; 38 | 39 | void* buffer[2]; 40 | float* depth_data; 41 | cudaStream_t stream; 42 | 43 | std::vector preprocess(cv::Mat& img_); 44 | }; 45 | } -------------------------------------------------------------------------------- /algorithm/mde/cuda/utils.cpp: -------------------------------------------------------------------------------- 1 | #include "utils.h" 2 | 3 | std::tuple resize_depth(cv::Mat& img, int w, int h) 4 | { 5 | cv::Mat result; 6 | int nw, nh; 7 | int ih = img.rows; 8 | int iw = img.cols; 9 | float aspectRatio = (float)img.cols / (float)img.rows; 10 | 11 | if (aspectRatio >= 1) 12 | { 13 | nw = w; 14 | nh = int(h / aspectRatio); 15 | } 16 | else 17 | { 18 | nw = int(w * aspectRatio); 19 | nh = h; 20 | } 21 | cv::resize(img, img, cv::Size(nw, nh)); 22 | result = cv::Mat::ones(cv::Size(w, h), CV_8UC1) * 128; 23 | cv::cvtColor(result, result, cv::COLOR_GRAY2RGB); 24 | cv::cvtColor(img, img, cv::COLOR_BGR2RGB); 25 | 26 | cv::Mat re(h, w, CV_8UC3); 27 | cv::resize(img, re, re.size(), 0, 0, cv::INTER_LINEAR); 28 | cv::Mat out(h, w, CV_8UC3, 0.0); 29 | re.copyTo(out(cv::Rect(0, 0, re.cols, re.rows))); 30 | 31 | std::tuple res_tuple = std::make_tuple(out, (w - nw) / 2, (h - nh) / 2); 32 | 33 | return res_tuple; 34 | } -------------------------------------------------------------------------------- /algorithm/mde/cuda/utils.h: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | 7 | struct DepthEstimation 8 | { 9 | int x; 10 | int y; 11 | int label; 12 | 13 | DepthEstimation() 14 | { 15 | x = 0; 16 | y = 0; 17 | label = -1; 18 | } 19 | }; 20 | 21 | 22 | std::tuple resize_depth(cv::Mat& img, int w, int h); 23 | 24 | -------------------------------------------------------------------------------- /algorithm/mde/sv_depth_est.cpp: -------------------------------------------------------------------------------- 1 | #include "sv_depth_est.h" 2 | #include 3 | #include 4 | #include "gason.h" 5 | #include "sv_util.h" 6 | 7 | #ifdef WITH_CUDA 8 | #include 9 | #include 10 | #include "depth_est_cuda_impl.h" 11 | #endif 12 | 13 | #define SV_ROOT_DIR "/SpireCV/" 14 | 15 | namespace sv 16 | { 17 | 18 | MonocularDepthEstimation::MonocularDepthEstimation() 19 | { 20 | #ifdef WITH_CUDA 21 | this->_cuda_impl = new DepthEstimationCUDAImpl; 22 | #endif 23 | } 24 | MonocularDepthEstimation::~MonocularDepthEstimation() 25 | { 26 | } 27 | 28 | bool MonocularDepthEstimation::setupImpl() 29 | { 30 | #ifdef WITH_CUDA 31 | return this->_cuda_impl->cudaSetup(this); 32 | #endif 33 | return false; 34 | } 35 | 36 | void MonocularDepthEstimation::predictImpl(cv::Mat img_, cv::Mat& mde_) 37 | { 38 | #ifdef WITH_CUDA 39 | this->_cuda_impl->predict(img_, mde_); 40 | #endif 41 | } 42 | 43 | } 44 | -------------------------------------------------------------------------------- /algorithm/mot/bytetrack/BYTETracker.h: -------------------------------------------------------------------------------- 1 | #ifndef __SV_BYTETrack__ 2 | #define __SV_BYTETrack__ 3 | 4 | #include "sv_core.h" 5 | #include "STrack.h" 6 | 7 | class detect_result 8 | { 9 | public: 10 | int classId; 11 | float confidence; 12 | cv::Rect_ box; 13 | }; 14 | 15 | namespace sv { 16 | 17 | class BYTETracker 18 | { 19 | public: 20 | BYTETracker(int frame_rate = 30, int track_buffer = 30); 21 | ~BYTETracker(); 22 | 23 | void update(TargetsInFrame &tgts); 24 | cv::Scalar get_color(int idx); 25 | 26 | private: 27 | std::vector joint_stracks( std::vector &tlista, std::vector &tlistb); 28 | std::vector joint_stracks( std::vector &tlista, std::vector &tlistb); 29 | 30 | std::vector sub_stracks( std::vector &tlista, std::vector &tlistb); 31 | void remove_duplicate_stracks( std::vector &resa, std::vector &resb, std::vector &stracksa, std::vector &stracksb); 32 | 33 | void linear_assignment( std::vector< std::vector > &cost_matrix, int cost_matrix_size, int cost_matrix_size_size, float thresh, 34 | std::vector< std::vector > &matches, std::vector &unmatched_a, std::vector &unmatched_b); 35 | std::vector< std::vector > iou_distance( std::vector &atracks, std::vector &btracks, int &dist_size, int &dist_size_size); 36 | std::vector< std::vector > iou_distance( std::vector &atracks, std::vector &btracks); 37 | std::vector< std::vector > ious( std::vector< std::vector > &atlbrs, std::vector< std::vector > &btlbrs); 38 | 39 | double lapjv(const std::vector< std::vector > &cost, std::vector &rowsol, std::vector &colsol, 40 | bool extend_cost = false, float cost_limit = LONG_MAX, bool return_cost = true); 41 | 42 | private: 43 | 44 | float track_thresh; 45 | float high_thresh; 46 | float match_thresh; 47 | int frame_id; 48 | int max_time_lost; 49 | 50 | std::vector tracked_stracks; 51 | std::vector lost_stracks; 52 | std::vector removed_stracks; 53 | byte_kalman::ByteKalmanFilter kalman_filter; 54 | }; 55 | } 56 | #endif -------------------------------------------------------------------------------- /algorithm/mot/bytetrack/BytekalmanFilter.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "dataType.h" 4 | 5 | namespace byte_kalman 6 | { 7 | class ByteKalmanFilter 8 | { 9 | public: 10 | static const double chi2inv95[10]; 11 | ByteKalmanFilter(); 12 | KAL_DATA initiate(const DETECTBOX& measurement); 13 | void predict(KAL_MEAN& mean, KAL_COVA& covariance); 14 | KAL_HDATA project(const KAL_MEAN& mean, const KAL_COVA& covariance); 15 | KAL_DATA update(const KAL_MEAN& mean, 16 | const KAL_COVA& covariance, 17 | const DETECTBOX& measurement); 18 | 19 | Eigen::Matrix gating_distance( 20 | const KAL_MEAN& mean, 21 | const KAL_COVA& covariance, 22 | const std::vector& measurements, 23 | bool only_position = false); 24 | 25 | private: 26 | Eigen::Matrix _motion_mat; 27 | Eigen::Matrix _update_mat; 28 | float _std_weight_position; 29 | float _std_weight_velocity; 30 | }; 31 | } -------------------------------------------------------------------------------- /algorithm/mot/bytetrack/STrack.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include "BytekalmanFilter.h" 5 | 6 | enum TrackState { New = 0, Tracked, Lost, Removed }; 7 | 8 | class STrack 9 | { 10 | public: 11 | STrack( std::vector tlwh_, float score); 12 | ~STrack(); 13 | 14 | std::vector static tlbr_to_tlwh( std::vector &tlbr); 15 | void static multi_predict( std::vector &stracks, byte_kalman::ByteKalmanFilter &kalman_filter); 16 | void static_tlwh(); 17 | void static_tlbr(); 18 | std::vector tlwh_to_xyah( std::vector tlwh_tmp); 19 | std::vector to_xyah(); 20 | void mark_lost(); 21 | void mark_removed(); 22 | int next_id(); 23 | int end_frame(); 24 | 25 | void activate(byte_kalman::ByteKalmanFilter &kalman_filter, int frame_id); 26 | void re_activate(STrack &new_track, int frame_id, bool new_id = false); 27 | void update(STrack &new_track, int frame_id); 28 | 29 | public: 30 | bool is_activated; 31 | int track_id; 32 | int state; 33 | 34 | std::vector _tlwh; 35 | std::vector tlwh; 36 | std::vector tlbr; 37 | int frame_id; 38 | int tracklet_len; 39 | int start_frame; 40 | 41 | KAL_MEAN mean; 42 | KAL_COVA covariance; 43 | float score; 44 | 45 | private: 46 | byte_kalman::ByteKalmanFilter kalman_filter; 47 | }; -------------------------------------------------------------------------------- /algorithm/mot/bytetrack/dataType.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | 6 | #include 7 | #include 8 | 9 | 10 | 11 | typedef Eigen::Matrix DETECTBOX; 12 | typedef Eigen::Matrix DETECTBOXSS; 13 | 14 | 15 | //Kalmanfilter 16 | typedef Eigen::Matrix KAL_FILTER; 17 | typedef Eigen::Matrix KAL_MEAN; 18 | typedef Eigen::Matrix KAL_COVA; 19 | typedef Eigen::Matrix KAL_HMEAN; 20 | typedef Eigen::Matrix KAL_HCOVA; 21 | using KAL_DATA = std::pair; 22 | using KAL_HDATA = std::pair; 23 | 24 | 25 | 26 | 27 | 28 | -------------------------------------------------------------------------------- /algorithm/mot/bytetrack/lapjv.h: -------------------------------------------------------------------------------- 1 | #ifndef LAPJV_H 2 | #define LAPJV_H 3 | 4 | #define LARGE 1000000 5 | 6 | #if !defined TRUE 7 | #define TRUE 1 8 | #endif 9 | #if !defined FALSE 10 | #define FALSE 0 11 | #endif 12 | 13 | #define NEW(x, t, n) if ((x = (t *)malloc(sizeof(t) * (n))) == 0) { return -1; } 14 | #define FREE(x) if (x != 0) { free(x); x = 0; } 15 | #define SWAP_INDICES(a, b) { int_t _temp_index = a; a = b; b = _temp_index; } 16 | 17 | #if 0 18 | #include 19 | #define ASSERT(cond) assert(cond) 20 | #define PRINTF(fmt, ...) printf(fmt, ##__VA_ARGS__) 21 | #define PRINT_COST_ARRAY(a, n) \ 22 | while (1) { \ 23 | printf(#a" = ["); \ 24 | if ((n) > 0) { \ 25 | printf("%f", (a)[0]); \ 26 | for (uint_t j = 1; j < n; j++) { \ 27 | printf(", %f", (a)[j]); \ 28 | } \ 29 | } \ 30 | printf("]\n"); \ 31 | break; \ 32 | } 33 | #define PRINT_INDEX_ARRAY(a, n) \ 34 | while (1) { \ 35 | printf(#a" = ["); \ 36 | if ((n) > 0) { \ 37 | printf("%d", (a)[0]); \ 38 | for (uint_t j = 1; j < n; j++) { \ 39 | printf(", %d", (a)[j]); \ 40 | } \ 41 | } \ 42 | printf("]\n"); \ 43 | break; \ 44 | } 45 | #else 46 | #define ASSERT(cond) 47 | #define PRINTF(fmt, ...) 48 | #define PRINT_COST_ARRAY(a, n) 49 | #define PRINT_INDEX_ARRAY(a, n) 50 | #endif 51 | 52 | 53 | typedef signed int int_t; 54 | typedef unsigned int uint_t; 55 | typedef double cost_t; 56 | typedef char boolean; 57 | typedef enum fp_t { FP_1 = 1, FP_2 = 2, FP_DYNAMIC = 3 } fp_t; 58 | 59 | extern int_t lapjv_internal( 60 | const uint_t n, cost_t *cost[], 61 | int_t *x, int_t *y); 62 | 63 | #endif // LAPJV_H -------------------------------------------------------------------------------- /algorithm/mot/sort/sort.h: -------------------------------------------------------------------------------- 1 | #ifndef __SV_SORT__ 2 | #define __SV_SORT__ 3 | 4 | #include "sv_core.h" 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | 12 | 13 | namespace sv { 14 | 15 | 16 | 17 | // define the tracklet struct to store the tracked objects. 18 | struct Tracklet 19 | { 20 | /* data */ 21 | public: 22 | Eigen::Vector4d bbox; // double x, y, w, h; 23 | int id = 0; 24 | int age; 25 | int hits; 26 | int misses; 27 | int frame_id = 0; 28 | int category_id; 29 | bool tentative; 30 | std::vector features; 31 | Eigen::Matrix mean; 32 | Eigen::Matrix covariance; 33 | }; 34 | 35 | 36 | class KalmanFilter { 37 | public: 38 | KalmanFilter(); 39 | ~KalmanFilter(); 40 | std::pair, Eigen::Matrix > initiate(Eigen::Vector4d &bbox); 41 | std::pair, Eigen::Matrix > update(Eigen::Matrix mean, Eigen::Matrix covariances, Box &box); 42 | std::pair, Eigen::Matrix > predict(Eigen::Matrix mean, Eigen::Matrix covariances); 43 | std::pair, Eigen::Matrix > project(Eigen::Matrix mean, Eigen::Matrix covariances); 44 | private: 45 | Eigen::Matrix _F; 46 | Eigen::Matrix _H; 47 | Eigen::Matrix _chi2inv95; 48 | double _std_weight_position; 49 | double _std_weight_vel; 50 | }; 51 | 52 | 53 | class SORT { 54 | public: 55 | SORT(double iou_threshold, int max_age, int min_hits): _iou_threshold(iou_threshold), _max_age(max_age), _min_hits(min_hits), _next_tracklet_id(0) {}; 56 | ~SORT(); 57 | void update(TargetsInFrame &tgts); 58 | std::vector getTracklets() const; 59 | private: 60 | double _iou(Tracklet &tracklet, Box &box); 61 | std::vector> _hungarian(std::vector> costMatrix); 62 | double _findMin(const std::vector& vec); 63 | void _subtractMinFromRows(std::vector>& costMatrix); 64 | void _subtractMinFromCols(std::vector>& costMatrix); 65 | //bool _augment(const std::vector>& costMatrix, int row, std::vector& rowMatch, std::vector& colMatch, std::vector& visited); 66 | 67 | double _iou_threshold; 68 | int _max_age; 69 | int _min_hits; 70 | int _next_tracklet_id; 71 | std::vector _tracklets; 72 | std::vector _new_tracklets; 73 | }; 74 | 75 | 76 | } 77 | #endif 78 | -------------------------------------------------------------------------------- /algorithm/sot/ocv470/sot_ocv470_impl.h: -------------------------------------------------------------------------------- 1 | #ifndef __SV_TRACKING_OCV470__ 2 | #define __SV_TRACKING_OCV470__ 3 | 4 | #include "sv_core.h" 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | 11 | 12 | 13 | namespace sv { 14 | 15 | 16 | class SingleObjectTrackerOCV470Impl 17 | { 18 | public: 19 | SingleObjectTrackerOCV470Impl(); 20 | ~SingleObjectTrackerOCV470Impl(); 21 | 22 | bool ocv470Setup(SingleObjectTrackerBase* base_); 23 | void ocv470Init(cv::Mat img_, const cv::Rect& bounding_box_); 24 | bool ocv470Track(cv::Mat img_, cv::Rect& output_bbox_); 25 | 26 | std::string _algorithm; 27 | int _backend; 28 | int _target; 29 | 30 | #ifdef WITH_OCV470 31 | cv::Ptr _siam_rpn; 32 | cv::Ptr _kcf; 33 | cv::Ptr _csrt; 34 | cv::Ptr _nano; 35 | #endif 36 | }; 37 | 38 | 39 | } 40 | #endif 41 | -------------------------------------------------------------------------------- /algorithm/sot/sv_sot.cpp: -------------------------------------------------------------------------------- 1 | #include "sv_sot.h" 2 | #include 3 | #include 4 | #include "sot_ocv470_impl.h" 5 | 6 | 7 | namespace sv { 8 | 9 | 10 | SingleObjectTracker::SingleObjectTracker() 11 | { 12 | this->_ocv470_impl = new SingleObjectTrackerOCV470Impl; 13 | } 14 | SingleObjectTracker::~SingleObjectTracker() 15 | { 16 | } 17 | 18 | bool SingleObjectTracker::setupImpl() 19 | { 20 | #ifdef WITH_OCV470 21 | return this->_ocv470_impl->ocv470Setup(this); 22 | #endif 23 | return false; 24 | } 25 | void SingleObjectTracker::initImpl(cv::Mat img_, const cv::Rect& bounding_box_) 26 | { 27 | #ifdef WITH_OCV470 28 | this->_ocv470_impl->ocv470Init(img_, bounding_box_); 29 | #endif 30 | } 31 | bool SingleObjectTracker::trackImpl(cv::Mat img_, cv::Rect& output_bbox_) 32 | { 33 | #ifdef WITH_OCV470 34 | return this->_ocv470_impl->ocv470Track(img_, output_bbox_); 35 | #endif 36 | return false; 37 | } 38 | 39 | 40 | } 41 | 42 | -------------------------------------------------------------------------------- /algorithm/veri/cuda/veri_det_cuda_impl.h: -------------------------------------------------------------------------------- 1 | #ifndef __SV_VERI_DET_CUDA__ 2 | #define __SV_VERI_DET_CUDA__ 3 | 4 | #include "sv_core.h" 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | 11 | 12 | 13 | #ifdef WITH_CUDA 14 | #include 15 | #include 16 | #endif 17 | 18 | 19 | 20 | namespace sv { 21 | 22 | 23 | class VeriDetectorCUDAImpl 24 | { 25 | public: 26 | VeriDetectorCUDAImpl(); 27 | ~VeriDetectorCUDAImpl(); 28 | 29 | bool cudaSetup(); 30 | void cudaRoiCNN( 31 | std::vector& input_rois_, 32 | std::vector& output_labels_ 33 | ); 34 | 35 | #ifdef WITH_CUDA 36 | float *_p_data; 37 | float *_p_prob1; 38 | float *_p_prob2; 39 | nvinfer1::IExecutionContext *_trt_context; 40 | int _input_index; 41 | int _output_index1; 42 | int _output_index2; 43 | void *_p_buffers[3]; 44 | cudaStream_t _cu_stream; 45 | #endif 46 | }; 47 | 48 | 49 | } 50 | #endif 51 | -------------------------------------------------------------------------------- /algorithm/veri/intel/veri_det_intel_impl.cpp: -------------------------------------------------------------------------------- 1 | #include "veri_det_intel_impl.h" 2 | #include 3 | #include 4 | 5 | #define SV_MODEL_DIR "/SpireCV/models/" 6 | #define SV_ROOT_DIR "/SpireCV/" 7 | 8 | #include 9 | #include 10 | int BAT = 1; 11 | float cosineSimilarity(float *vec1, float *vec2, int size) 12 | { 13 | // 计算向量的点积 14 | float dotProduct = 0.0f; 15 | for (int i = 0; i < size; ++i) 16 | { 17 | dotProduct += vec1[i] * vec2[i]; 18 | } 19 | 20 | // 计算向量的模长 21 | float magnitudeVec1 = 0.0f; 22 | float magnitudeVec2 = 0.0f; 23 | for (int i = 0; i < size; ++i) 24 | { 25 | magnitudeVec1 += vec1[i] * vec1[i]; 26 | magnitudeVec2 += vec2[i] * vec2[i]; 27 | } 28 | magnitudeVec1 = std::sqrt(magnitudeVec1); 29 | magnitudeVec2 = std::sqrt(magnitudeVec2); 30 | 31 | // 计算余弦相似性 32 | float similarity = dotProduct / (magnitudeVec1 * magnitudeVec2); 33 | 34 | return similarity; 35 | } 36 | 37 | namespace sv 38 | { 39 | #ifdef WITH_INTEL 40 | using namespace cv; 41 | using namespace std; 42 | using namespace dnn; 43 | #endif 44 | 45 | VeriDetectorIntelImpl::VeriDetectorIntelImpl() 46 | { 47 | } 48 | 49 | VeriDetectorIntelImpl::~VeriDetectorIntelImpl() 50 | { 51 | } 52 | 53 | bool VeriDetectorIntelImpl::intelSetup() 54 | { 55 | #ifdef WITH_INTEL 56 | std::string onnx_model_fn = get_home() + SV_MODEL_DIR + "veri.onnx"; 57 | if (!is_file_exist(onnx_model_fn)) 58 | { 59 | throw std::runtime_error("SpireCV (104) Error loading the VeriDetector openVINO model (File Not Exist)"); 60 | } 61 | 62 | // OpenVINO 63 | ov::Core core; 64 | this->compiled_model = core.compile_model(onnx_model_fn, "GPU"); 65 | this->infer_request = compiled_model.create_infer_request(); 66 | 67 | return true; 68 | #endif 69 | return false; 70 | } 71 | 72 | void VeriDetectorIntelImpl::intelRoiCNN( 73 | std::vector &input_rois_, 74 | std::vector &output_labels_) 75 | { 76 | #ifdef WITH_INTEL 77 | 78 | Mat blobs; 79 | blobFromImages(input_rois_, blobs, 1 / 255.0, Size(224, 224), Scalar(0, 0, 0), true, true); 80 | 81 | auto input_port = compiled_model.input(); 82 | ov::Tensor input_tensor(input_port.get_element_type(), input_port.get_shape(), blobs.ptr(0)); 83 | 84 | infer_request.infer(); 85 | 86 | const ov::Tensor &label_pre = infer_request.get_output_tensor(0); 87 | this->_p_prob1 = label_pre.data(); 88 | 89 | const ov::Tensor &proto_pre = infer_request.get_output_tensor(1); 90 | this->_p_prob2 = proto_pre.data(); 91 | 92 | // Find max index 93 | double max = 0; 94 | int label = 0; 95 | for (int i = 0; i < 576; ++i) 96 | { 97 | if (max < this->_p_prob1[i]) 98 | { 99 | max = this->_p_prob1[i]; 100 | label = i; 101 | } 102 | } 103 | 104 | float similarity = cosineSimilarity(this->_p_prob2, this->_p_prob2 + 1280, 1280); 105 | 106 | output_labels_.push_back(label); 107 | output_labels_.push_back(similarity); 108 | #endif 109 | } 110 | 111 | 112 | } 113 | -------------------------------------------------------------------------------- /algorithm/veri/intel/veri_det_intel_impl.h: -------------------------------------------------------------------------------- 1 | #ifndef __SV_VERI_DET_INTEL__ 2 | #define __SV_VERI_DET_INTEL__ 3 | 4 | #include "sv_core.h" 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | 11 | #ifdef WITH_INTEL 12 | #include 13 | #endif 14 | 15 | namespace sv 16 | { 17 | class VeriDetectorIntelImpl 18 | { 19 | public: 20 | VeriDetectorIntelImpl(); 21 | ~VeriDetectorIntelImpl(); 22 | 23 | bool intelSetup(); 24 | void intelRoiCNN( 25 | std::vector &input_rois_, 26 | std::vector &output_labels_); 27 | 28 | #ifdef WITH_INTEL 29 | 30 | float *_p_data; 31 | float *_p_prob1; 32 | float *_p_prob2; 33 | 34 | ov::Tensor input_tensor; 35 | ov::InferRequest infer_request; 36 | ov::CompiledModel compiled_model; 37 | #endif 38 | }; 39 | 40 | } 41 | #endif 42 | -------------------------------------------------------------------------------- /build_on_jetson.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash -e 2 | 3 | rm -rf build 4 | mkdir build 5 | cd build 6 | cmake .. -DPLATFORM=JETSON 7 | make -j4 8 | sudo make install 9 | 10 | -------------------------------------------------------------------------------- /build_on_x86_cuda.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash -e 2 | 3 | rm -rf build 4 | mkdir build 5 | cd build 6 | cmake .. -DPLATFORM=X86_CUDA 7 | make -j4 8 | sudo make install 9 | 10 | -------------------------------------------------------------------------------- /build_on_x86_intel.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash -e 2 | 3 | rm -rf build 4 | mkdir build 5 | cd build 6 | cmake .. -DPLATFORM=X86_INTEL 7 | make -j4 8 | sudo make install 9 | 10 | -------------------------------------------------------------------------------- /gimbal_ctrl/IOs/serial/README.md: -------------------------------------------------------------------------------- 1 | # Serial Communication Library 2 | 3 | [![Build Status](https://travis-ci.org/wjwwood/serial.svg?branch=master)](https://travis-ci.org/wjwwood/serial)*(Linux and OS X)* [![Build Status](https://ci.appveyor.com/api/projects/status/github/wjwwood/serial)](https://ci.appveyor.com/project/wjwwood/serial)*(Windows)* 4 | 5 | This is a cross-platform library for interfacing with rs-232 serial like ports written in C++. It provides a modern C++ interface with a workflow designed to look and feel like PySerial, but with the speed and control provided by C++. 6 | 7 | This library is in use in several robotics related projects and can be built and installed to the OS like most unix libraries with make and then sudo make install, but because it is a catkin project it can also be built along side other catkin projects in a catkin workspace. 8 | 9 | Serial is a class that provides the basic interface common to serial libraries (open, close, read, write, etc..) and requires no extra dependencies. It also provides tight control over timeouts and control over handshaking lines. 10 | 11 | ### Documentation 12 | 13 | Website: http://wjwwood.github.io/serial/ 14 | 15 | API Documentation: http://wjwwood.github.io/serial/doc/1.1.0/index.html 16 | 17 | ### Dependencies 18 | 19 | Required: 20 | * [catkin](http://www.ros.org/wiki/catkin) - cmake and Python based buildsystem 21 | * [cmake](http://www.cmake.org) - buildsystem 22 | * [Python](http://www.python.org) - scripting language 23 | * [empy](http://www.alcyone.com/pyos/empy/) - Python templating library 24 | * [catkin_pkg](http://pypi.python.org/pypi/catkin_pkg/) - Runtime Python library for catkin 25 | 26 | Optional (for documentation): 27 | * [Doxygen](http://www.doxygen.org/) - Documentation generation tool 28 | * [graphviz](http://www.graphviz.org/) - Graph visualization software 29 | 30 | ### Install 31 | 32 | Get the code: 33 | 34 | git clone https://github.com/wjwwood/serial.git 35 | 36 | Build: 37 | 38 | make 39 | 40 | Build and run the tests: 41 | 42 | make test 43 | 44 | Build the documentation: 45 | 46 | make doc 47 | 48 | Install: 49 | 50 | make install 51 | 52 | ### License 53 | 54 | [The MIT License](LICENSE) 55 | 56 | ### Authors 57 | 58 | William Woodall 59 | John Harrison 60 | 61 | ### Contact 62 | 63 | William Woodall 64 | -------------------------------------------------------------------------------- /gimbal_ctrl/IOs/serial/include/serial/v8stdint.h: -------------------------------------------------------------------------------- 1 | // This header is from the v8 google project: 2 | // http://code.google.com/p/v8/source/browse/trunk/include/v8stdint.h 3 | 4 | // Copyright 2012 the V8 project authors. All rights reserved. 5 | // Redistribution and use in source and binary forms, with or without 6 | // modification, are permitted provided that the following conditions are 7 | // met: 8 | // 9 | // * Redistributions of source code must retain the above copyright 10 | // notice, this list of conditions and the following disclaimer. 11 | // * Redistributions in binary form must reproduce the above 12 | // copyright notice, this list of conditions and the following 13 | // disclaimer in the documentation and/or other materials provided 14 | // with the distribution. 15 | // * Neither the name of Google Inc. nor the names of its 16 | // contributors may be used to endorse or promote products derived 17 | // from this software without specific prior written permission. 18 | // 19 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 20 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 21 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 22 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 23 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 24 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 25 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 26 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 27 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 28 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 29 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | 31 | // Load definitions of standard types. 32 | 33 | #ifndef V8STDINT_H_ 34 | #define V8STDINT_H_ 35 | 36 | #include 37 | #include 38 | 39 | #if defined(_WIN32) && !defined(__MINGW32__) 40 | 41 | typedef signed char int8_t; 42 | typedef unsigned char uint8_t; 43 | typedef short int16_t; // NOLINT 44 | typedef unsigned short uint16_t; // NOLINT 45 | typedef int int32_t; 46 | typedef unsigned int uint32_t; 47 | typedef __int64 int64_t; 48 | typedef unsigned __int64 uint64_t; 49 | // intptr_t and friends are defined in crtdefs.h through stdio.h. 50 | 51 | #else 52 | 53 | #include 54 | 55 | #endif 56 | 57 | #endif // V8STDINT_H_ 58 | -------------------------------------------------------------------------------- /gimbal_ctrl/driver/src/AT10/AT10_gimbal_crc32.h: -------------------------------------------------------------------------------- 1 | /* 2 | * @Description: 3 | * @Author: L LC @amov 4 | * @Date: 2022-10-27 18:10:06 5 | * @LastEditors: L LC @amov 6 | * @LastEditTime: 2023-12-05 16:30:27 7 | * @FilePath: /SpireCV/gimbal_ctrl/driver/src/AT10/AT10_gimbal_crc32.h 8 | */ 9 | #ifndef AT10_GIMBAL_CRC32_H 10 | #define AT10_GIMBAL_CRC32_H 11 | 12 | namespace AT10 13 | { 14 | static inline unsigned char CheckSum(unsigned char *pData, unsigned short Lenght) 15 | { 16 | unsigned short temp = 0; 17 | unsigned short i = 0; 18 | for (i = 0; i < Lenght; i++) 19 | { 20 | temp += pData[i]; 21 | } 22 | return temp & 0XFF; 23 | } 24 | 25 | static inline unsigned char checkXOR(unsigned char *pData, unsigned char Lenght) 26 | { 27 | unsigned char temp = Lenght; 28 | unsigned char i; 29 | for (i = 1; i < Lenght - 1; i++) 30 | { 31 | temp ^= pData[i]; 32 | } 33 | return temp; 34 | } 35 | 36 | } // namespace name 37 | 38 | #endif -------------------------------------------------------------------------------- /gimbal_ctrl/driver/src/AT10/AT10_gimbal_driver.h: -------------------------------------------------------------------------------- 1 | /* 2 | * @Description: Q10f吊舱的驱动文件 3 | * @Author: L LC @amov 4 | * @Date: 2022-10-28 12:24:21 5 | * @LastEditors: L LC @amov 6 | * @LastEditTime: 2023-12-06 10:27:48 7 | * @FilePath: /SpireCV/gimbal_ctrl/driver/src/AT10/AT10_gimbal_driver.h 8 | */ 9 | #ifndef __AT10_DRIVER_H 10 | #define __AT10_DRIVER_H 11 | #include "../amov_gimbal_private.h" 12 | #include "AT10_gimbal_struct.h" 13 | #include 14 | #include 15 | #include 16 | 17 | class AT10GimbalDriver : protected amovGimbal::amovGimbalBase 18 | { 19 | private: 20 | AT10::GIMBAL_SERIAL_STATE_T parserState; 21 | AT10::GIMBAL_EXTEND_FRAME_T extendRx; 22 | 23 | AT10::GIMBAL_STD_FRAME_T stdRx; 24 | fifoRing *stdRxQueue; 25 | fifoRing *stdTxQueue; 26 | 27 | // void send(void); 28 | 29 | void stackStart(void); 30 | void sendHeart(void); 31 | void sendStd(void); 32 | 33 | void parserStart(pAmovGimbalStateInvoke callback, void *caller); 34 | void parserLoop(void); 35 | void getExtRxPack(void); 36 | void getStdRxPack(void); 37 | 38 | std::thread::native_handle_type sendHreatThreadHandle; 39 | std::thread::native_handle_type extStackThreadHandle; 40 | 41 | bool parser(IN uint8_t byte); 42 | void convert(void *buf); 43 | uint32_t pack(IN uint32_t cmd, uint8_t *pPayload, uint8_t payloadSize); 44 | uint32_t calPackLen(void *pack); 45 | 46 | public: 47 | // funtions 48 | uint32_t setGimabalPos(const AMOV_GIMBAL_POS_T &pos); 49 | uint32_t setGimabalSpeed(const AMOV_GIMBAL_POS_T &speed); 50 | uint32_t setGimabalFollowSpeed(const AMOV_GIMBAL_POS_T &followSpeed); 51 | uint32_t setGimabalHome(void); 52 | 53 | uint32_t setGimbalZoom(AMOV_GIMBAL_ZOOM_T zoom, float targetRate = 0); 54 | uint32_t setGimbalFocus(AMOV_GIMBAL_ZOOM_T zoom, float targetRate = 0); 55 | 56 | uint32_t takePic(void); 57 | uint32_t setVideo(const AMOV_GIMBAL_VIDEO_T newState); 58 | 59 | uint32_t extensionFuntions(void *cmd); 60 | 61 | // builds 62 | static amovGimbal::amovGimbalBase *creat(amovGimbal::IOStreamBase *_IO) 63 | { 64 | return new AT10GimbalDriver(_IO); 65 | } 66 | 67 | AT10GimbalDriver(amovGimbal::IOStreamBase *_IO); 68 | ~AT10GimbalDriver() 69 | { 70 | if (stdRxQueue != nullptr) 71 | { 72 | delete stdRxQueue; 73 | } 74 | if (stdTxQueue != nullptr) 75 | { 76 | delete stdTxQueue; 77 | } 78 | // set thread kill anytime 79 | pthread_setcanceltype(PTHREAD_CANCEL_ASYNCHRONOUS, NULL); 80 | parserThreadHanle = parserThreadHanle == 0 ? 0 : pthread_cancel(parserThreadHanle); 81 | sendThreadHanle = sendThreadHanle == 0 ? 0 : pthread_cancel(sendThreadHanle); 82 | stackThreadHanle = stackThreadHanle == 0 ? 0 : pthread_cancel(stackThreadHanle); 83 | sendHreatThreadHandle = sendHreatThreadHandle == 0 ? 0 : pthread_cancel(sendHreatThreadHandle); 84 | extStackThreadHandle = extStackThreadHandle == 0 ? 0 : pthread_cancel(extStackThreadHandle); 85 | } 86 | }; 87 | 88 | #endif 89 | -------------------------------------------------------------------------------- /gimbal_ctrl/driver/src/FIFO/Ring_Fifo.h: -------------------------------------------------------------------------------- 1 | /* 2 | * @Description : 3 | * @Author : Aiyangsky 4 | * @Date : 2022-08-26 21:42:02 5 | * @LastEditors: L LC @amov 6 | * @LastEditTime: 2023-11-28 11:47:39 7 | * @FilePath: /SpireCV/gimbal_ctrl/driver/src/FIFO/Ring_Fifo.h 8 | */ 9 | 10 | #ifndef RING_FIFO_H 11 | #define RING_FIFO_H 12 | 13 | #include 14 | #include 15 | #include 16 | #include 17 | 18 | class fifoRing 19 | { 20 | private: 21 | unsigned char *start; 22 | unsigned char *in; 23 | unsigned char *out; 24 | unsigned char *end; 25 | 26 | unsigned short currNumber; 27 | unsigned short maxNumber; 28 | unsigned short cellSize; 29 | 30 | std::mutex fifoMutex; 31 | std::condition_variable_any notEmpty; 32 | 33 | public: 34 | fifoRing(unsigned short _cellSize, unsigned int _cellNum); 35 | ~fifoRing() 36 | { 37 | if (start != nullptr) 38 | { 39 | free(start); 40 | } 41 | } 42 | 43 | bool inCell(void *data); 44 | unsigned short inCells(void *data, unsigned short number); 45 | bool outCell(void *data); 46 | unsigned short outCells(void *data, unsigned short number); 47 | }; 48 | 49 | #endif -------------------------------------------------------------------------------- /gimbal_ctrl/driver/src/G1/g1_gimbal_driver.h: -------------------------------------------------------------------------------- 1 | /* 2 | * @Description: G1吊舱的驱动文件 3 | * @Author: L LC @amov 4 | * @Date: 2022-10-28 12:24:21 5 | * @LastEditors: L LC @amov 6 | * @LastEditTime: 2023-12-05 16:29:58 7 | * @FilePath: /SpireCV/gimbal_ctrl/driver/src/G1/g1_gimbal_driver.h 8 | */ 9 | #ifndef __G1_DRIVER_H 10 | #define __G1_DRIVER_H 11 | 12 | #include "../amov_gimbal_private.h" 13 | #include "g1_gimbal_struct.h" 14 | #include 15 | #include 16 | #include 17 | 18 | class g1GimbalDriver : protected amovGimbal::amovGimbalBase 19 | { 20 | private: 21 | G1::GIMBAL_CMD_PARSER_STATE_T parserState; 22 | G1::GIMBAL_FRAME_T rx; 23 | 24 | uint32_t pack(IN uint32_t cmd, uint8_t *pPayload, uint8_t payloadSize); 25 | bool parser(IN uint8_t byte); 26 | void convert(void *buf); 27 | uint32_t calPackLen(void *pack); 28 | 29 | public: 30 | // funtions 31 | uint32_t setGimabalPos(const AMOV_GIMBAL_POS_T &pos); 32 | uint32_t setGimabalSpeed(const AMOV_GIMBAL_POS_T &speed); 33 | uint32_t setGimabalFollowSpeed(const AMOV_GIMBAL_POS_T &followSpeed); 34 | uint32_t setGimabalHome(void); 35 | 36 | uint32_t takePic(void); 37 | uint32_t setVideo(const AMOV_GIMBAL_VIDEO_T newState); 38 | 39 | uint32_t attitudeCorrection(const AMOV_GIMBAL_QUATERNION_T &quaterion, 40 | const AMOV_GIMBAL_VELOCITY_T &speed, 41 | const AMOV_GIMBAL_VELOCITY_T &acc, 42 | void *extenData); 43 | 44 | uint32_t attitudeCorrection(const AMOV_GIMBAL_POS_T &pos, 45 | const AMOV_GIMBAL_VELOCITY_T &seppd, 46 | const AMOV_GIMBAL_VELOCITY_T &acc, 47 | void *extenData); 48 | uint32_t extensionFuntions(void *cmd); 49 | 50 | // builds 51 | static amovGimbal::amovGimbalBase *creat(amovGimbal::IOStreamBase *_IO) 52 | { 53 | return new g1GimbalDriver(_IO); 54 | } 55 | 56 | g1GimbalDriver(amovGimbal::IOStreamBase *_IO); 57 | }; 58 | 59 | #endif 60 | -------------------------------------------------------------------------------- /gimbal_ctrl/driver/src/G1/g1_gimbal_struct.h: -------------------------------------------------------------------------------- 1 | /* 2 | * @Description: 3 | * @Author: L LC @amov 4 | * @Date: 2022-10-27 18:10:07 5 | * @LastEditors: L LC @amov 6 | * @LastEditTime: 2023-12-05 16:29:48 7 | * @FilePath: /SpireCV/gimbal_ctrl/driver/src/G1/g1_gimbal_struct.h 8 | */ 9 | #ifndef G1_GIMBAL_STRUCT_H 10 | #define G1_GIMBAL_STRUCT_H 11 | 12 | #include 13 | namespace G1 14 | { 15 | #define G1_MAX_GIMBAL_PAYLOAD 256 16 | #define G1_PAYLOAD_OFFSET 5 17 | #define G1_SCALE_FACTOR 0.01f 18 | #define G1_SERIAL_HEAD 0XAE 19 | #define G1_SERIAL_VERSION 0X01 20 | 21 | typedef enum 22 | { 23 | GIMBAL_CMD_SET_STATE = 0X01, 24 | GIMBAL_CMD_SET_POS = 0X85, 25 | GIMBAL_CMD_CAMERA = 0X86, 26 | GIMBAL_CMD_RCV_POS = 0X87 27 | } GIMBAL_CMD_T; 28 | 29 | typedef enum 30 | { 31 | GIMBAL_CMD_POS_MODE_SPEED = 1, 32 | GIMBAL_CMD_POS_MODE_ANGLE = 2, 33 | GIMBAL_CMD_POS_MODE_HOME = 3 34 | } GIMBAL_CMD_POS_MODE_T; 35 | 36 | typedef enum 37 | { 38 | GIMBAL_CMD_CAMERA_REC = 1, 39 | GIMBAL_CMD_CAMERA_TACK = 2 40 | } GIMBAL_CMD_CAMERA_T; 41 | 42 | typedef enum 43 | { 44 | GIMBAL_SERIAL_STATE_IDLE, 45 | GIMBAL_SERIAL_STATE_VERSION, 46 | GIMBAL_SERIAL_STATE_LENGHT, 47 | GIMBAL_SERIAL_STATE_CMD, 48 | GIMBAL_SERIAL_STATE_CHECK, 49 | GIMBAL_SERIAL_STATE_PAYLOAD, 50 | } GIMBAL_CMD_PARSER_STATE_T; 51 | 52 | #pragma pack(1) 53 | typedef struct 54 | { 55 | uint8_t head; 56 | uint8_t version; 57 | uint8_t lenght; 58 | uint8_t cmd; 59 | uint8_t checksum; 60 | uint8_t payload[G1_MAX_GIMBAL_PAYLOAD + sizeof(uint32_t)]; 61 | union 62 | { 63 | uint8_t u8[4]; 64 | uint32_t u32; 65 | } crc; 66 | } GIMBAL_FRAME_T; 67 | 68 | typedef struct 69 | { 70 | uint8_t mode; 71 | int16_t angle_roll; 72 | int16_t angle_pitch; 73 | int16_t angle_yaw; 74 | int16_t speed_roll; 75 | int16_t speed_pitch; 76 | int16_t speed_yaw; 77 | } GIMBAL_SET_POS_MSG_T; 78 | 79 | typedef struct 80 | { 81 | int16_t IMU_roll; 82 | int16_t IMU_pitch; 83 | int16_t IMU_yaw; 84 | int16_t HALL_roll; 85 | int16_t HALL_pitch; 86 | int16_t HALL_yaw; 87 | } GIMBAL_RCV_POS_MSG_T; 88 | 89 | typedef struct 90 | { 91 | float q[4]; 92 | float acc[3]; 93 | float yawSetPoint; 94 | float yawSpeedSetPoint; 95 | } GIMBAL_ATT_CORR_MSG_T; 96 | 97 | 98 | typedef struct 99 | { 100 | uint8_t cmd; 101 | uint8_t data[256]; 102 | uint8_t len; 103 | }GIMBAL_STD_MSG_T; 104 | 105 | #pragma pack() 106 | 107 | } 108 | #endif -------------------------------------------------------------------------------- /gimbal_ctrl/driver/src/GX40/GX40_gimbal_crc16.h: -------------------------------------------------------------------------------- 1 | /* 2 | * @Description: 3 | * @Author: L LC @amov 4 | * @Date: 2023-10-20 16:33:07 5 | * @LastEditors: L LC @amov 6 | * @LastEditTime: 2023-12-05 16:29:39 7 | * @FilePath: /SpireCV/gimbal_ctrl/driver/src/GX40/GX40_gimbal_crc16.h 8 | */ 9 | #ifndef GX40_GIMBAL_CRC16_H 10 | #define GX40_GIMBAL_CRC16_H 11 | 12 | #include 13 | 14 | namespace GX40 15 | { 16 | const static uint16_t crc16Tab[16] = { 17 | 0x0000, 0x1021, 0x2042, 0x3063, 18 | 0x4084, 0x50a5, 0x60c6, 0x70e7, 19 | 0x8108, 0x9129, 0xa14a, 0xb16b, 20 | 0xc18c, 0xd1ad, 0xe1ce, 0xf1ef}; 21 | 22 | static inline uint16_t CalculateCrc16(const uint8_t *ptr, uint8_t len) 23 | { 24 | uint16_t crc = 0; 25 | uint8_t temp; 26 | 27 | while (len-- != 0) 28 | { 29 | temp = crc >> 12; 30 | crc <<= 4; 31 | crc ^= crc16Tab[temp ^ (*ptr >> 4)]; 32 | temp = crc >> 12; 33 | crc <<= 4; 34 | crc ^= crc16Tab[temp ^ (*ptr & 0x0F)]; 35 | ptr++; 36 | } 37 | crc = (crc >> 8) | (crc << 8); 38 | return (crc); 39 | } 40 | } 41 | #endif -------------------------------------------------------------------------------- /gimbal_ctrl/driver/src/GX40/GX40_gimbal_driver.h: -------------------------------------------------------------------------------- 1 | 2 | /* 3 | * @Description: 4 | * @Author: L LC @amov 5 | * @Date: 2023-10-20 16:08:13 6 | * @LastEditors: L LC @amov 7 | * @LastEditTime: 2023-12-06 10:27:05 8 | * @FilePath: /SpireCV/gimbal_ctrl/driver/src/GX40/GX40_gimbal_driver.h 9 | */ 10 | #ifndef __GX40_DRIVER_H 11 | #define __GX40_DRIVER_H 12 | #include "../amov_gimbal_private.h" 13 | #include "GX40_gimbal_struct.h" 14 | #include 15 | #include 16 | #include 17 | #include 18 | #include 19 | 20 | class GX40GimbalDriver : public amovGimbal::amovGimbalBase 21 | { 22 | GX40::GIMBAL_FRAME_PARSER_STATE_T parserState; 23 | GX40::GIMBAL_FRAME_T rx; 24 | 25 | std::chrono::milliseconds upDataTs; 26 | std::mutex carrierStateMutex; 27 | 28 | int16_t targetPos[3]; 29 | 30 | AMOV_GIMBAL_POS_T carrierPos; 31 | AMOV_GIMBAL_VELOCITY_T carrierSpeed; 32 | AMOV_GIMBAL_VELOCITY_T carrierAcc; 33 | GX40::GIMBAL_SECONDARY_MASTER_FRAME_T carrierGNSS; 34 | 35 | std::thread::native_handle_type nopSendThreadHandle; 36 | void nopSend(void); 37 | void parserStart(pAmovGimbalStateInvoke callback, void *caller); 38 | 39 | public: 40 | uint32_t pack(IN uint32_t cmd, uint8_t *pPayload, uint8_t payloadSize); 41 | bool parser(IN uint8_t byte); 42 | void convert(void *buf); 43 | uint32_t calPackLen(void *pack); 44 | 45 | // funtions 46 | uint32_t setGimabalPos(const AMOV_GIMBAL_POS_T &pos); 47 | uint32_t setGimabalSpeed(const AMOV_GIMBAL_POS_T &speed); 48 | uint32_t setGimabalHome(void); 49 | 50 | uint32_t setGimbalZoom(AMOV_GIMBAL_ZOOM_T zoom, float targetRate = 0); 51 | uint32_t setGimbalFocus(AMOV_GIMBAL_ZOOM_T zoom, float targetRate = 0); 52 | 53 | uint32_t takePic(void); 54 | uint32_t setVideo(const AMOV_GIMBAL_VIDEO_T newState); 55 | uint32_t attitudeCorrection(const AMOV_GIMBAL_POS_T &pos, 56 | const AMOV_GIMBAL_VELOCITY_T &seppd, 57 | const AMOV_GIMBAL_VELOCITY_T &acc, 58 | void *extenData); 59 | 60 | uint32_t setGNSSInfo(float lng, float lat, float alt, uint32_t nState, float relAlt); 61 | uint32_t extensionFuntions(void *cmd); 62 | static amovGimbal::amovGimbalBase *creat(amovGimbal::IOStreamBase *_IO) 63 | { 64 | return new GX40GimbalDriver(_IO); 65 | } 66 | GX40GimbalDriver(amovGimbal::IOStreamBase *_IO); 67 | ~GX40GimbalDriver() 68 | { 69 | if (txQueue != nullptr) 70 | { 71 | delete txQueue; 72 | } 73 | if (rxQueue != nullptr) 74 | { 75 | delete rxQueue; 76 | } 77 | 78 | pthread_setcanceltype(PTHREAD_CANCEL_ASYNCHRONOUS, NULL); 79 | parserThreadHanle = parserThreadHanle == 0 ? 0 : pthread_cancel(parserThreadHanle); 80 | sendThreadHanle = sendThreadHanle == 0 ? 0 : pthread_cancel(sendThreadHanle); 81 | stackThreadHanle = stackThreadHanle == 0 ? 0 : pthread_cancel(stackThreadHanle); 82 | nopSendThreadHandle = nopSendThreadHandle == 0 ? 0 : pthread_cancel(nopSendThreadHandle); 83 | } 84 | }; 85 | 86 | #endif 87 | -------------------------------------------------------------------------------- /gimbal_ctrl/driver/src/Q10f/Q10f_gimbal_crc32.h: -------------------------------------------------------------------------------- 1 | /* 2 | * @Description: 3 | * @Author: L LC @amov 4 | * @Date: 2022-10-27 18:10:06 5 | * @LastEditors: L LC @amov 6 | * @LastEditTime: 2023-12-05 16:28:29 7 | * @FilePath: /SpireCV/gimbal_ctrl/driver/src/Q10f/Q10f_gimbal_crc32.h 8 | */ 9 | #ifndef Q10F_GIMBAL_CRC32_H 10 | #define Q10F_GIMBAL_CRC32_H 11 | namespace Q10f 12 | { 13 | static inline unsigned char CheckSum(unsigned char *pData, unsigned short Lenght) 14 | { 15 | unsigned short temp = 0; 16 | unsigned short i = 0; 17 | for (i = 0; i < Lenght; i++) 18 | { 19 | temp += pData[i]; 20 | } 21 | return temp & 0XFF; 22 | } 23 | 24 | } // namespace name 25 | 26 | #endif -------------------------------------------------------------------------------- /gimbal_ctrl/driver/src/Q10f/Q10f_gimbal_driver.h: -------------------------------------------------------------------------------- 1 | /* 2 | * @Description: Q10f吊舱的驱动文件 3 | * @Author: L LC @amov 4 | * @Date: 2022-10-28 12:24:21 5 | * @LastEditors: L LC @amov 6 | * @LastEditTime: 2023-12-05 16:27:45 7 | * @FilePath: /SpireCV/gimbal_ctrl/driver/src/Q10f/Q10f_gimbal_driver.h 8 | */ 9 | #ifndef __Q10F_DRIVER_H 10 | #define __Q10F_DRIVER_H 11 | 12 | #include "../amov_gimbal_private.h" 13 | #include "Q10f_gimbal_struct.h" 14 | #include 15 | #include 16 | #include 17 | 18 | class Q10fGimbalDriver : protected amovGimbal::amovGimbalBase 19 | { 20 | private: 21 | Q10f::GIMBAL_SERIAL_STATE_T parserState; 22 | Q10f::GIMBAL_FRAME_T rx; 23 | 24 | bool parser(IN uint8_t byte); 25 | void convert(void *buf); 26 | uint32_t pack(IN uint32_t cmd, uint8_t *pPayload, uint8_t payloadSize); 27 | uint32_t calPackLen(void *pack); 28 | 29 | public: 30 | // funtions 31 | uint32_t setGimabalPos(const AMOV_GIMBAL_POS_T &pos); 32 | uint32_t setGimabalSpeed(const AMOV_GIMBAL_POS_T &speed); 33 | uint32_t setGimabalFollowSpeed(const AMOV_GIMBAL_POS_T &followSpeed); 34 | uint32_t setGimabalHome(void); 35 | 36 | uint32_t setGimbalZoom(AMOV_GIMBAL_ZOOM_T zoom, float targetRate = 0); 37 | uint32_t setGimbalFocus(AMOV_GIMBAL_ZOOM_T zoom, float targetRate = 0); 38 | 39 | uint32_t takePic(void); 40 | uint32_t setVideo(const AMOV_GIMBAL_VIDEO_T newState); 41 | 42 | // builds 43 | static amovGimbal::amovGimbalBase *creat(amovGimbal::IOStreamBase *_IO) 44 | { 45 | return new Q10fGimbalDriver(_IO); 46 | } 47 | 48 | Q10fGimbalDriver(amovGimbal::IOStreamBase *_IO); 49 | }; 50 | 51 | #endif 52 | -------------------------------------------------------------------------------- /gimbal_ctrl/driver/src/Q10f/Q10f_gimbal_struct.h: -------------------------------------------------------------------------------- 1 | /* 2 | * @Description: 3 | * @Author: L LC @amov 4 | * @Date: 2022-10-27 18:10:07 5 | * @LastEditors: L LC @amov 6 | * @LastEditTime: 2023-12-05 16:27:27 7 | * @FilePath: /SpireCV/gimbal_ctrl/driver/src/Q10f/Q10f_gimbal_struct.h 8 | */ 9 | #ifndef Q10F_GIMBAL_STRUCT_H 10 | #define Q10F_GIMBAL_STRUCT_H 11 | 12 | #include 13 | namespace Q10f 14 | { 15 | #define Q10F_MAX_GIMBAL_PAYLOAD 64 16 | #define Q10F_PAYLOAD_OFFSET 4 17 | #define Q10F_SCALE_FACTOR_ANGLE 0.02197f 18 | #define Q10F_SCALE_FACTOR_SPEED 0.06103f 19 | #define Q10F_MAX_ZOOM 10.0f 20 | #define Q10F_MAX_ZOOM_COUNT 0X4000 21 | 22 | typedef enum 23 | { 24 | GIMBAL_CMD_SET_POS = 0X100F01FF, 25 | GIMBAL_CMD_GET = 0X3D003D3E, 26 | GIMBAL_CMD_FOCUS = 0X08040181, 27 | GIMBAL_CMD_ZOOM = 0X07040181, 28 | GIMBAL_CMD_ZOOM_DIRECT = 0X47040181, 29 | GIMBAL_CMD_HOME = 0X010A0181, 30 | GIMBAL_CMD_CAMERA = 0X68040181, 31 | GIMBAL_CMD_RCV_STATE = 0X721A583E, 32 | GIMBAL_CMD_SET_FEEDBACK_L = 0X143055AA, 33 | GIMBAL_CMD_SET_FEEDBACK_H = 0X003155AA, 34 | GIMBAL_CMD_OPEN_FEEDBACK =0X3E003E3E, 35 | GIMBAL_CMD_CLOSE_FEEDBACK =0X3D003D3E, 36 | } GIMBAL_CMD_T; 37 | 38 | typedef enum 39 | { 40 | GIMBAL_CMD_POS_MODE_NO = 0X00, 41 | GIMBAL_CMD_POS_MODE_SPEED = 0X01, 42 | GIMBAL_CMD_POS_MODE_ANGLE = 0X02, 43 | GIMBAL_CMD_POS_MODE_ANGLE_SPEED = 0X03, 44 | } GIMBAL_CMD_POS_MODE_T; 45 | 46 | typedef enum 47 | { 48 | GIMBAL_CMD_ZOOM_IN = 0X27, 49 | GIMBAL_CMD_ZOOM_OUT = 0X37, 50 | GIMBAL_CMD_ZOOM_STOP = 0X00, 51 | } GIMBAL_CMD_ZOOM_T; 52 | 53 | typedef enum 54 | { 55 | GIMBAL_SERIAL_STATE_IDLE, 56 | GIMBAL_SERIAL_STATE_HEAD1, 57 | GIMBAL_SERIAL_STATE_HEAD2, 58 | GIMBAL_SERIAL_STATE_HEAD3, 59 | GIMBAL_SERIAL_STATE_DATE, 60 | GIMBAL_SERIAL_STATE_CHECK 61 | } GIMBAL_SERIAL_STATE_T; 62 | 63 | #pragma pack(1) 64 | typedef struct 65 | { 66 | uint32_t head; 67 | uint8_t data[Q10F_MAX_GIMBAL_PAYLOAD]; 68 | uint8_t checkSum; 69 | uint8_t len; 70 | } GIMBAL_FRAME_T; 71 | 72 | typedef struct 73 | { 74 | uint8_t modeR; 75 | uint8_t modeP; 76 | uint8_t modeY; 77 | int16_t speedR; 78 | int16_t angleR; 79 | int16_t speedP; 80 | int16_t angleP; 81 | int16_t speedY; 82 | int16_t angleY; 83 | } GIMBAL_SET_POS_MSG_T; 84 | 85 | typedef struct 86 | { 87 | uint16_t timeStamp; 88 | int16_t rollIMUAngle; 89 | int16_t pitchIMUAngle; 90 | int16_t yawIMUAngle; 91 | int16_t rollTAGAngle; 92 | int16_t pitchTAGAngle; 93 | int16_t yawTAGAngle; 94 | int16_t rollTAGSpeed; 95 | int16_t pitchTAGSpeed; 96 | int16_t yawTAGSpeed; 97 | int16_t rollStatorRotorAngle; 98 | int16_t pitchStatorRotorAngle; 99 | int16_t yawStatorRotorAngle; 100 | } GIMBAL_RCV_POS_MSG_T; 101 | 102 | #pragma pack() 103 | 104 | } 105 | #endif -------------------------------------------------------------------------------- /gimbal_ctrl/driver/src/SU17-G/SU17_gimbal_driver.h: -------------------------------------------------------------------------------- 1 | /* 2 | * @Description: 3 | * @Author: L LC @amov 4 | * @Date: 2023-03-01 10:02:24 5 | * @LastEditors: L LC @amov 6 | * @LastEditTime: 2023-12-05 18:03:11 7 | * @FilePath: /SpireCV/gimbal_ctrl/driver/src/SU17-G/SU17_gimbal_driver.h 8 | */ 9 | #ifndef __SU17_G_DRIVER_H 10 | #define __SU17_G_DRIVER_H 11 | #include "../amov_gimbal_private.h" 12 | #include "SU17_gimbal_struct.h" 13 | #include 14 | #include 15 | #include 16 | #include 17 | 18 | class su17GimbalDriver : protected amovGimbal::amovGimbalBase 19 | { 20 | private: 21 | SU17::GIMBAL_CMD_PARSER_STATE_T parserState; 22 | SU17::GIMBAL_FRAME_T rx; 23 | 24 | uint8_t self; 25 | uint8_t remote; 26 | 27 | bool parser(IN uint8_t byte); 28 | void convert(void *buf); 29 | uint32_t pack(IN uint32_t cmd, uint8_t *pPayload, uint8_t payloadSize); 30 | uint32_t calPackLen(void *pack); 31 | 32 | void heart(void); 33 | std::thread::native_handle_type heartThreadHandle; 34 | 35 | public: 36 | void nodeSet(SET uint32_t _self, SET uint32_t _remote) 37 | { 38 | self = _self; 39 | remote = _remote; 40 | } 41 | 42 | // funtion 43 | uint32_t setGimabalPos(const AMOV_GIMBAL_POS_T &pos); 44 | uint32_t setGimabalSpeed(const AMOV_GIMBAL_POS_T &speed); 45 | // uint32_t setGimabalFollowSpeed(const AMOV_GIMBAL_POS_T &followSpeed); 46 | // uint32_t setGimabalHome(void); 47 | 48 | uint32_t takePic(void); 49 | uint32_t setVideo(const AMOV_GIMBAL_VIDEO_T newState); 50 | 51 | static amovGimbal::amovGimbalBase *creat(amovGimbal::IOStreamBase *_IO) 52 | { 53 | return new su17GimbalDriver(_IO); 54 | } 55 | 56 | su17GimbalDriver(amovGimbal::IOStreamBase *_IO); 57 | 58 | ~su17GimbalDriver() 59 | { 60 | if (txQueue != nullptr) 61 | { 62 | delete txQueue; 63 | } 64 | if (rxQueue != nullptr) 65 | { 66 | delete rxQueue; 67 | } 68 | 69 | pthread_setcanceltype(PTHREAD_CANCEL_ASYNCHRONOUS, NULL); 70 | heartThreadHandle = heartThreadHandle == 0 ? 0 : pthread_cancel(heartThreadHandle); 71 | } 72 | }; 73 | 74 | #endif 75 | -------------------------------------------------------------------------------- /gimbal_ctrl/driver/src/SU17-G/SU17_gimbal_funtion.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * @Description: 3 | * @Author: L LC @amov 4 | * @Date: 2023-03-13 11:58:54 5 | * @LastEditors: L LC @amov 6 | * @LastEditTime: 2023-03-13 12:31:58 7 | * @FilePath: /SpireCV/gimbal_ctrl/driver/src/SU17-G/SU17_gimbal_funtion.cpp 8 | */ 9 | #include "SU17_gimbal_driver.h" 10 | #include "SU17_gimbal_crc.h" 11 | #include "string.h" 12 | 13 | /** 14 | * It sets the gimbal position. 15 | * 16 | * @param pos the position of the gimbal 17 | * 18 | * @return The return value is the number of bytes written to the buffer. 19 | */ 20 | uint32_t su17GimbalDriver::setGimabalPos(const AMOV_GIMBAL_POS_T &pos) 21 | { 22 | SU17::GIMBAL_SET_ATT_T temp; 23 | 24 | temp.mode = SU17::GIMBAL_CMD_MODE_POS; 25 | temp.att.pitch = pos.pitch / SU17_SCALE_FACTOR; 26 | temp.att.roll = pos.roll / SU17_SCALE_FACTOR; 27 | temp.att.yaw = pos.yaw / SU17_SCALE_FACTOR; 28 | return pack(SU17::GIMBAL_CMD_SET_POS, (uint8_t *)&temp, sizeof(temp)); 29 | } 30 | 31 | /** 32 | * It takes a struct of type AMOV_GIMBAL_POS_T and converts it to a struct of type 33 | * G1::GIMBAL_SET_POS_MSG_T 34 | * 35 | * @param speed the speed of the gimbal 36 | * 37 | * @return The return value is the number of bytes written to the buffer. 38 | */ 39 | uint32_t su17GimbalDriver::setGimabalSpeed(const AMOV_GIMBAL_POS_T &speed) 40 | { 41 | SU17::GIMBAL_SET_ATT_T temp; 42 | 43 | temp.mode = SU17::GIMBAL_CMD_MODE_SPEED; 44 | temp.att.pitchSpeed = speed.pitch / SU17_SCALE_FACTOR; 45 | temp.att.rollSpeed = speed.roll / SU17_SCALE_FACTOR; 46 | temp.att.yawSpeed = speed.yaw / SU17_SCALE_FACTOR; 47 | return pack(SU17::GIMBAL_CMD_SET_POS, (uint8_t *)&temp, sizeof(temp)); 48 | } 49 | 50 | /** 51 | * This function sets the gimbal's follow speed 52 | * 53 | * @param followSpeed the speed of the gimbal 54 | * 55 | * @return The return value is the number of bytes written to the buffer. 56 | */ 57 | // uint32_t su17GimbalDriver::setGimabalFollowSpeed(const AMOV_GIMBAL_POS_T &followSpeed) 58 | // { 59 | // return 0; 60 | // } 61 | 62 | /** 63 | * This function sets the gimbal to its home position 64 | * 65 | * @return The return value is the number of bytes written to the buffer. 66 | */ 67 | // uint32_t su17GimbalDriver::setGimabalHome(void) 68 | // { 69 | // return 0; 70 | // } 71 | 72 | /** 73 | * It takes a picture. 74 | * 75 | * @return The return value is the number of bytes written to the serial port. 76 | */ 77 | uint32_t su17GimbalDriver::takePic(void) 78 | { 79 | return pack(SU17::GIMBAL_CMD_TAKEPIC, nullptr, 0); 80 | } 81 | 82 | /** 83 | * The function sets the video state of the gimbal 84 | * 85 | * @param newState The new state of the video. 86 | * 87 | * @return The return value is the number of bytes written to the serial port. 88 | */ 89 | uint32_t su17GimbalDriver::setVideo(const AMOV_GIMBAL_VIDEO_T newState) 90 | { 91 | uint8_t cmd = 0; 92 | return pack(SU17::GIMBAL_CMD__VIDEO, &cmd, 1); 93 | } 94 | -------------------------------------------------------------------------------- /gimbal_ctrl/driver/src/SU17-G/SU17_gimbal_struct.h: -------------------------------------------------------------------------------- 1 | /* 2 | * @Description: 3 | * @Author: L LC @amov 4 | * @Date: 2023-03-01 09:21:57 5 | * @LastEditors: L LC @amov 6 | * @LastEditTime: 2023-04-18 10:13:23 7 | * @FilePath: /SpireCV/gimbal_ctrl/driver/src/SU17-G/SU17_gimbal_struct.h 8 | */ 9 | 10 | #ifndef SU17_G_GIMBAL_STRUCT_H 11 | #define SU17_G_GIMBAL_STRUCT_H 12 | 13 | #include 14 | 15 | namespace SU17 16 | { 17 | 18 | #define SU17_MAX_GIMBAL_PAYLOAD 64 19 | #define SU17_PAYLOAD_OFFSET 6 20 | #define SU17_SCALE_FACTOR 0.01f 21 | #define SU17_SERIAL_HEAD 0XAF 22 | #define SU17_SERIAL_VERSION 0X02 23 | 24 | typedef enum 25 | { 26 | GIMBAL_CMD_HEART = 20, 27 | GIMBAL_CMD_ATT = 160, 28 | GIMBAL_CMD_SET_POS = 162, 29 | GIMBAL_CMD_TAKEPIC = 180, 30 | GIMBAL_CMD__VIDEO = 181 31 | } GIMBAL_CMD_T; 32 | 33 | typedef enum 34 | { 35 | GIMBAL_SERIAL_STATE_IDEL = 0, 36 | GIMBAL_SERIAL_STATE_HEAD_RCV, 37 | GIMBAL_SERIAL_STATE_VERSION_RCV, 38 | GIMBAL_SERIAL_STATE_TARGET_RCV, 39 | GIMBAL_SERIAL_STATE_SOURCE_RCV, 40 | GIMBAL_SERIAL_STATE_LENGHT_RCV, 41 | GIMBAL_SERIAL_STATE_DATA_RCV, 42 | GIMBAL_SERIAL_STATE_CRC_RCV1, 43 | GIMBAL_SERIAL_STATE_END, 44 | } GIMBAL_CMD_PARSER_STATE_T; 45 | 46 | typedef enum 47 | { 48 | GIMBAL_CMD_MODE_POS = 0X01, 49 | GIMBAL_CMD_MODE_SPEED = 0X02, 50 | GIMBAL_CMD_MODE_MIX = 0X03 51 | } GIMBAL_CMD_MODE_T; 52 | 53 | #pragma pack(1) 54 | typedef struct 55 | { 56 | int16_t roll; 57 | int16_t pitch; 58 | int16_t yaw; 59 | int16_t rollSpeed; 60 | int16_t pitchSpeed; 61 | int16_t yawSpeed; 62 | } GIMBAL_ATT_T; 63 | 64 | typedef struct 65 | { 66 | uint8_t mode; 67 | GIMBAL_ATT_T att; 68 | } GIMBAL_SET_ATT_T; 69 | 70 | typedef struct 71 | { 72 | uint8_t head; 73 | uint8_t version; 74 | uint8_t target; 75 | uint8_t source; 76 | uint8_t len; 77 | uint8_t command; 78 | uint8_t data[SU17_MAX_GIMBAL_PAYLOAD]; 79 | union 80 | { 81 | uint8_t f8[2]; 82 | uint16_t f16; 83 | } crc; 84 | } GIMBAL_FRAME_T; 85 | #pragma pack(0) 86 | 87 | } 88 | #endif -------------------------------------------------------------------------------- /gimbal_ctrl/driver/src/amovGimbal/amov_gimbal_c.h: -------------------------------------------------------------------------------- 1 | /* 2 | * @Description: 3 | * @Author: L LC @amov 4 | * @Date: 2023-11-24 16:01:22 5 | * @LastEditors: L LC @amov 6 | * @LastEditTime: 2023-12-06 11:35:58 7 | * @FilePath: /SpireCV/gimbal_ctrl/driver/src/amovGimbal/amov_gimbal_c.h 8 | */ 9 | #ifndef AMOV_GIMBAL_C_H 10 | #define AMOV_GIMBAL_C_H 11 | 12 | #include 13 | #include "amov_gimbal_struct.h" 14 | 15 | extern "C" 16 | { 17 | // initialization funtions 18 | void amovGimbalCreat(char *type, uint32_t selfId, uint32_t gimbalId, void *handle); 19 | void amovGimbalInBytesCallback(uint8_t *pData, uint32_t len, void *handle); 20 | void amovGimbalSetRcvBytes(pAmovGimbalInputBytesInvoke callbaclk, void *handle, void *caller); 21 | void amovGimbalSetSendBytes(pAmovGimbalOutputBytesInvoke callbaclk, void *handle, void *caller); 22 | void amovGimbalChangeStateCallback(pAmovGimbalStateInvoke callback, void *handle, void *caller); 23 | void amovGimbalSetMsgCallback(pAmovGimbalMsgInvoke callback, void *handle, void *caller); 24 | void amovGimbalStart(pAmovGimbalStateInvoke callback, void *handle, void *caller); 25 | 26 | // non-block functions 27 | uint32_t amovGimbalSetGimabalPos(AMOV_GIMBAL_POS_T *pos, void *handle); 28 | uint32_t amovGimbalSetGimabalSpeed(AMOV_GIMBAL_POS_T *speed, void *handle); 29 | uint32_t amovGimbalSetGimabalFollowSpeed(AMOV_GIMBAL_POS_T *followSpeed, void *handle); 30 | uint32_t amovGimbalSetGimabalHome(void *handle); 31 | uint32_t amovGimbalSetGimbalZoom(AMOV_GIMBAL_ZOOM_T zoom, float targetRate, void *handle); 32 | uint32_t amovGimbalSetGimbalFocus(AMOV_GIMBAL_ZOOM_T zoom, float targetRate, void *handle); 33 | uint32_t amovGimbalSetGimbalROI(AMOV_GIMBAL_ROI_T *area, void *handle); 34 | uint32_t amovGimbalTakePic(void *handle); 35 | uint32_t amovGimbalSetVideo(AMOV_GIMBAL_VIDEO_T newState, void *handle); 36 | uint32_t amovGimbalAttitudeCorrectionQ(AMOV_GIMBAL_QUATERNION_T *quaterion, 37 | AMOV_GIMBAL_VELOCITY_T *speed, 38 | AMOV_GIMBAL_VELOCITY_T *acc, void *extenData, void *handle); 39 | uint32_t amovGimbalAttitudeCorrectionE(AMOV_GIMBAL_POS_T *pos, 40 | AMOV_GIMBAL_VELOCITY_T *speed, 41 | AMOV_GIMBAL_VELOCITY_T *acc, void *extenData, void *handle); 42 | uint32_t amovGimbalSetGNSSInfo(float lng, float lat, float alt, uint32_t nState, float relAlt, void *handle); 43 | uint32_t amovGimbalExtensionFuntions(void *cmd, void *handle); 44 | void getGimabalState(AMOV_GIMBAL_STATE_T *state, void *handle); 45 | void getGimbalType(char *type, void *handle); 46 | 47 | // block functions 48 | bool amovGimbalSetGimbalPosBlock(AMOV_GIMBAL_POS_T *pos, void *handle); 49 | bool amovGimbalSetGimabalHomeBlock(void *handle); 50 | bool amovGimbalSetGimbalZoomBlock(float targetRate, void *handle); 51 | bool amovGimbalTakePicBlock(void *handle); 52 | bool amovGimbalCalibrationBlock(void *handle); 53 | } 54 | 55 | #endif 56 | -------------------------------------------------------------------------------- /gimbal_ctrl/driver/src/amovGimbal/amov_gimbal_struct.h: -------------------------------------------------------------------------------- 1 | /* 2 | * @Description: Common Data Structures of gimbal 3 | * @Author: L LC @amov 4 | * @Date: 2022-10-31 11:56:43 5 | * @LastEditors: L LC @amov 6 | * @LastEditTime: 2023-12-05 17:03:02 7 | * @FilePath: /SpireCV/gimbal_ctrl/driver/src/amovGimbal/amov_gimbal_struct.h 8 | */ 9 | 10 | #include 11 | 12 | #ifndef __AMOV_GIMABL_STRUCT_H 13 | #define __AMOV_GIMABL_STRUCT_H 14 | 15 | typedef void (*pAmovGimbalStateInvoke)(double frameAngleRoll, double frameAnglePitch, double frameAngleYaw, 16 | double imuAngleRoll, double imuAnglePitch, double imuAngleYaw, 17 | double fovX, double fovY, void *caller); 18 | typedef void (*pAmovGimbalMsgInvoke)(void *msg, void *caller); 19 | typedef uint32_t (*pAmovGimbalInputBytesInvoke)(uint8_t *pData, void *caller); 20 | typedef uint32_t (*pAmovGimbalOutputBytesInvoke)(uint8_t *pData, uint32_t len, void *caller); 21 | 22 | typedef enum 23 | { 24 | AMOV_GIMBAL_SERVO_MODE_FPV = 0X10, 25 | AMOV_GIMBAL_SERVO_MODE_LOCK = 0X11, 26 | AMOV_GIMBAL_SERVO_MODE_FOLLOW = 0X12, 27 | AMOV_GIMBAL_SERVO_MODE_OVERLOOK = 0X13, 28 | AMOV_GIMBAL_SERVO_MODE_EULER = 0X14, 29 | AMOV_GIMBAL_SERVO_MODE_WATCH = 0X16, 30 | AMOV_GIMBAL_SERVO_MODE_TRACK = 0X17, 31 | } AMOV_GIMBAL_SERVO_MODE_T; 32 | 33 | typedef enum 34 | { 35 | AMOV_GIMBAL_CAMERA_FLAG_INVERSION = 0X1000, 36 | AMOV_GIMBAL_CAMERA_FLAG_IR = 0X0200, 37 | AMOV_GIMBAL_CAMERA_FLAG_RF = 0X0100, 38 | AMOV_GIMBAL_CAMERA_FLAG_LOCK = 0X0001, 39 | } AMOV_GIMBAL_CAMERA_FLAG_T; 40 | 41 | typedef enum 42 | { 43 | AMOV_GIMBAL_VIDEO_TAKE, 44 | AMOV_GIMBAL_VIDEO_OFF 45 | } AMOV_GIMBAL_VIDEO_T; 46 | 47 | typedef enum 48 | { 49 | AMOV_GIMBAL_ZOOM_IN, 50 | AMOV_GIMBAL_ZOOM_OUT, 51 | AMOV_GIMBAL_ZOOM_STOP 52 | } AMOV_GIMBAL_ZOOM_T; 53 | 54 | typedef struct 55 | { 56 | double yaw; 57 | double roll; 58 | double pitch; 59 | } AMOV_GIMBAL_POS_T; 60 | 61 | typedef struct 62 | { 63 | double x; 64 | double y; 65 | } AMOV_GIMBAL_FOV_T; 66 | 67 | typedef struct 68 | { 69 | AMOV_GIMBAL_SERVO_MODE_T workMode; 70 | AMOV_GIMBAL_CAMERA_FLAG_T cameraFlag; 71 | AMOV_GIMBAL_VIDEO_T video; 72 | AMOV_GIMBAL_POS_T abs; 73 | AMOV_GIMBAL_POS_T rel; 74 | AMOV_GIMBAL_POS_T relSpeed; 75 | AMOV_GIMBAL_POS_T maxFollow; 76 | AMOV_GIMBAL_FOV_T fov; 77 | } AMOV_GIMBAL_STATE_T; 78 | 79 | typedef struct 80 | { 81 | uint32_t centreX; 82 | uint32_t centreY; 83 | uint32_t hight; 84 | uint32_t width; 85 | } AMOV_GIMBAL_ROI_T; 86 | 87 | typedef struct 88 | { 89 | double q0; 90 | double q1; 91 | double q2; 92 | double q3; 93 | } AMOV_GIMBAL_QUATERNION_T; 94 | 95 | typedef struct 96 | { 97 | double x; // or N 98 | double y; // or E 99 | double z; // or UP 100 | } AMOV_GIMBAL_VELOCITY_T; 101 | 102 | #endif 103 | -------------------------------------------------------------------------------- /gimbal_ctrl/driver/src/amov_gimbal_factory.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * @Description: 3 | * @Author: L LC @amov 4 | * @Date: 2023-11-24 15:48:47 5 | * @LastEditors: L LC @amov 6 | * @LastEditTime: 2023-12-05 16:27:10 7 | * @FilePath: /SpireCV/gimbal_ctrl/driver/src/amov_gimbal_factory.cpp 8 | */ 9 | 10 | #include "amov_gimbal_private.h" 11 | #include "g1_gimbal_driver.h" 12 | #include "Q10f_gimbal_driver.h" 13 | #include "AT10_gimbal_driver.h" 14 | #include "GX40_gimbal_driver.h" 15 | #include "SU17_gimbal_driver.h" 16 | 17 | #include 18 | #include 19 | 20 | namespace amovGimbalFactory 21 | { 22 | typedef amovGimbal::amovGimbalBase *(*createCallback)(amovGimbal::IOStreamBase *_IO); 23 | typedef std::map callbackMap; 24 | 25 | callbackMap amovGimbals = 26 | { 27 | {"G1", g1GimbalDriver::creat}, 28 | {"Q10f", Q10fGimbalDriver::creat}, 29 | {"AT10", AT10GimbalDriver::creat}, 30 | {"GX40", GX40GimbalDriver::creat}, 31 | {"SU17", su17GimbalDriver::creat}}; 32 | 33 | /* The amovGimbalCreator class is a factory class that creates an instance of the amovGimbal class */ 34 | // Factory used to create the gimbal instance 35 | class amovGimbalCreator 36 | { 37 | public: 38 | static amovGimbal::amovGimbalBase *createAmovGimbal(const std::string &type, amovGimbal::IOStreamBase *_IO) 39 | { 40 | callbackMap::iterator temp = amovGimbals.find(type); 41 | 42 | if (temp != amovGimbals.end()) 43 | { 44 | return (temp->second)(_IO); 45 | } 46 | std::cout << type << " is Unsupported device type!" << std::endl; 47 | return NULL; 48 | } 49 | 50 | private: 51 | amovGimbalCreator() 52 | { 53 | } 54 | static amovGimbalCreator *pInstance; 55 | static amovGimbalCreator *getInstance() 56 | { 57 | if (pInstance == NULL) 58 | { 59 | pInstance = new amovGimbalCreator(); 60 | } 61 | return pInstance; 62 | } 63 | 64 | ~amovGimbalCreator(); 65 | }; 66 | } // namespace amovGimbalFactory 67 | 68 | /** 69 | * The function creates a new gimbal object, which is a pointer to a new amovGimbal object, which is a 70 | * pointer to a new Gimbal object, which is a pointer to a new IOStreamBase object 71 | * 72 | * @param type the type of the device, which is the same as the name of the class 73 | * @param _IO The IOStreamBase object that is used to communicate with the device. 74 | * @param _self the node ID of the device 75 | * @param _remote the node ID of the remote device 76 | */ 77 | amovGimbal::gimbal::gimbal(const std::string &type, IOStreamBase *_IO, 78 | uint32_t _self, uint32_t _remote) 79 | { 80 | typeName = type; 81 | 82 | devHandle = amovGimbalFactory::amovGimbalCreator::createAmovGimbal(typeName, _IO); 83 | 84 | ((amovGimbalBase *)(devHandle))->nodeSet(_self, _remote); 85 | } 86 | 87 | amovGimbal::gimbal::~gimbal() 88 | { 89 | // 先干掉请求线程 90 | std::this_thread::sleep_for(std::chrono::milliseconds(50)); 91 | delete ((amovGimbalBase *)(devHandle)); 92 | } 93 | -------------------------------------------------------------------------------- /gimbal_ctrl/driver/src/amov_tool.h: -------------------------------------------------------------------------------- 1 | /* 2 | * @Description: 3 | * @Author: L LC @amov 4 | * @Date: 2023-07-31 18:30:33 5 | * @LastEditors: L LC @amov 6 | * @LastEditTime: 2023-12-05 16:26:05 7 | * @FilePath: /SpireCV/gimbal_ctrl/driver/src/amov_tool.h 8 | */ 9 | 10 | #ifndef __AMOVGIMABL_TOOL_H 11 | #define __AMOVGIMABL_TOOL_H 12 | namespace amovGimbalTools 13 | { 14 | static inline unsigned short conversionBigLittle(unsigned short value) 15 | { 16 | unsigned short temp = 0; 17 | temp |= ((value >> 8) & 0X00FF); 18 | temp |= ((value << 8) & 0XFF00); 19 | return temp; 20 | } 21 | 22 | static inline unsigned int conversionBigLittle(unsigned int value) 23 | { 24 | unsigned int temp = 0; 25 | temp |= ((value << 24) & 0XFF000000); 26 | temp |= ((value << 8) & 0X00FF0000); 27 | temp |= ((value >> 8) & 0X0000FF00); 28 | temp |= ((value << 24) & 0X000000FF); 29 | return temp; 30 | } 31 | } 32 | #endif 33 | -------------------------------------------------------------------------------- /include/sv_color_line.h: -------------------------------------------------------------------------------- 1 | #ifndef __SV_COLOR_LINE__ 2 | #define __SV_COLOR_LINE__ 3 | 4 | #include "sv_core.h" 5 | #include 6 | #include 7 | #include 8 | 9 | namespace sv 10 | { 11 | 12 | 13 | class ColorLineDetector : public CameraAlgorithm 14 | { 15 | public: 16 | ColorLineDetector(); 17 | ~ColorLineDetector(); 18 | 19 | void detect(cv::Mat img_, TargetsInFrame &tgts_); 20 | 21 | cv::Point3d pose; 22 | 23 | double line_location; 24 | double line_location_a1; 25 | double line_location_a2; 26 | 27 | bool is_load_parameter; 28 | std::string line_color; 29 | 30 | protected: 31 | float _cy_a1; 32 | float _cy_a2; 33 | float _half_h; 34 | float _half_w; 35 | 36 | void _load(); 37 | float cnt_area(std::vector cnt_); 38 | void get_line_area(cv::Mat &frame_, cv::Mat &line_area_, cv::Mat &line_area_a1_, cv::Mat &line_area_a2_); 39 | void seg(cv::Mat line_area_, cv::Mat line_area_a1_, cv::Mat line_area_a2_, std::string line_color_, cv::Point ¢er_, int &area_, cv::Point ¢er_a1_, cv::Point ¢er_a2_); 40 | }; 41 | } 42 | #endif 43 | -------------------------------------------------------------------------------- /include/sv_common_det.h: -------------------------------------------------------------------------------- 1 | #ifndef __SV_COMMON_DET__ 2 | #define __SV_COMMON_DET__ 3 | 4 | #include "sv_core.h" 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | 11 | namespace sv 12 | { 13 | 14 | class CommonObjectDetectorCUDAImpl; 15 | class CommonObjectDetectorIntelImpl; 16 | 17 | 18 | class CommonObjectDetector : public CommonObjectDetectorBase 19 | { 20 | public: 21 | CommonObjectDetector(bool input_4k = false); 22 | ~CommonObjectDetector(); 23 | 24 | protected: 25 | bool setupImpl(); 26 | void detectImpl( 27 | cv::Mat img_, 28 | std::vector &boxes_x_, 29 | std::vector &boxes_y_, 30 | std::vector &boxes_w_, 31 | std::vector &boxes_h_, 32 | std::vector &boxes_label_, 33 | std::vector &boxes_score_, 34 | std::vector &boxes_seg_); 35 | 36 | CommonObjectDetectorCUDAImpl *_cuda_impl; 37 | CommonObjectDetectorIntelImpl *_intel_impl; 38 | 39 | bool _input_4k; 40 | }; 41 | 42 | } 43 | #endif 44 | -------------------------------------------------------------------------------- /include/sv_core.h: -------------------------------------------------------------------------------- 1 | #ifndef __SV_CORE__ 2 | #define __SV_CORE__ 3 | 4 | #include "sv_video_base.h" 5 | #include "sv_gimbal.h" 6 | #include "sv_algorithm_base.h" 7 | 8 | #endif 9 | -------------------------------------------------------------------------------- /include/sv_depth_est.h: -------------------------------------------------------------------------------- 1 | #ifndef __SV_DEPTH_EST__ 2 | #define __SV_DEPTH_EST__ 3 | 4 | #include "sv_core.h" 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | 11 | 12 | namespace sv { 13 | 14 | class DepthEstimationCUDAImpl; 15 | 16 | class MonocularDepthEstimation : public MonocularDepthEstimationBase 17 | { 18 | public: 19 | MonocularDepthEstimation(); 20 | ~MonocularDepthEstimation(); 21 | protected: 22 | void _load(); 23 | bool setupImpl(); 24 | void predictImpl( 25 | cv::Mat img_, 26 | cv::Mat& mde_ 27 | ); 28 | 29 | DepthEstimationCUDAImpl *_cuda_impl; 30 | }; 31 | } 32 | #endif 33 | -------------------------------------------------------------------------------- /include/sv_landing_det.h: -------------------------------------------------------------------------------- 1 | #ifndef __SV_LANDING_DET__ 2 | #define __SV_LANDING_DET__ 3 | 4 | #include "sv_core.h" 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | 11 | 12 | namespace sv { 13 | 14 | class LandingMarkerDetectorCUDAImpl; 15 | class LandingMarkerDetectorIntelImpl; 16 | 17 | class LandingMarkerDetector : public LandingMarkerDetectorBase 18 | { 19 | public: 20 | LandingMarkerDetector(); 21 | ~LandingMarkerDetector(); 22 | protected: 23 | bool setupImpl(); 24 | void roiCNN( 25 | std::vector& input_rois_, 26 | std::vector& output_labels_ 27 | ); 28 | 29 | LandingMarkerDetectorCUDAImpl *_cuda_impl; 30 | LandingMarkerDetectorIntelImpl *_intel_impl; 31 | }; 32 | 33 | 34 | } 35 | #endif 36 | -------------------------------------------------------------------------------- /include/sv_mot.h: -------------------------------------------------------------------------------- 1 | #ifndef __SV_MOT__ 2 | #define __SV_MOT__ 3 | 4 | #include "sv_core.h" 5 | #include "sv_common_det.h" 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | 13 | 14 | namespace sv { 15 | 16 | 17 | class SORT; 18 | class BYTETracker; 19 | 20 | class MultipleObjectTracker : public CameraAlgorithm 21 | { 22 | public: 23 | MultipleObjectTracker(); 24 | ~MultipleObjectTracker(); 25 | 26 | void init(CommonObjectDetector* detector_); 27 | sv::TargetsInFrame track(cv::Mat img_, TargetsInFrame& tgts_); 28 | 29 | private: 30 | void _load(); 31 | bool _params_loaded; 32 | 33 | std::string _algorithm; 34 | bool _with_reid; 35 | int _reid_input_h; 36 | int _reid_input_w; 37 | int _reid_num_samples; 38 | double _reid_match_thres; 39 | double _iou_thres; 40 | int _max_age; 41 | int _min_hits; 42 | int _frame_rate; 43 | int _track_buffer; 44 | 45 | SORT* _sort_impl; 46 | BYTETracker* _bytetrack_impl; 47 | CommonObjectDetector* _detector; 48 | }; 49 | } 50 | #endif 51 | -------------------------------------------------------------------------------- /include/sv_sot.h: -------------------------------------------------------------------------------- 1 | #ifndef __SV_TRACKING__ 2 | #define __SV_TRACKING__ 3 | 4 | #include "sv_core.h" 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | 11 | 12 | 13 | namespace sv { 14 | 15 | class SingleObjectTrackerOCV470Impl; 16 | 17 | class SingleObjectTracker : public SingleObjectTrackerBase 18 | { 19 | public: 20 | SingleObjectTracker(); 21 | ~SingleObjectTracker(); 22 | protected: 23 | bool setupImpl(); 24 | void initImpl(cv::Mat img_, const cv::Rect& bounding_box_); 25 | bool trackImpl(cv::Mat img_, cv::Rect& output_bbox_); 26 | 27 | SingleObjectTrackerOCV470Impl* _ocv470_impl; 28 | }; 29 | 30 | 31 | } 32 | #endif 33 | -------------------------------------------------------------------------------- /include/sv_veri_det.h: -------------------------------------------------------------------------------- 1 | #ifndef __SV_VERI_DET__ 2 | #define __SV_VERI_DET__ 3 | 4 | #include "sv_core.h" 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | 11 | namespace sv 12 | { 13 | 14 | class VeriDetectorCUDAImpl; 15 | class VeriDetectorIntelImpl; 16 | 17 | class VeriDetector : public LandingMarkerDetectorBase 18 | { 19 | public: 20 | VeriDetector(); 21 | ~VeriDetector(); 22 | 23 | void detect(cv::Mat img_, const cv::Rect &bounding_box_, sv::Target &tgt); 24 | 25 | protected: 26 | void _load(); 27 | bool setupImpl(); 28 | void roiCNN( 29 | std::vector &input_rois_, 30 | std::vector &output_labels_); 31 | void getSubwindow(cv::Mat &dstCrop, cv::Mat &srcImg, int originalSz, int resizeSz); 32 | 33 | std::string vehicle_id; 34 | 35 | // Save the target bounding box for each frame. 36 | std::vector targetSz = {0, 0}; // H and W of bounding box 37 | std::vector targetPos = {0, 0}; // center point of bounding box (x, y) 38 | 39 | VeriDetectorCUDAImpl *_cuda_impl; 40 | VeriDetectorIntelImpl *_intel_impl; 41 | }; 42 | 43 | } 44 | #endif 45 | -------------------------------------------------------------------------------- /include/sv_video_input.h: -------------------------------------------------------------------------------- 1 | #ifndef __SV_VIDEO_INPUT__ 2 | #define __SV_VIDEO_INPUT__ 3 | 4 | #include "sv_core.h" 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | 11 | 12 | namespace sv { 13 | 14 | 15 | class Camera : public CameraBase 16 | { 17 | public: 18 | Camera(); 19 | ~Camera(); 20 | protected: 21 | void openImpl(); 22 | 23 | }; 24 | 25 | 26 | } 27 | #endif 28 | -------------------------------------------------------------------------------- /include/sv_video_output.h: -------------------------------------------------------------------------------- 1 | #ifndef __SV_VIDEO_OUTPUT__ 2 | #define __SV_VIDEO_OUTPUT__ 3 | 4 | #include "sv_core.h" 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | 11 | 12 | class BsVideoSaver; 13 | class BsPushStreamer; 14 | 15 | namespace sv { 16 | 17 | class VideoWriterGstreamerImpl; 18 | class VideoStreamerGstreamerImpl; 19 | 20 | class VideoWriter : public VideoWriterBase 21 | { 22 | public: 23 | VideoWriter(); 24 | ~VideoWriter(); 25 | protected: 26 | bool setupImpl(std::string file_name_); 27 | bool isOpenedImpl(); 28 | void writeImpl(cv::Mat img_); 29 | void releaseImpl(); 30 | 31 | VideoWriterGstreamerImpl* _gstreamer_impl; 32 | BsVideoSaver* _ffmpeg_impl; 33 | }; 34 | 35 | 36 | class VideoStreamer : public VideoStreamerBase 37 | { 38 | public: 39 | VideoStreamer(); 40 | ~VideoStreamer(); 41 | protected: 42 | bool setupImpl(); 43 | bool isOpenedImpl(); 44 | void writeImpl(cv::Mat img_); 45 | void releaseImpl(); 46 | 47 | VideoStreamerGstreamerImpl* _gstreamer_impl; 48 | BsPushStreamer* _ffmpeg_impl; 49 | }; 50 | 51 | 52 | } 53 | #endif 54 | -------------------------------------------------------------------------------- /include/sv_world.h: -------------------------------------------------------------------------------- 1 | #ifndef __SV__WORLD__ 2 | #define __SV__WORLD__ 3 | 4 | #include "sv_core.h" 5 | #include "sv_common_det.h" 6 | #include "sv_landing_det.h" 7 | #include "sv_sot.h" 8 | #include "sv_mot.h" 9 | #include "sv_color_line.h" 10 | #include "sv_veri_det.h" 11 | #include "sv_depth_est.h" 12 | #include "sv_video_input.h" 13 | #include "sv_video_output.h" 14 | 15 | 16 | #endif 17 | -------------------------------------------------------------------------------- /params/c-params/calib_webcam_1280x720.yaml: -------------------------------------------------------------------------------- 1 | %YAML:1.0 2 | --- 3 | calibration_time: "2021年01月12日 星期二 18时08分01秒" 4 | image_width: 1280 5 | image_height: 720 6 | flags: 0 7 | camera_matrix: !!opencv-matrix 8 | rows: 3 9 | cols: 3 10 | dt: d 11 | data: [ 7.9379415710551370e+02, 0., 2.9783879354295328e+02, 0., 12 | 7.9491985564466654e+02, 3.0942416136837386e+02, 0., 0., 1. ] 13 | distortion_coefficients: !!opencv-matrix 14 | rows: 1 15 | cols: 5 16 | dt: d 17 | data: [ 2.0950200339181715e-01, -1.1587468096518483e+00, 18 | 5.5342063671841328e-03, 2.2214393775334758e-04, 19 | 1.7127431916651392e+00 ] 20 | avg_reprojection_error: 2.8342964851391211e-01 21 | -------------------------------------------------------------------------------- /params/c-params/calib_webcam_1920x1080.yaml: -------------------------------------------------------------------------------- 1 | %YAML:1.0 2 | --- 3 | calibration_time: "2021年01月12日 星期二 18时08分01秒" 4 | image_width: 1920 5 | image_height: 1080 6 | flags: 0 7 | camera_matrix: !!opencv-matrix 8 | rows: 3 9 | cols: 3 10 | dt: d 11 | data: [ 7.9379415710551370e+02, 0., 2.9783879354295328e+02, 0., 12 | 7.9491985564466654e+02, 3.0942416136837386e+02, 0., 0., 1. ] 13 | distortion_coefficients: !!opencv-matrix 14 | rows: 1 15 | cols: 5 16 | dt: d 17 | data: [ 2.0950200339181715e-01, -1.1587468096518483e+00, 18 | 5.5342063671841328e-03, 2.2214393775334758e-04, 19 | 1.7127431916651392e+00 ] 20 | avg_reprojection_error: 2.8342964851391211e-01 21 | -------------------------------------------------------------------------------- /params/c-params/calib_webcam_640x480.yaml: -------------------------------------------------------------------------------- 1 | %YAML:1.0 2 | --- 3 | calibration_time: "2021年01月12日 星期二 18时08分01秒" 4 | image_width: 640 5 | image_height: 480 6 | flags: 0 7 | camera_matrix: !!opencv-matrix 8 | rows: 3 9 | cols: 3 10 | dt: d 11 | data: [ 7.9379415710551370e+02, 0., 2.9783879354295328e+02, 0., 12 | 7.9491985564466654e+02, 3.0942416136837386e+02, 0., 0., 1. ] 13 | distortion_coefficients: !!opencv-matrix 14 | rows: 1 15 | cols: 5 16 | dt: d 17 | data: [ 2.0950200339181715e-01, -1.1587468096518483e+00, 18 | 5.5342063671841328e-03, 2.2214393775334758e-04, 19 | 1.7127431916651392e+00 ] 20 | avg_reprojection_error: 2.8342964851391211e-01 21 | -------------------------------------------------------------------------------- /samples/calib/aruco_samples_utility.hpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | 6 | namespace { 7 | inline static bool readCameraParameters(std::string filename, cv::Mat &camMatrix, cv::Mat &distCoeffs) { 8 | cv::FileStorage fs(filename, cv::FileStorage::READ); 9 | if (!fs.isOpened()) 10 | return false; 11 | fs["camera_matrix"] >> camMatrix; 12 | fs["distortion_coefficients"] >> distCoeffs; 13 | return true; 14 | } 15 | 16 | inline static bool saveCameraParams(const std::string &filename, cv::Size imageSize, float aspectRatio, int flags, 17 | const cv::Mat &cameraMatrix, const cv::Mat &distCoeffs, double totalAvgErr) { 18 | cv::FileStorage fs(filename, cv::FileStorage::WRITE); 19 | if (!fs.isOpened()) 20 | return false; 21 | 22 | time_t tt; 23 | time(&tt); 24 | struct tm *t2 = localtime(&tt); 25 | char buf[1024]; 26 | strftime(buf, sizeof(buf) - 1, "%c", t2); 27 | 28 | fs << "calibration_time" << buf; 29 | fs << "image_width" << imageSize.width; 30 | fs << "image_height" << imageSize.height; 31 | 32 | if (flags & cv::CALIB_FIX_ASPECT_RATIO) fs << "aspectRatio" << aspectRatio; 33 | 34 | if (flags != 0) { 35 | sprintf(buf, "flags: %s%s%s%s", 36 | flags & cv::CALIB_USE_INTRINSIC_GUESS ? "+use_intrinsic_guess" : "", 37 | flags & cv::CALIB_FIX_ASPECT_RATIO ? "+fix_aspectRatio" : "", 38 | flags & cv::CALIB_FIX_PRINCIPAL_POINT ? "+fix_principal_point" : "", 39 | flags & cv::CALIB_ZERO_TANGENT_DIST ? "+zero_tangent_dist" : ""); 40 | } 41 | fs << "flags" << flags; 42 | fs << "camera_matrix" << cameraMatrix; 43 | fs << "distortion_coefficients" << distCoeffs; 44 | fs << "avg_reprojection_error" << totalAvgErr; 45 | return true; 46 | } 47 | 48 | } 49 | -------------------------------------------------------------------------------- /samples/demo/aruco_detection.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | // 包含SpireCV SDK头文件 4 | #include 5 | 6 | using namespace std; 7 | 8 | int main(int argc, char *argv[]) { 9 | // 实例化Aruco检测器类 10 | sv::ArucoDetector ad; 11 | // 手动导入相机参数,如果使用Amov的G1等吊舱或相机,则可以忽略该步骤,将自动下载相机参数文件 12 | ad.loadCameraParams(sv::get_home() + "/SpireCV/confs/calib_webcam_1280x720.yaml"); 13 | ad.loadAlgorithmParams(sv::get_home() + "/SpireCV/confs/sv_algorithm_params.json"); 14 | 15 | // 打开摄像头 16 | sv::Camera cap; 17 | cap.setWH(ad.image_width, ad.image_height); 18 | cap.setFps(30); 19 | cap.open(sv::CameraType::V4L2CAM, 0); // CameraID 0 20 | // 实例化OpenCV的Mat类,用于内存单帧图像 21 | cv::Mat img; 22 | int frame_id = 0; 23 | while (1) 24 | { 25 | // 实例化SpireCV的 单帧检测结果 接口类 TargetsInFrame 26 | sv::TargetsInFrame tgts(frame_id++); 27 | // 读取一帧图像到img 28 | cap.read(img); 29 | cv::resize(img, img, cv::Size(ad.image_width, ad.image_height)); 30 | 31 | // 执行Aruco二维码检测 32 | ad.detect(img, tgts); 33 | // 可视化检测结果,叠加到img上 34 | sv::drawTargetsInFrame(img, tgts); 35 | 36 | // 控制台打印Aruco检测结果 37 | printf("Frame-[%d]\n", frame_id); 38 | // 打印当前检测的FPS 39 | printf(" FPS = %.2f\n", tgts.fps); 40 | // 打印当前相机的视场角(degree) 41 | printf(" FOV (fx, fy) = (%.2f, %.2f)\n", tgts.fov_x, tgts.fov_y); 42 | // 打印当前输入图像的像素宽度和高度 43 | printf(" Frame Size (width, height) = (%d, %d)\n", tgts.width, tgts.height); 44 | for (int i=0; i 2 | #include 3 | // 包含SpireCV SDK头文件 4 | #include 5 | 6 | using namespace std; 7 | 8 | int main(int argc, char *argv[]) { 9 | // 打开摄像头 10 | sv::Camera cap; 11 | cap.setWH(1280, 720); 12 | cap.setFps(30); 13 | cap.open(sv::CameraType::V4L2CAM, 0); // CameraID 0 14 | // 实例化OpenCV的Mat类,用于内存单帧图像 15 | cv::Mat img; 16 | while (1) 17 | { 18 | // 读取一帧图像到img 19 | cap.read(img); 20 | 21 | // 显示img 22 | cv::imshow("img", img); 23 | cv::waitKey(10); 24 | } 25 | 26 | return 0; 27 | } 28 | 29 | -------------------------------------------------------------------------------- /samples/demo/color_line_detect.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | // 包含SpireCV SDK头文件 4 | #include 5 | 6 | using namespace std; 7 | using namespace sv; 8 | 9 | int main(int argc, char *argv[]) 10 | { 11 | // 实例化 color line detection 检测器类 12 | sv::ColorLineDetector cld; 13 | // 手动导入相机参数,如果使用Amov的G1等吊舱或相机,则可以忽略该步骤,将自动下载相机参数文件 14 | cld.loadCameraParams(sv::get_home() + "/SpireCV/confs/calib_webcam_1280x720.yaml"); 15 | cld.loadAlgorithmParams(sv::get_home() + "/SpireCV/confs/sv_algorithm_params.json"); 16 | 17 | // 打开摄像头 18 | sv::Camera cap; 19 | cap.setWH(cld.image_width, cld.image_height); 20 | cap.setFps(30); 21 | cap.open(sv::CameraType::V4L2CAM, 0); // CameraID 0 22 | // 实例化OpenCV的Mat类,用于内存单帧图像 23 | cv::Mat img; 24 | int frame_id = 0; 25 | while (1) 26 | { 27 | // 实例化SpireCV的 单帧检测结果 接口类 TargetsInFrame 28 | sv::TargetsInFrame tgts(frame_id++); 29 | // 读取一帧图像到img 30 | cap.read(img); 31 | cv::resize(img, img, cv::Size(cld.image_width, cld.image_height)); 32 | 33 | // 执行 color line detection 检测 34 | cld.detect(img, tgts); 35 | // 可视化检测结果,叠加到img上 36 | sv::drawTargetsInFrame(img, tgts); 37 | 38 | // 控制台打印 color line detection 检测结果 39 | printf("Frame-[%d]\n", frame_id); 40 | // 打印当前检测的FPS 41 | printf(" FPS = %.2f\n", tgts.fps); 42 | // 打印当前相机的视场角(degree) 43 | printf(" FOV (fx, fy) = (%.2f, %.2f)\n", tgts.fov_x, tgts.fov_y); 44 | // 打印当前输入图像的像素宽度和高度 45 | printf(" Frame Size (width, height) = (%d, %d)\n", tgts.width, tgts.height); 46 | for (int i = 0; i < tgts.targets.size(); i++) 47 | { 48 | 49 | // 打印每个 color_line 的中心位置,cx,cy的值域为[0, 1],以及cx,cy的像素值 50 | printf(" Color Line detect Center (cx, cy) = (%.3f, %.3f), in Pixels = ((%d, %d))\n", 51 | tgts.targets[i].cx, tgts.targets[i].cy, 52 | int(tgts.targets[i].cx * tgts.width), 53 | int(tgts.targets[i].cy * tgts.height)); 54 | 55 | // 打印每个color_line的x_方向反正切值,跟相机视场相关 56 | printf(" Color Line detect Line-of-sight (ax, ay) = (%.3f, %.3f)\n", tgts.targets[i].los_ax, tgts.targets[i].los_ay); 57 | } 58 | 59 | // 显示检测结果img 60 | cv::imshow("img", img); 61 | cv::waitKey(10); 62 | } 63 | 64 | return 0; 65 | } 66 | -------------------------------------------------------------------------------- /samples/demo/common_object_detection.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | // 包含SpireCV SDK头文件 4 | #include 5 | 6 | using namespace std; 7 | 8 | int main(int argc, char *argv[]) { 9 | // 实例化 通用目标 检测器类 10 | sv::CommonObjectDetector cod; 11 | // 手动导入相机参数,如果使用Amov的G1等吊舱或相机,则可以忽略该步骤,将自动下载相机参数文件 12 | cod.loadCameraParams(sv::get_home() + "/SpireCV/confs/calib_webcam_1280x720.yaml"); 13 | cod.loadAlgorithmParams(sv::get_home() + "/SpireCV/confs/sv_algorithm_params.json"); 14 | 15 | // 打开摄像头 16 | sv::Camera cap; 17 | cap.setWH(cod.image_width, cod.image_height); 18 | cap.setFps(30); 19 | cap.open(sv::CameraType::V4L2CAM, 0); // CameraID 0 20 | // 实例化OpenCV的Mat类,用于内存单帧图像 21 | cv::Mat img; 22 | int frame_id = 0; 23 | while (1) 24 | { 25 | // 实例化SpireCV的 单帧检测结果 接口类 TargetsInFrame 26 | sv::TargetsInFrame tgts(frame_id++); 27 | // 读取一帧图像到img 28 | cap.read(img); 29 | cv::resize(img, img, cv::Size(cod.image_width, cod.image_height)); 30 | 31 | // 执行通用目标检测 32 | cod.detect(img, tgts); 33 | // 可视化检测结果,叠加到img上 34 | sv::drawTargetsInFrame(img, tgts); 35 | 36 | // 控制台打印通用目标检测结果 37 | printf("Frame-[%d]\n", frame_id); 38 | // 打印当前检测的FPS 39 | printf(" FPS = %.2f\n", tgts.fps); 40 | // 打印当前相机的视场角(degree) 41 | printf(" FOV (fx, fy) = (%.2f, %.2f)\n", tgts.fov_x, tgts.fov_y); 42 | // 打印当前输入图像的像素宽度和高度 43 | printf(" Frame Size (width, height) = (%d, %d)\n", tgts.width, tgts.height); 44 | for (int i=0; i 2 | #include 3 | // 包含SpireCV SDK头文件 4 | #include 5 | 6 | using namespace std; 7 | 8 | int main(int argc, char *argv[]) { 9 | // 实例化 椭圆 检测器类 10 | sv::EllipseDetector ed; 11 | // 手动导入相机参数,如果使用Amov的G1等吊舱或相机,则可以忽略该步骤,将自动下载相机参数文件 12 | ed.loadCameraParams(sv::get_home() + "/SpireCV/confs/calib_webcam_1280x720.yaml"); 13 | ed.loadAlgorithmParams(sv::get_home() + "/SpireCV/confs/sv_algorithm_params.json"); 14 | 15 | // 打开摄像头 16 | sv::Camera cap; 17 | cap.setWH(ed.image_width, ed.image_height); 18 | cap.setFps(30); 19 | cap.open(sv::CameraType::V4L2CAM, 0); // CameraID 0 20 | // 实例化OpenCV的Mat类,用于内存单帧图像 21 | cv::Mat img; 22 | int frame_id = 0; 23 | while (1) 24 | { 25 | // 实例化SpireCV的 单帧检测结果 接口类 TargetsInFrame 26 | sv::TargetsInFrame tgts(frame_id++); 27 | // 读取一帧图像到img 28 | cap.read(img); 29 | cv::resize(img, img, cv::Size(ed.image_width, ed.image_height)); 30 | 31 | // 执行 椭圆 检测 32 | ed.detect(img, tgts); 33 | // 可视化检测结果,叠加到img上 34 | sv::drawTargetsInFrame(img, tgts); 35 | 36 | // 控制台打印 椭圆 检测结果 37 | printf("Frame-[%d]\n", frame_id); 38 | // 打印当前检测的FPS 39 | printf(" FPS = %.2f\n", tgts.fps); 40 | // 打印当前相机的视场角(degree) 41 | printf(" FOV (fx, fy) = (%.2f, %.2f)\n", tgts.fov_x, tgts.fov_y); 42 | // 打印当前输入图像的像素宽度和高度 43 | printf(" Frame Size (width, height) = (%d, %d)\n", tgts.width, tgts.height); 44 | for (int i=0; i 2 | #include 3 | #include 4 | // 包含SpireCV SDK头文件 5 | #include 6 | 7 | using namespace std; 8 | namespace fs = std::experimental::filesystem; 9 | 10 | int main(int argc, char *argv[]) { 11 | // 实例化 12 | sv::CommonObjectDetector cod; 13 | // 手动导入相机参数,如果使用Amov的G1等吊舱或相机,则可以忽略该步骤,将自动下载相机参数文件 14 | cod.loadCameraParams(sv::get_home() + "/SpireCV/confs/calib_webcam_1280x720.yaml"); 15 | cod.loadAlgorithmParams(sv::get_home() + "/SpireCV/confs/sv_algorithm_params.json"); 16 | sv::MultipleObjectTracker mot; 17 | // 手动导入相机参数,如果使用Amov的G1等吊舱或相机,则可以忽略该步骤,将自动下载相机参数文件 18 | mot.loadCameraParams(sv::get_home() + "/SpireCV/confs/calib_webcam_1280x720.yaml"); 19 | mot.loadAlgorithmParams(sv::get_home() + "/SpireCV/confs/sv_algorithm_params.json"); 20 | mot.init(&cod); 21 | 22 | // 打开摄像头 23 | /* 24 | sv::Camera cap; 25 | cap.setWH(mot.image_width, mot.image_height); 26 | cap.setFps(30); 27 | cap.open(sv::CameraType::V4L2CAM, 0); // CameraID 0 28 | */ 29 | std::string mot17_folder_path = sv::get_home()+"/SpireCV/dataset/MOT17/train/"; 30 | std::string pred_file_path = sv::get_home()+"/SpireCV/dataset/pred_mot17/data/"; 31 | for (auto & seq_path : std::experimental::filesystem::directory_iterator(mot17_folder_path)) 32 | { 33 | // mkdir pred dirs and touch pred_files 34 | string pred_file = pred_file_path + seq_path.path().filename().string() + ".txt"; 35 | fs::create_directories(pred_file_path); 36 | std::ofstream file(pred_file); 37 | // listdir seqence images 38 | string seq_image_paths = mot17_folder_path + seq_path.path().filename().string() + "/img1"; 39 | // cout << seq_image_paths < seq_image_file_path; 41 | cv::glob(seq_image_paths, seq_image_file_path); 42 | 43 | //eval MOT algorithms 44 | cv::Mat img; 45 | int frame_id = 0; 46 | while (frame_id < seq_image_file_path.size()) 47 | { 48 | img = cv::imread(seq_image_file_path[frame_id]); 49 | // 实例化SpireCV的 单帧检测结果 接口类 TargetsInFrame 50 | sv::TargetsInFrame tgts(frame_id++); 51 | // 读取一帧图像到img 52 | //cap.read(img); 53 | //cv::resize(img, img, cv::Size(mot.image_width, mot.image_height)); 54 | 55 | // 执行通用目标检测 56 | sv::TargetsInFrame person_tgts = mot.track(img, tgts); 57 | // 可视化检测结果,叠加到img上 58 | sv::drawTargetsInFrame(img, person_tgts); 59 | // printf(" Frame Size (width, height) = (%d, %d)\n", tgts.width, tgts.height); 60 | for (auto target : person_tgts.targets) 61 | { 62 | int center_x = int(target.cx * tgts.width); 63 | int center_y = int(target.cy * tgts.height); 64 | int width = int(target.w * tgts.width); 65 | int height = int(target.h * tgts.height); 66 | double conf = target.score; 67 | file << frame_id << ","<< target.tracked_id << "," << center_x - width / 2 << "," << center_y - height / 2 << "," << width << "," << height << "," << conf << "," << "-1,-1,-1" << endl; 68 | // file << frame_id << ","<< target.tracked_id << "," << center_x << "," << center_y << "," << width << "," << height << "," << conf << "," << "-1,-1,-1" << endl; 69 | } 70 | cv::imshow("img", img); 71 | cv::waitKey(10); 72 | } 73 | file.close(); 74 | } 75 | return 0; 76 | } -------------------------------------------------------------------------------- /samples/demo/gimbal_udp_detection_info_sender.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | // 包含SpireCV SDK头文件 4 | #include 5 | 6 | using namespace std; 7 | 8 | // yaw roll pitch 9 | double gimbalEulerAngle[3]; 10 | void gimableCallback(double &frame_ang_r, double &frame_ang_p, double &frame_ang_y, 11 | double &imu_ang_r, double &imu_ang_p, double &imu_ang_y, 12 | double &fov_x, double &fov_y) 13 | { 14 | static int count = 0; 15 | if (count == 25) 16 | { 17 | std::cout << "GIMBAL_CMD_RCV_POS" << std::endl; 18 | std::cout << "=============================================" << std::endl; 19 | std::cout << "HALL_yaw:" << frame_ang_y << " " << std::endl; 20 | std::cout << "HALL_roll:" << frame_ang_r << " " << std::endl; 21 | std::cout << "HALL_pitch:" << frame_ang_p << " " << std::endl; 22 | std::cout << "GYRO_yaw:" << imu_ang_y << " " << std::endl; 23 | std::cout << "GYRO_roll:" << imu_ang_r << " " << std::endl; 24 | std::cout << "GYRO_pitch:" << imu_ang_p << " " << std::endl; 25 | count = 0; 26 | } 27 | 28 | gimbalEulerAngle[0] = frame_ang_y; 29 | gimbalEulerAngle[1] = imu_ang_r; 30 | gimbalEulerAngle[2] = imu_ang_p; 31 | 32 | count++; 33 | } 34 | 35 | // 定义吊舱 36 | sv::Gimbal *gimbal; 37 | 38 | // 定义窗口名称 39 | static const std::string RGB_WINDOW = "Image window"; 40 | 41 | // 鼠标点击事件的回调函数 42 | void onMouse(int event, int x, int y, int, void *); 43 | 44 | int main(int argc, char *argv[]) 45 | { 46 | // 实例化吊舱 47 | gimbal = new sv::Gimbal(sv::GimbalType::G1, sv::GimbalLink::SERIAL); 48 | // 使用 /dev/ttyUSB0 作为控制串口 49 | gimbal->setSerialPort("/dev/ttyUSB0"); 50 | // 以gimableCallback作为状态回调函数启用吊舱控制 51 | gimbal->open(gimableCallback); 52 | // 定义相机 53 | sv::Camera cap; 54 | // 设置相机流媒体地址为 192.168.2.64 55 | cap.setIp("192.168.2.64"); 56 | // 设置获取画面分辨率为720P 57 | cap.setWH(1280, 720); 58 | // 设置视频帧率为30帧 59 | cap.setFps(30); 60 | // 开启相机 61 | cap.open(sv::CameraType::G1); 62 | 63 | // 定义一个窗口 才可以在上面操作 64 | cv::namedWindow(RGB_WINDOW); 65 | // 设置窗口操作回调函数,该函数实现吊舱控制 66 | cv::setMouseCallback(RGB_WINDOW, onMouse, 0); 67 | // 实例化Aruco检测器类 68 | sv::ArucoDetector ad; 69 | // 手动导入相机参数,如果使用Amov的G1等吊舱或相机,则可以忽略该步骤,将自动下载相机参数文件 70 | ad.loadCameraParams(sv::get_home() + "/SpireCV/confs/calib_webcam_1280x720.yaml"); 71 | ad.loadAlgorithmParams(sv::get_home() + "/SpireCV/confs/sv_algorithm_params.json"); 72 | 73 | sv::UDPServer udp; 74 | // 实例化OpenCV的Mat类,用于内存单帧图像 75 | cv::Mat img; 76 | int frame_id = 0; 77 | while (1) 78 | { 79 | // 实例化SpireCV的 单帧检测结果 接口类 TargetsInFrame 80 | sv::TargetsInFrame tgts(frame_id++); 81 | // 读取一帧图像到img 82 | cap.read(img); 83 | 84 | // std::cout << img.type() << std::endl; 85 | 86 | // 执行Aruco二维码检测 87 | ad.detect(img, tgts); 88 | 89 | tgts.has_pod_info = true; 90 | tgts.pod_patch = gimbalEulerAngle[2]; 91 | tgts.pod_roll = gimbalEulerAngle[1]; 92 | tgts.pod_yaw = gimbalEulerAngle[0]; 93 | 94 | tgts.has_uav_pos = false; 95 | tgts.has_uav_vel = false; 96 | tgts.has_ill = false; 97 | 98 | // www.write(img, tgts); 99 | udp.send(tgts); 100 | // 可视化检测结果,叠加到img上 101 | sv::drawTargetsInFrame(img, tgts); 102 | 103 | // 显示检测结果img 104 | cv::imshow(RGB_WINDOW, img); 105 | cv::waitKey(10); 106 | } 107 | 108 | return 0; 109 | } 110 | 111 | void onMouse(int event, int x, int y, int, void *) 112 | { 113 | if (event == cv::EVENT_LBUTTONDOWN) 114 | { 115 | gimbal->setAngleRateEuler(0, 0.02 * (y - 720 / 2), 0.02 * (x - 1280 / 2)); 116 | } 117 | if (event == cv::EVENT_RBUTTONDOWN) 118 | { 119 | gimbal->setHome(); 120 | } 121 | } 122 | -------------------------------------------------------------------------------- /samples/demo/landing_marker_detection.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | // 包含SpireCV SDK头文件 4 | #include 5 | 6 | using namespace std; 7 | 8 | int main(int argc, char *argv[]) { 9 | // 实例化 圆形降落标志 检测器类 10 | sv::LandingMarkerDetector lmd; 11 | // 手动导入相机参数,如果使用Amov的G1等吊舱或相机,则可以忽略该步骤,将自动下载相机参数文件 12 | lmd.loadCameraParams(sv::get_home() + "/SpireCV/confs/calib_webcam_1280x720.yaml"); 13 | lmd.loadAlgorithmParams(sv::get_home() + "/SpireCV/confs/sv_algorithm_params.json"); 14 | 15 | // 打开摄像头 16 | sv::Camera cap; 17 | cap.setWH(lmd.image_width, lmd.image_height); 18 | cap.setFps(30); 19 | cap.open(sv::CameraType::V4L2CAM, 0); // CameraID 0 20 | // 实例化OpenCV的Mat类,用于内存单帧图像 21 | cv::Mat img; 22 | int frame_id = 0; 23 | while (1) 24 | { 25 | // 实例化SpireCV的 单帧检测结果 接口类 TargetsInFrame 26 | sv::TargetsInFrame tgts(frame_id++); 27 | // 读取一帧图像到img 28 | cap.read(img); 29 | cv::resize(img, img, cv::Size(lmd.image_width, lmd.image_height)); 30 | 31 | // 执行 降落标志 检测 32 | lmd.detect(img, tgts); 33 | // 可视化检测结果,叠加到img上 34 | sv::drawTargetsInFrame(img, tgts); 35 | 36 | // 控制台打印 降落标志 检测结果 37 | printf("Frame-[%d]\n", frame_id); 38 | // 打印当前检测的FPS 39 | printf(" FPS = %.2f\n", tgts.fps); 40 | // 打印当前相机的视场角(degree) 41 | printf(" FOV (fx, fy) = (%.2f, %.2f)\n", tgts.fov_x, tgts.fov_y); 42 | // 打印当前输入图像的像素宽度和高度 43 | printf(" Frame Size (width, height) = (%d, %d)\n", tgts.width, tgts.height); 44 | for (int i=0; i 2 | #include 3 | // 包含SpireCV SDK头文件 4 | #include 5 | 6 | using namespace std; 7 | 8 | int main(int argc, char *argv[]) 9 | { 10 | // 实例化 通用目标 检测器类 11 | sv::MonocularDepthEstimation mde; 12 | // 手动导入相机参数,如果使用Amov的G1等吊舱或相机,则可以忽略该步骤,将自动下载相机参数文件 13 | mde.loadCameraParams(sv::get_home() + "/SpireCV/confs/calib_webcam_640x480.yaml"); 14 | mde.loadAlgorithmParams(sv::get_home() + "/SpireCV/confs/sv_algorithm_params.json"); 15 | 16 | // 打开摄像头 17 | sv::Camera cap; 18 | cap.setWH(mde.image_width, mde.image_height); 19 | cap.setFps(30); 20 | cap.open(sv::CameraType::V4L2CAM, 0); // CameraID 0 21 | // 实例化OpenCV的Mat类,用于内存单帧图像 22 | cv::Mat img; 23 | int frame_id = 0; 24 | while (1) 25 | { 26 | // 实例化SpireCV的 单帧检测结果 接口类 TargetsInFrame 27 | sv::TargetsInFrame tgts(frame_id++); 28 | // 读取一帧图像到img 29 | cap.read(img); 30 | cv::resize(img, img, cv::Size(mde.image_width, mde.image_height)); 31 | 32 | // 执行MonocularDepthEstimation 33 | mde.predict(img, tgts); 34 | 35 | // 控制台打印通用目标检测结果 36 | printf("Frame-[%d]\n", frame_id); 37 | // 打印当前检测的FPS 38 | printf(" FPS = %.2f\n", tgts.fps); 39 | // 打印当前相机的视场角(degree) 40 | printf(" FOV (fx, fy) = (%.2f, %.2f)\n", tgts.fov_x, tgts.fov_y); 41 | // 打印当前输入图像的像素宽度和高度 42 | printf(" Frame Size (width, height) = (%d, %d)\n", tgts.width, tgts.height); 43 | 44 | // 归一化深度图到0-1范围 45 | double minVal, maxVal; 46 | cv::minMaxLoc(tgts.depth_data, &minVal, &maxVal); 47 | 48 | // 深度图可视化 49 | cv::Mat depth_mat; 50 | cv::normalize(tgts.depth_data, depth_mat, 0, 255, cv::NORM_MINMAX, CV_8U); 51 | 52 | // 根据深度数据创建色域图 53 | cv::Mat colormap; 54 | cv::applyColorMap(depth_mat, colormap, cv::COLORMAP_JET); 55 | cv::resize(colormap, colormap, cv::Size(mde.image_width, mde.image_height)); 56 | 57 | cv::putText(colormap, cv::format("maxVal: %.1f m", maxVal), cv::Point(200, 20), 58 | 0, 0.6, cv::Scalar(255, 99, 71), 2, cv::LINE_AA); 59 | cv::putText(colormap, cv::format("minVal: %.1f m", minVal), cv::Point(20, 20), 60 | 0, 0.6, cv::Scalar(255, 99, 71), 2, cv::LINE_AA); 61 | 62 | // 合并当前帧和深度图 63 | cv::Mat showImage; 64 | cv::hconcat(img, colormap, showImage); 65 | 66 | // 显示检测结果img 67 | cv::imshow("img", showImage); 68 | cv::waitKey(1); 69 | } 70 | 71 | return 0; 72 | } 73 | -------------------------------------------------------------------------------- /samples/demo/multiple_object_tracking.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | // 包含SpireCV SDK头文件 4 | #include 5 | 6 | using namespace std; 7 | 8 | int main(int argc, char *argv[]) { 9 | // 实例化 10 | sv::CommonObjectDetector cod; 11 | // 手动导入相机参数,如果使用Amov的G1等吊舱或相机,则可以忽略该步骤,将自动下载相机参数文件 12 | cod.loadCameraParams(sv::get_home() + "/SpireCV/confs/calib_webcam_1280x720.yaml"); 13 | cod.loadAlgorithmParams(sv::get_home() + "/SpireCV/confs/sv_algorithm_params.json"); 14 | sv::MultipleObjectTracker mot; 15 | // 手动导入相机参数,如果使用Amov的G1等吊舱或相机,则可以忽略该步骤,将自动下载相机参数文件 16 | mot.loadCameraParams(sv::get_home() + "/SpireCV/confs/calib_webcam_1280x720.yaml"); 17 | mot.loadAlgorithmParams(sv::get_home() + "/SpireCV/confs/sv_algorithm_params.json"); 18 | mot.init(&cod); 19 | 20 | // 打开摄像头 21 | sv::Camera cap; 22 | cap.setWH(mot.image_width, mot.image_height); 23 | cap.setFps(30); 24 | cap.open(sv::CameraType::V4L2CAM, 0); // CameraID 0 25 | // 实例化OpenCV的Mat类,用于内存单帧图像 26 | cv::Mat img; 27 | int frame_id = 0; 28 | while (1) 29 | { 30 | // 实例化SpireCV的 单帧检测结果 接口类 TargetsInFrame 31 | sv::TargetsInFrame tgts(frame_id++); 32 | // 读取一帧图像到img 33 | cap.read(img); 34 | cv::resize(img, img, cv::Size(mot.image_width, mot.image_height)); 35 | 36 | // 执行通用目标检测 37 | sv::TargetsInFrame person_tgts = mot.track(img, tgts); 38 | // 可视化检测结果,叠加到img上 39 | sv::drawTargetsInFrame(img, person_tgts); 40 | 41 | // 显示检测结果img 42 | cv::imshow("img", img); 43 | cv::waitKey(10); 44 | } 45 | 46 | return 0; 47 | } 48 | -------------------------------------------------------------------------------- /samples/demo/udp_detection_info_sender.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | // 包含SpireCV SDK头文件 4 | #include 5 | 6 | using namespace std; 7 | 8 | int main(int argc, char *argv[]) { 9 | // 实例化Aruco检测器类 10 | sv::ArucoDetector ad; 11 | // 手动导入相机参数,如果使用Amov的G1等吊舱或相机,则可以忽略该步骤,将自动下载相机参数文件 12 | ad.loadCameraParams("/home/amov/SpireCV/calib_webcam_1280x720.yaml"); 13 | 14 | // 打开摄像头 15 | sv::Camera cap; 16 | cap.setWH(ad.image_width, ad.image_height); 17 | cap.setFps(30); 18 | cap.open(sv::CameraType::V4L2CAM, 0); // CameraID 0 19 | 20 | sv::UDPServer udp; 21 | // 实例化OpenCV的Mat类,用于内存单帧图像 22 | cv::Mat img; 23 | int frame_id = 0; 24 | while (1) 25 | { 26 | // 实例化SpireCV的 单帧检测结果 接口类 TargetsInFrame 27 | sv::TargetsInFrame tgts(frame_id++); 28 | // 读取一帧图像到img 29 | cap.read(img); 30 | 31 | // 执行Aruco二维码检测 32 | ad.detect(img, tgts); 33 | 34 | tgts.has_pod_info = true; 35 | tgts.pod_patch = 1; 36 | tgts.pod_roll = 2; 37 | tgts.pod_yaw = 3; 38 | tgts.has_uav_pos = true; 39 | tgts.longitude = 1.1234567; 40 | tgts.latitude = 2.2345678; 41 | tgts.altitude = 3.3456789; 42 | tgts.has_uav_vel = true; 43 | tgts.uav_vx = 4; 44 | tgts.uav_vy = 5; 45 | tgts.uav_vz = 6; 46 | tgts.has_ill = true; 47 | tgts.illumination = 7; 48 | 49 | // www.write(img, tgts); 50 | udp.send(tgts); 51 | // 可视化检测结果,叠加到img上 52 | sv::drawTargetsInFrame(img, tgts); 53 | 54 | // 显示检测结果img 55 | cv::imshow("img", img); 56 | cv::waitKey(10); 57 | } 58 | 59 | return 0; 60 | } 61 | -------------------------------------------------------------------------------- /samples/demo/veri.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | // 包含SpireCV SDK头文件 4 | #include 5 | 6 | using namespace std; 7 | 8 | struct node 9 | { 10 | double x, y; 11 | }; 12 | 13 | node p1; 14 | 15 | // 框选到的矩形 16 | cv::Rect rect_sel; 17 | 18 | int main(int argc, char *argv[]) 19 | { 20 | // 实例化 框选目标跟踪类 21 | sv::VeriDetector veri; 22 | // 手动导入相机参数,如果使用Amov的G1等吊舱或相机,则可以忽略该步骤,将自动下载相机参数文件 23 | veri.loadCameraParams(sv::get_home() + "/SpireCV/confs/calib_webcam_1280x720.yaml"); 24 | veri.loadAlgorithmParams(sv::get_home() + "/SpireCV/confs/sv_algorithm_params.json"); 25 | 26 | sv::CommonObjectDetector cod; 27 | cod.loadCameraParams(sv::get_home() + "/SpireCV/confs/calib_webcam_1280x720.yaml"); 28 | cod.loadAlgorithmParams(sv::get_home() + "/SpireCV/confs/sv_algorithm_params.json"); 29 | 30 | // 打开摄像头 31 | sv::Camera cap; 32 | cap.setWH(cod.image_width, cod.image_height); 33 | cap.setFps(30); 34 | cap.open(sv::CameraType::V4L2CAM, 0); // CameraID 0 35 | // 实例化OpenCV的Mat类,用于内存单帧图像 36 | cv::Mat img; 37 | int frame_id = 0; 38 | while (1) 39 | { 40 | 41 | // 实例化SpireCV的 单帧检测结果 接口类 TargetsInFrame 42 | sv::TargetsInFrame tgts(frame_id++); 43 | // 读取一帧图像到img 44 | cap.read(img); 45 | cv::resize(img, img, cv::Size(cod.image_width, cod.image_height)); 46 | 47 | // 执行通用目标检测 48 | cod.detect(img, tgts); 49 | 50 | // 可视化检测结果,叠加到img上 51 | sv::drawTargetsInFrame(img, tgts); 52 | 53 | // 控制台打印通用目标检测结果 54 | printf("Frame-[%d]\n", frame_id); 55 | // 打印当前检测的FPS 56 | printf(" FPS = %.2f\n", tgts.fps); 57 | // 打印当前相机的视场角(degree) 58 | printf(" FOV (fx, fy) = (%.2f, %.2f)\n", tgts.fov_x, tgts.fov_y); 59 | for (int i = 0; i < tgts.targets.size(); i++) 60 | { 61 | printf("Frame-[%d], Object-[%d]\n", frame_id, i); 62 | // 打印每个目标的中心位置,cx,cy的值域为[0, 1] 63 | printf(" Object Center (cx, cy) = (%.3f, %.3f)\n", tgts.targets[i].cx, tgts.targets[i].cy); 64 | // 打印每个目标的外接矩形框的宽度、高度,w,h的值域为(0, 1] 65 | printf(" Object Size (w, h) = (%.3f, %.3f)\n", tgts.targets[i].w, tgts.targets[i].h); 66 | // 打印每个目标的置信度 67 | printf(" Object Score = %.3f\n", tgts.targets[i].score); 68 | // 打印每个目标的类别,字符串类型 69 | printf(" Object Category = %s, Category ID = [%d]\n", tgts.targets[i].category.c_str(), tgts.targets[i].category_id); 70 | // 打印每个目标的视线角,跟相机视场相关 71 | printf(" Object Line-of-sight (ax, ay) = (%.3f, %.3f)\n", tgts.targets[i].los_ax, tgts.targets[i].los_ay); 72 | // 打印每个目标的3D位置(在相机坐标系下),跟目标实际长宽、相机参数相关 73 | printf(" Object Position = (x, y, z) = (%.3f, %.3f, %.3f)\n", tgts.targets[i].px, tgts.targets[i].py, tgts.targets[i].pz); 74 | 75 | if (tgts.targets[i].category_id == 2) 76 | { 77 | p1.x = tgts.targets[i].cx * tgts.width - tgts.targets[i].w * tgts.width / 2; 78 | p1.y = tgts.targets[i].cy * tgts.height - tgts.targets[i].h * tgts.height / 2; 79 | rect_sel = cv::Rect(p1.x, p1.y, tgts.targets[i].w * tgts.width, tgts.targets[i].h * tgts.height); 80 | veri.detect(img, rect_sel, tgts.targets[i]); 81 | // 打印每个目标的CosineSimilarity 82 | printf(" CosineSimilarity Score = %.3f\n", tgts.targets[i].sim_score); 83 | } 84 | } 85 | 86 | // 显示检测结果img 87 | cv::imshow("img", img); 88 | cv::waitKey(10); 89 | } 90 | return 0; 91 | } 92 | -------------------------------------------------------------------------------- /samples/demo/video_saving.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | // 包含SpireCV SDK头文件 4 | #include 5 | 6 | using namespace std; 7 | 8 | int main(int argc, char *argv[]) { 9 | // 实例化 通用目标 检测器类 10 | sv::CommonObjectDetector cod; 11 | // 手动导入相机参数,如果使用Amov的G1等吊舱或相机,则可以忽略该步骤,将自动下载相机参数文件 12 | cod.loadCameraParams(sv::get_home() + "/SpireCV/confs/calib_webcam_1280x720.yaml"); 13 | cod.loadAlgorithmParams(sv::get_home() + "/SpireCV/confs/sv_algorithm_params.json"); 14 | 15 | // 打开摄像头 16 | sv::Camera cap; 17 | cap.setWH(cod.image_width, cod.image_height); 18 | cap.setFps(30); 19 | cap.open(sv::CameraType::V4L2CAM, 0); // CameraID 0 20 | // 实例化OpenCV的Mat类,用于内存单帧图像 21 | cv::Mat img; 22 | int frame_id = 0; 23 | 24 | // 实例化视频保存类 25 | sv::VideoWriter vw; 26 | // 设置保存路径"/home/amov/Videos",保存图像尺寸(640,480),帧频25Hz,同步保存检测结果(.svj) 27 | vw.setup(sv::get_home() + "/Videos", cv::Size(cod.image_width, cod.image_height), 25, true); 28 | 29 | while (1) 30 | { 31 | // 实例化SpireCV的 单帧检测结果 接口类 TargetsInFrame 32 | sv::TargetsInFrame tgts(frame_id++); 33 | // 读取一帧图像到img 34 | cap.read(img); 35 | cv::resize(img, img, cv::Size(cod.image_width, cod.image_height)); 36 | 37 | // 执行通用目标检测 38 | cod.detect(img, tgts); 39 | 40 | // 同步保存视频流 和 检测结果信息 41 | vw.write(img, tgts); 42 | 43 | // 可视化检测结果,叠加到img上 44 | sv::drawTargetsInFrame(img, tgts); 45 | 46 | // 显示检测结果img 47 | cv::imshow("img", img); 48 | cv::waitKey(10); 49 | } 50 | 51 | return 0; 52 | } 53 | -------------------------------------------------------------------------------- /samples/demo/video_streaming.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | // 包含SpireCV SDK头文件 4 | #include 5 | 6 | using namespace std; 7 | 8 | int main(int argc, char *argv[]) { 9 | // 打开摄像头 10 | sv::Camera cap; 11 | // cap.setWH(1280, 720); 12 | // cap.setFps(30); 13 | cap.open(sv::CameraType::WEBCAM, 0); // CameraID 0 14 | 15 | // 实例化视频推流类sv::VideoStreamer 16 | sv::VideoStreamer streamer; 17 | // 初始化 推流分辨率(640, 480),端口号8554,比特率1Mb 18 | streamer.setup(cv::Size(1280, 720), 8554, 1); 19 | // 实例化OpenCV的Mat类,用于内存单帧图像 20 | cv::Mat img; 21 | while (1) 22 | { 23 | // 读取一帧图像到img 24 | cap.read(img); 25 | cv::resize(img, img, cv::Size(1280, 720)); 26 | // 将img推流到 地址:rtsp://ip:8554/live 27 | streamer.stream(img); 28 | 29 | // 显示检测结果img 30 | cv::imshow("img", img); 31 | cv::waitKey(10); 32 | } 33 | 34 | return 0; 35 | } 36 | -------------------------------------------------------------------------------- /samples/test/eval_mAP_on_coco_val/coco_eval.py: -------------------------------------------------------------------------------- 1 | from pycocotools.coco import COCO 2 | from pycocotools.cocoeval import COCOeval 3 | import os 4 | import json 5 | 6 | if __name__ == '__main__': 7 | path = os.path.abspath(os.path.join(os.getcwd(),"../../..")) 8 | pred_json = 'pd_coco.json' 9 | anno_json = path + '/val2017/instances_val2017.json' 10 | 11 | # use COCO API to load forecast results and annotations 12 | cocoGt = COCO(anno_json) 13 | with open(pred_json,'r') as file: 14 | data = json.load(file) 15 | 16 | # align anno_json with pred_json category_id 17 | gtCatDicts = {} 18 | for anns in range(len(cocoGt.getCatIds())): 19 | gtCatDicts[anns] = cocoGt.getCatIds()[anns] 20 | 21 | pdCatIds=list(set([d['category_id'] for d in data])) 22 | 23 | if not set(pdCatIds).issubset(set(cocoGt.getCatIds())): 24 | for ins in data: 25 | temp = int(gtCatDicts[ins['category_id']]) 26 | ins['category_id'] = temp 27 | 28 | # load prediction results 29 | cocoDt = cocoGt.loadRes(data) 30 | 31 | # create COCO eval object 32 | cocoEval = COCOeval(cocoGt, cocoDt,'bbox') 33 | 34 | # assessment 35 | cocoEval.evaluate() 36 | cocoEval.accumulate() 37 | cocoEval.summarize() 38 | -------------------------------------------------------------------------------- /samples/test/eval_mAP_on_coco_val/eval_mAP_on_coco_val.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | // 包含SpireCV SDK头文件 4 | #include 5 | 6 | using namespace std; 7 | using namespace cv; 8 | 9 | //extract name 10 | std::string GetImageFileName(const std::string& imagePath) { 11 | size_t lastSlash = imagePath.find_last_of("/\\"); 12 | if (lastSlash == std::string::npos) 13 | { 14 | return imagePath; 15 | } 16 | else 17 | { 18 | std::string fileName = imagePath.substr(lastSlash + 1); 19 | size_t lastDot = fileName.find_last_of("."); 20 | if (lastDot != std::string::npos) 21 | { 22 | return fileName.substr(0, lastDot); 23 | } 24 | return fileName; 25 | } 26 | } 27 | 28 | 29 | int main(int argc, char *argv[]) 30 | { 31 | // 实例化 通用目标 检测器类 32 | sv::CommonObjectDetector cod; 33 | // 手动导入相机参数,如果使用Amov的G1等吊舱或相机,则可以忽略该步骤,将自动下载相机参数文件 34 | cod.loadCameraParams(sv::get_home() + "/SpireCV/calib_webcam_640x480.yaml"); 35 | 36 | //load data 37 | string val_path = sv::get_home() + "/SpireCV/val2017/val2017"; 38 | vector val_image; 39 | glob(val_path, val_image, false); 40 | if (val_image.size() == 0) 41 | { 42 | printf("val_image error!!!\n"); 43 | exit(1); 44 | } 45 | 46 | //preds folder 47 | std::string folder = sv::get_home() + "/SpireCV/val2017/preds"; 48 | int checkStatus = std::system(("if [ -d \"" + folder + "\" ]; then echo; fi").c_str()); 49 | if(checkStatus == 0) 50 | { 51 | int removeStatus = std::system(("rm -rf \"" + folder + "\"").c_str()); 52 | if(removeStatus != 0) 53 | { 54 | printf("remove older preds folder error!!!\n"); 55 | exit(1); 56 | } 57 | } 58 | 59 | int status = std::system(("mkdir \""+folder+"\"").c_str()); 60 | if(status != 0) 61 | { 62 | printf("create preds folder error!!!\n"); 63 | exit(1); 64 | } 65 | 66 | 67 | for (int i = 0; i < val_image.size(); i++) 68 | { 69 | //create pred file 70 | std::string val_image_name = GetImageFileName(val_image[i]); 71 | std::string filename = folder+"/"+ val_image_name + ".txt"; 72 | std::ofstream file(filename); 73 | file.is_open(); 74 | file<> ~/.bashrc 45 | 46 | -------------------------------------------------------------------------------- /scripts/common/opencv470-install.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | 4 | wget https://download.amovlab.com/model/deps/opencv-4.7.0.zip 5 | wget https://download.amovlab.com/model/deps/opencv_contrib-4.7.0.zip 6 | wget https://download.amovlab.com/model/deps/opencv_cache-4.7.0.zip 7 | 8 | 9 | package_dir="." 10 | mkdir ~/opencv_build 11 | 12 | 13 | if [ ! -d ""$package_dir"" ];then 14 | echo "\033[31m[ERROR]: $package_dir not exist!: \033[0m" 15 | exit 1 16 | fi 17 | 18 | sudo add-apt-repository "deb http://security.ubuntu.com/ubuntu xenial-security main" 19 | sudo add-apt-repository "deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu-ports/ xenial main multiverse restricted universe" 20 | sudo apt update 21 | sudo apt install -y build-essential 22 | sudo apt install -y cmake git libgtk2.0-dev pkg-config libavcodec-dev libavformat-dev libswscale-dev 23 | sudo apt install -y libjasper1 libjasper-dev 24 | sudo apt install -y python3-dev python3-numpy libtbb2 libtbb-dev libjpeg-dev libpng-dev libtiff-dev 25 | sudo apt install -y libdc1394-22-dev 26 | 27 | 28 | echo "\033[32m[INFO]:\033[0m unzip opencv-4.7.0.zip ..." 29 | unzip -q -o $package_dir/opencv-4.7.0.zip -d ~/opencv_build 30 | 31 | echo "\033[32m[INFO]:\033[0m unzip opencv_contrib-4.7.0.zip ..." 32 | unzip -q -o $package_dir/opencv_contrib-4.7.0.zip -d ~/opencv_build 33 | 34 | echo "\033[32m[INFO]:\033[0m unzip opencv_cache-4.7.0.zip ..." 35 | unzip -q -o $package_dir/opencv_cache-4.7.0.zip -d ~/opencv_build 36 | 37 | 38 | sudo rm opencv-4.7.0.zip 39 | sudo rm opencv_contrib-4.7.0.zip 40 | sudo rm opencv_cache-4.7.0.zip 41 | 42 | cd ~/opencv_build/opencv-4.7.0 43 | mkdir .cache 44 | 45 | cp -r ~/opencv_build/opencv_cache-4.7.0/* ~/opencv_build/opencv-4.7.0/.cache/ 46 | 47 | mkdir build 48 | cd build 49 | 50 | cmake -D CMAKE_BUILD_TYPE=Release -D WITH_CUDA=OFF -D OPENCV_ENABLE_NONFREE=ON -D CMAKE_INSTALL_PREFIX=/usr/local -D OPENCV_EXTRA_MODULES_PATH=../../opencv_contrib-4.7.0/modules .. 51 | 52 | make -j2 53 | sudo make install 54 | 55 | cd 56 | sudo rm -r ~/opencv_build 57 | -------------------------------------------------------------------------------- /scripts/jetson/configs-downloading.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash -e 2 | 3 | root_dir=${HOME}"/SpireCV/models" 4 | root_server="https://download.amovlab.com/model" 5 | 6 | sv_params1=${HOME}"/SpireCV/sv_algorithm_params.json" 7 | sv_params2=${HOME}"/SpireCV/sv_algorithm_params_coco_640.json" 8 | sv_params3=${HOME}"/SpireCV/sv_algorithm_params_coco_1280.json" 9 | camera_params1=${HOME}"/SpireCV/calib_webcam_640x480.yaml" 10 | camera_params2=${HOME}"/SpireCV/calib_webcam_1280x720.yaml" 11 | 12 | 13 | if [ ! -d ${root_dir} ]; then 14 | echo -e "\033[32m[INFO]: ${root_dir} not exist, creating it ... \033[0m" 15 | mkdir -p ${root_dir} 16 | fi 17 | 18 | if [ ! -f ${sv_params1} ]; then 19 | echo -e "\033[32m[INFO]: ${sv_params1} not exist, downloading ... \033[0m" 20 | wget -O ${sv_params1} ${root_server}/install/a-params/sv_algorithm_params.json 21 | fi 22 | if [ ! -f ${sv_params2} ]; then 23 | echo -e "\033[32m[INFO]: ${sv_params2} not exist, downloading ... \033[0m" 24 | wget -O ${sv_params2} ${root_server}/install/a-params/sv_algorithm_params_coco_640.json 25 | fi 26 | if [ ! -f ${sv_params3} ]; then 27 | echo -e "\033[32m[INFO]: ${sv_params3} not exist, downloading ... \033[0m" 28 | wget -O ${sv_params3} ${root_server}/install/a-params/sv_algorithm_params_coco_1280.json 29 | fi 30 | 31 | if [ ! -f ${camera_params1} ]; then 32 | echo -e "\033[32m[INFO]: ${camera_params1} not exist, downloading ... \033[0m" 33 | wget -O ${camera_params1} ${root_server}/install/c-params/calib_webcam_640x480.yaml 34 | fi 35 | if [ ! -f ${camera_params2} ]; then 36 | echo -e "\033[32m[INFO]: ${camera_params2} not exist, downloading ... \033[0m" 37 | wget -O ${camera_params2} ${root_server}/install/c-params/calib_webcam_1280x720.yaml 38 | fi 39 | 40 | -------------------------------------------------------------------------------- /scripts/jetson/gst-install-orin.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | sudo apt install -y libgstreamer1.0-dev libgstreamer-plugins-base1.0-dev 4 | sudo apt install -y libgstreamer-plugins-bad1.0-dev gstreamer1.0-plugins-base 5 | sudo apt install -y gstreamer1.0-plugins-good gstreamer1.0-plugins-bad 6 | sudo apt install -y gstreamer1.0-plugins-ugly gstreamer1.0-libav gstreamer1.0-doc 7 | sudo apt install -y gstreamer1.0-tools gstreamer1.0-x gstreamer1.0-alsa 8 | sudo apt install -y gstreamer1.0-gl gstreamer1.0-gtk3 gstreamer1.0-qt5 9 | sudo apt install -y gstreamer1.0-pulseaudio 10 | sudo apt install -y gtk-doc-tools 11 | sudo apt install -y libeigen3-dev libfmt-dev v4l-utils 12 | 13 | sudo apt -y install autotools-dev automake m4 perl 14 | sudo apt -y install libtool 15 | autoreconf -ivf 16 | 17 | git clone https://gitee.com/jario-jin/gst-rtsp-server-b18.git 18 | cd gst-rtsp-server-b18 19 | ./autogen.sh 20 | make 21 | sudo make install 22 | cd .. 23 | sudo rm -r gst-rtsp-server-b18 24 | 25 | -------------------------------------------------------------------------------- /scripts/jetson/gst-install.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | sudo apt install -y libgstreamer1.0-dev libgstreamer-plugins-base1.0-dev 4 | sudo apt install -y libgstreamer-plugins-bad1.0-dev gstreamer1.0-plugins-base 5 | sudo apt install -y gstreamer1.0-plugins-good gstreamer1.0-plugins-bad 6 | sudo apt install -y gstreamer1.0-plugins-ugly gstreamer1.0-libav gstreamer1.0-doc 7 | sudo apt install -y gstreamer1.0-tools gstreamer1.0-x gstreamer1.0-alsa 8 | sudo apt install -y gstreamer1.0-gl gstreamer1.0-gtk3 gstreamer1.0-qt5 9 | sudo apt install -y gstreamer1.0-pulseaudio 10 | sudo apt install -y gtk-doc-tools 11 | sudo apt install -y libeigen3-dev libfmt-dev v4l-utils 12 | 13 | git clone https://gitee.com/jario-jin/gst-rtsp-server-b18.git 14 | cd gst-rtsp-server-b18 15 | ./autogen.sh 16 | make 17 | sudo make install 18 | cd .. 19 | sudo rm -r gst-rtsp-server-b18 20 | 21 | -------------------------------------------------------------------------------- /scripts/jetson/opencv470-install.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | 4 | wget https://download.amovlab.com/model/deps/opencv-4.7.0.zip 5 | wget https://download.amovlab.com/model/deps/opencv_contrib-4.7.0.zip 6 | wget https://download.amovlab.com/model/deps/opencv_cache_x86-4.7.0.zip 7 | 8 | current_dir=$(pwd) 9 | package_dir="." 10 | mkdir ~/opencv_build 11 | 12 | 13 | if [ ! -d ""$package_dir"" ];then 14 | echo "\033[31m[ERROR]: $package_dir not exist!: \033[0m" 15 | exit 1 16 | fi 17 | 18 | # sudo add-apt-repository "deb http://security.ubuntu.com/ubuntu xenial-security main" 19 | # sudo add-apt-repository "deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu-ports/ xenial main multiverse restricted universe" 20 | sudo apt update 21 | sudo apt install -y build-essential 22 | sudo apt install -y cmake git libgtk2.0-dev pkg-config libavcodec-dev libavformat-dev libswscale-dev 23 | 24 | sudo add-apt-repository "deb http://security.ubuntu.com/ubuntu xenial-security main" 25 | sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 3B4FE6ACC0B21F32 26 | sudo apt update 27 | sudo apt install -y libjasper1 libjasper-dev 28 | 29 | sudo apt install -y python3-dev python3-numpy libtbb2 libtbb-dev libjpeg-dev libpng-dev libtiff-dev 30 | sudo apt install -y libdc1394-22-dev 31 | sudo apt install -y libcurl4 build-essential pkg-config cmake libopenblas-dev libeigen3-dev \ 32 | libtbb-dev libavcodec-dev libavformat-dev libgstreamer-plugins-base1.0-dev \ 33 | libgstreamer1.0-dev libswscale-dev libgtk-3-dev libpng-dev libjpeg-dev \ 34 | libcanberra-gtk-module libcanberra-gtk3-module 35 | 36 | 37 | echo "\033[32m[INFO]:\033[0m unzip opencv-4.7.0.zip ..." 38 | unzip -q -o $package_dir/opencv-4.7.0.zip -d ~/opencv_build 39 | 40 | echo "\033[32m[INFO]:\033[0m unzip opencv_contrib-4.7.0.zip ..." 41 | unzip -q -o $package_dir/opencv_contrib-4.7.0.zip -d ~/opencv_build 42 | 43 | echo "\033[32m[INFO]:\033[0m unzip opencv_cache_x86-4.7.0.zip ..." 44 | unzip -q -o $package_dir/opencv_cache_x86-4.7.0.zip -d ~/opencv_build 45 | 46 | 47 | sudo rm opencv-4.7.0.zip 48 | sudo rm opencv_contrib-4.7.0.zip 49 | sudo rm opencv_cache_x86-4.7.0.zip 50 | 51 | cd ~/opencv_build/opencv-4.7.0 52 | mkdir .cache 53 | 54 | cp -r ~/opencv_build/opencv_cache_x86-4.7.0/* ~/opencv_build/opencv-4.7.0/.cache/ 55 | 56 | mkdir build 57 | cd build 58 | 59 | cmake -D CMAKE_BUILD_TYPE=Release \ 60 | -D WITH_CUDA=OFF \ 61 | -D OPENCV_ENABLE_NONFREE=ON \ 62 | -D CMAKE_INSTALL_PREFIX=/usr/local \ 63 | -D OPENCV_EXTRA_MODULES_PATH=../../opencv_contrib-4.7.0/modules .. 64 | 65 | make -j2 66 | sudo make install 67 | 68 | cd 69 | sudo rm -r ~/opencv_build 70 | cd ${current_dir} 71 | -------------------------------------------------------------------------------- /scripts/jetson/opencv470-jetpack511-cuda-install.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | 4 | wget https://download.amovlab.com/model/deps/opencv-4.7.0.zip 5 | wget https://download.amovlab.com/model/deps/opencv_contrib-4.7.0.zip 6 | wget https://download.amovlab.com/model/deps/opencv_cache-4.7.0.zip 7 | 8 | current_dir=$(pwd) 9 | package_dir="." 10 | mkdir ~/opencv_build 11 | 12 | 13 | if [ ! -d ""$package_dir"" ];then 14 | echo "\033[31m[ERROR]: $package_dir not exist!: \033[0m" 15 | exit 1 16 | fi 17 | 18 | sudo apt update 19 | sudo apt install -y build-essential 20 | sudo apt install -y cmake git libgtk2.0-dev pkg-config libavcodec-dev libavformat-dev libswscale-dev 21 | sudo apt install -y libjasper1 libjasper-dev 22 | sudo apt install -y python3-dev python3-numpy libtbb2 libtbb-dev libjpeg-dev libpng-dev libtiff-dev 23 | sudo apt install -y libdc1394-22-dev 24 | 25 | 26 | echo "\033[32m[INFO]:\033[0m unzip opencv-4.7.0.zip ..." 27 | unzip -q -o $package_dir/opencv-4.7.0.zip -d ~/opencv_build 28 | 29 | echo "\033[32m[INFO]:\033[0m unzip opencv_contrib-4.7.0.zip ..." 30 | unzip -q -o $package_dir/opencv_contrib-4.7.0.zip -d ~/opencv_build 31 | 32 | echo "\033[32m[INFO]:\033[0m unzip opencv_cache-4.7.0.zip ..." 33 | unzip -q -o $package_dir/opencv_cache-4.7.0.zip -d ~/opencv_build 34 | 35 | 36 | sudo rm opencv-4.7.0.zip 37 | sudo rm opencv_contrib-4.7.0.zip 38 | sudo rm opencv_cache-4.7.0.zip 39 | 40 | cd ~/opencv_build/opencv-4.7.0 41 | mkdir .cache 42 | 43 | cp -r ~/opencv_build/opencv_cache-4.7.0/* ~/opencv_build/opencv-4.7.0/.cache/ 44 | 45 | mkdir build 46 | cd build 47 | 48 | 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 .. 49 | 50 | make -j2 51 | sudo make install 52 | 53 | cd 54 | sudo rm -r ~/opencv_build 55 | cd ${current_dir} 56 | -------------------------------------------------------------------------------- /scripts/jetson/opencv470-jetpack511-install.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | 4 | wget https://download.amovlab.com/model/deps/opencv-4.7.0.zip 5 | wget https://download.amovlab.com/model/deps/opencv_contrib-4.7.0.zip 6 | wget https://download.amovlab.com/model/deps/opencv_cache-4.7.0.zip 7 | 8 | current_dir=$(pwd) 9 | package_dir="." 10 | mkdir ~/opencv_build 11 | 12 | 13 | if [ ! -d ""$package_dir"" ];then 14 | echo "\033[31m[ERROR]: $package_dir not exist!: \033[0m" 15 | exit 1 16 | fi 17 | 18 | sudo apt update 19 | sudo apt install -y build-essential 20 | sudo apt install -y cmake git libgtk2.0-dev pkg-config libavcodec-dev libavformat-dev libswscale-dev 21 | sudo apt install -y libjasper1 libjasper-dev 22 | sudo apt install -y python3-dev python3-numpy libtbb2 libtbb-dev libjpeg-dev libpng-dev libtiff-dev 23 | sudo apt install -y libdc1394-22-dev 24 | 25 | 26 | echo "\033[32m[INFO]:\033[0m unzip opencv-4.7.0.zip ..." 27 | unzip -q -o $package_dir/opencv-4.7.0.zip -d ~/opencv_build 28 | 29 | echo "\033[32m[INFO]:\033[0m unzip opencv_contrib-4.7.0.zip ..." 30 | unzip -q -o $package_dir/opencv_contrib-4.7.0.zip -d ~/opencv_build 31 | 32 | echo "\033[32m[INFO]:\033[0m unzip opencv_cache-4.7.0.zip ..." 33 | unzip -q -o $package_dir/opencv_cache-4.7.0.zip -d ~/opencv_build 34 | 35 | 36 | sudo rm opencv-4.7.0.zip 37 | sudo rm opencv_contrib-4.7.0.zip 38 | sudo rm opencv_cache-4.7.0.zip 39 | 40 | cd ~/opencv_build/opencv-4.7.0 41 | mkdir .cache 42 | 43 | cp -r ~/opencv_build/opencv_cache-4.7.0/* ~/opencv_build/opencv-4.7.0/.cache/ 44 | 45 | mkdir build 46 | cd build 47 | 48 | cmake -D CMAKE_BUILD_TYPE=Release -D WITH_CUDA=OFF -D OPENCV_ENABLE_NONFREE=ON -D CMAKE_INSTALL_PREFIX=/usr/local -D OPENCV_EXTRA_MODULES_PATH=../../opencv_contrib-4.7.0/modules .. 49 | 50 | make -j2 51 | sudo make install 52 | 53 | cd 54 | sudo rm -r ~/opencv_build 55 | cd ${current_dir} 56 | -------------------------------------------------------------------------------- /scripts/test/test_fps.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash -e 2 | 3 | if [ ! -d build ]; then 4 | mkdir build 5 | fi 6 | 7 | cd build 8 | 9 | cmake .. 10 | make -j 11 | 12 | ./EvalFpsOnVideo ${HOME}/SpireCV/test/tracking_640x480.mp4 ${HOME}/SpireCV/calib_webcam_640x480.yaml 51 13 | ./EvalFpsOnVideo ${HOME}/SpireCV/test/tracking_1280x720.mp4 ${HOME}/SpireCV/calib_webcam_1280x720.yaml 51 14 | ./EvalFpsOnVideo ${HOME}/SpireCV/test/tracking_1280x720.mp4 ${HOME}/SpireCV/calib_webcam_1920x1080.yaml 51 15 | 16 | ./EvalFpsOnVideo ${HOME}/SpireCV/test/tracking_640x480.mp4 ${HOME}/SpireCV/calib_webcam_640x480.yaml 52 17 | ./EvalFpsOnVideo ${HOME}/SpireCV/test/tracking_1280x720.mp4 ${HOME}/SpireCV/calib_webcam_1280x720.yaml 52 18 | ./EvalFpsOnVideo ${HOME}/SpireCV/test/tracking_1280x720.mp4 ${HOME}/SpireCV/calib_webcam_1920x1080.yaml 52 19 | 20 | ./EvalFpsOnVideo ${HOME}/SpireCV/test/tracking_640x480.mp4 ${HOME}/SpireCV/calib_webcam_640x480.yaml 54 21 | ./EvalFpsOnVideo ${HOME}/SpireCV/test/tracking_1280x720.mp4 ${HOME}/SpireCV/calib_webcam_1280x720.yaml 54 22 | ./EvalFpsOnVideo ${HOME}/SpireCV/test/tracking_1280x720.mp4 ${HOME}/SpireCV/calib_webcam_1920x1080.yaml 54 23 | 24 | ./EvalFpsOnVideo ${HOME}/SpireCV/test/drone_640x480.mp4 ${HOME}/SpireCV/calib_webcam_640x480.yaml 41 25 | ./EvalFpsOnVideo ${HOME}/SpireCV/test/drone_1280x720.mp4 ${HOME}/SpireCV/calib_webcam_1280x720.yaml 41 26 | ./EvalFpsOnVideo ${HOME}/SpireCV/test/drone_1280x720.mp4 ${HOME}/SpireCV/calib_webcam_1920x1080.yaml 41 27 | 28 | ./EvalFpsOnVideo ${HOME}/SpireCV/test/drone_640x480.mp4 ${HOME}/SpireCV/calib_webcam_640x480.yaml 42 29 | ./EvalFpsOnVideo ${HOME}/SpireCV/test/drone_1280x720.mp4 ${HOME}/SpireCV/calib_webcam_1280x720.yaml 42 30 | ./EvalFpsOnVideo ${HOME}/SpireCV/test/drone_1280x720.mp4 ${HOME}/SpireCV/calib_webcam_1920x1080.yaml 42 31 | 32 | ./EvalFpsOnVideo ${HOME}/SpireCV/test/drone_640x480.mp4 ${HOME}/SpireCV/calib_webcam_640x480.yaml 43 33 | ./EvalFpsOnVideo ${HOME}/SpireCV/test/drone_1280x720.mp4 ${HOME}/SpireCV/calib_webcam_1280x720.yaml 43 34 | ./EvalFpsOnVideo ${HOME}/SpireCV/test/drone_1280x720.mp4 ${HOME}/SpireCV/calib_webcam_1920x1080.yaml 43 35 | 36 | ./EvalFpsOnVideo ${HOME}/SpireCV/test/aruco_640x480.mp4 ${HOME}/SpireCV/calib_webcam_640x480.yaml 1 37 | ./EvalFpsOnVideo ${HOME}/SpireCV/test/aruco_1280x720.mp4 ${HOME}/SpireCV/calib_webcam_1280x720.yaml 1 38 | ./EvalFpsOnVideo ${HOME}/SpireCV/test/aruco_1280x720.mp4 ${HOME}/SpireCV/calib_webcam_1920x1080.yaml 1 39 | 40 | ./EvalFpsOnVideo ${HOME}/SpireCV/test/landing_640x480.mp4 ${HOME}/SpireCV/calib_webcam_640x480.yaml 2 41 | ./EvalFpsOnVideo ${HOME}/SpireCV/test/landing_1280x720.mp4 ${HOME}/SpireCV/calib_webcam_1280x720.yaml 2 42 | 43 | ./EvalFpsOnVideo ${HOME}/SpireCV/test/ellipse_640x480.mp4 ${HOME}/SpireCV/calib_webcam_640x480.yaml 3 44 | ./EvalFpsOnVideo ${HOME}/SpireCV/test/ellipse_1280x720.mp4 ${HOME}/SpireCV/calib_webcam_1280x720.yaml 3 45 | 46 | -------------------------------------------------------------------------------- /scripts/test/test_gimbal.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash -e 2 | 3 | ./GimbalTest /dev/ttyUSB0 192.168.2.64 4 | 5 | -------------------------------------------------------------------------------- /scripts/x86-cuda/configs-downloading.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash -e 2 | 3 | root_dir=${HOME}"/SpireCV/models" 4 | root_server="https://download.amovlab.com/model" 5 | 6 | sv_params1=${HOME}"/SpireCV/sv_algorithm_params.json" 7 | sv_params2=${HOME}"/SpireCV/sv_algorithm_params_coco_640.json" 8 | sv_params3=${HOME}"/SpireCV/sv_algorithm_params_coco_1280.json" 9 | camera_params1=${HOME}"/SpireCV/calib_webcam_640x480.yaml" 10 | camera_params2=${HOME}"/SpireCV/calib_webcam_1280x720.yaml" 11 | 12 | 13 | if [ ! -d ${root_dir} ]; then 14 | echo -e "\033[32m[INFO]: ${root_dir} not exist, creating it ... \033[0m" 15 | mkdir -p ${root_dir} 16 | fi 17 | 18 | if [ ! -f ${sv_params1} ]; then 19 | echo -e "\033[32m[INFO]: ${sv_params1} not exist, downloading ... \033[0m" 20 | wget -O ${sv_params1} ${root_server}/install/a-params/sv_algorithm_params.json 21 | fi 22 | if [ ! -f ${sv_params2} ]; then 23 | echo -e "\033[32m[INFO]: ${sv_params2} not exist, downloading ... \033[0m" 24 | wget -O ${sv_params2} ${root_server}/install/a-params/sv_algorithm_params_coco_640.json 25 | fi 26 | if [ ! -f ${sv_params3} ]; then 27 | echo -e "\033[32m[INFO]: ${sv_params3} not exist, downloading ... \033[0m" 28 | wget -O ${sv_params3} ${root_server}/install/a-params/sv_algorithm_params_coco_1280.json 29 | fi 30 | 31 | if [ ! -f ${camera_params1} ]; then 32 | echo -e "\033[32m[INFO]: ${camera_params1} not exist, downloading ... \033[0m" 33 | wget -O ${camera_params1} ${root_server}/install/c-params/calib_webcam_640x480.yaml 34 | fi 35 | if [ ! -f ${camera_params2} ]; then 36 | echo -e "\033[32m[INFO]: ${camera_params2} not exist, downloading ... \033[0m" 37 | wget -O ${camera_params2} ${root_server}/install/c-params/calib_webcam_1280x720.yaml 38 | fi 39 | 40 | -------------------------------------------------------------------------------- /scripts/x86-cuda/ffmpeg425-install.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | 4 | sudo apt install -y \ 5 | build-essential yasm cmake libtool libc6 libc6-dev unzip wget libeigen3-dev libfmt-dev \ 6 | libnuma1 libnuma-dev libx264-dev libx265-dev libfaac-dev libssl-dev v4l-utils 7 | 8 | current_dir=$(pwd) 9 | root_dir=${HOME}"/SpireCV" 10 | if [ ! -d ${root_dir} ]; then 11 | echo -e "\033[32m[INFO]: ${root_dir} not exist, creating it ... \033[0m" 12 | mkdir -p ${root_dir} 13 | fi 14 | cd ${root_dir} 15 | 16 | git clone https://gitee.com/jario-jin/nv-codec-headers.git 17 | cd nv-codec-headers 18 | git checkout n11.1.5.0 19 | sudo make install 20 | cd .. 21 | sudo rm -r nv-codec-headers 22 | 23 | wget https://ffmpeg.org/releases/ffmpeg-4.2.5.tar.bz2 24 | tar -xjf ffmpeg-4.2.5.tar.bz2 25 | cd ffmpeg-4.2.5 26 | export PATH=$PATH:/usr/local/cuda/bin 27 | sed -i 's#_30#_75#' configure; sed -i 's#_30#_75#' configure 28 | ./configure \ 29 | --enable-nonfree \ 30 | --enable-gpl \ 31 | --enable-shared \ 32 | --enable-ffmpeg \ 33 | --enable-ffplay \ 34 | --enable-ffprobe \ 35 | --enable-libx264 \ 36 | --enable-libx265 \ 37 | --enable-cuda-nvcc \ 38 | --enable-nvenc \ 39 | --enable-cuda \ 40 | --enable-cuvid \ 41 | --enable-libnpp \ 42 | --extra-libs="-lpthread -lm" \ 43 | --extra-cflags=-I/usr/local/cuda/include \ 44 | --extra-ldflags=-L/usr/local/cuda/lib64 45 | make -j8 46 | sudo make install 47 | cd .. 48 | 49 | git clone https://gitee.com/jario-jin/ZLMediaKit.git 50 | cd ZLMediaKit 51 | git submodule update --init 52 | mkdir build 53 | cd build 54 | cmake .. 55 | make -j4 56 | cd .. 57 | cd .. 58 | 59 | mkdir ZLM 60 | cd ZLM 61 | cp ../ZLMediaKit/release/linux/Debug/MediaServer . 62 | cp ../ZLMediaKit/release/linux/Debug/config.ini . 63 | cd .. 64 | 65 | cd ${current_dir} 66 | 67 | -------------------------------------------------------------------------------- /scripts/x86-cuda/gst-install.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | sudo apt install -y libgstreamer1.0-dev libgstreamer-plugins-base1.0-dev 4 | sudo apt install -y libgstreamer-plugins-bad1.0-dev gstreamer1.0-plugins-base 5 | sudo apt install -y gstreamer1.0-plugins-good gstreamer1.0-plugins-bad 6 | sudo apt install -y gstreamer1.0-plugins-ugly gstreamer1.0-libav gstreamer1.0-doc 7 | sudo apt install -y gstreamer1.0-tools gstreamer1.0-x gstreamer1.0-alsa 8 | sudo apt install -y gstreamer1.0-gl gstreamer1.0-gtk3 gstreamer1.0-qt5 9 | sudo apt install -y gstreamer1.0-pulseaudio 10 | sudo apt install -y gtk-doc-tools 11 | sudo apt install -y libeigen3-dev libfmt-dev 12 | 13 | git clone https://gitee.com/jario-jin/gst-rtsp-server-b18.git 14 | cd gst-rtsp-server-b18 15 | ./autogen.sh 16 | make 17 | sudo make install 18 | cd .. 19 | sudo rm -r gst-rtsp-server-b18 20 | 21 | -------------------------------------------------------------------------------- /scripts/x86-cuda/opencv470-cuda-install.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | 4 | wget https://download.amovlab.com/model/deps/opencv-4.7.0.zip 5 | wget https://download.amovlab.com/model/deps/opencv_contrib-4.7.0.zip 6 | wget https://download.amovlab.com/model/deps/opencv_cache_x86-4.7.0.zip 7 | 8 | current_dir=$(pwd) 9 | package_dir="." 10 | mkdir ~/opencv_build 11 | 12 | 13 | if [ ! -d ""$package_dir"" ];then 14 | echo "\033[31m[ERROR]: $package_dir not exist!: \033[0m" 15 | exit 1 16 | fi 17 | 18 | # sudo add-apt-repository "deb http://security.ubuntu.com/ubuntu xenial-security main" 19 | # sudo add-apt-repository "deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu-ports/ xenial main multiverse restricted universe" 20 | sudo apt update 21 | sudo apt install -y build-essential 22 | sudo apt install -y cmake git libgtk2.0-dev pkg-config libavcodec-dev libavformat-dev libswscale-dev 23 | 24 | sudo add-apt-repository "deb http://security.ubuntu.com/ubuntu xenial-security main" 25 | sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 3B4FE6ACC0B21F32 26 | sudo apt update 27 | sudo apt install -y libjasper1 libjasper-dev 28 | 29 | sudo apt install -y python3-dev python3-numpy libtbb2 libtbb-dev libjpeg-dev libpng-dev libtiff-dev 30 | sudo apt install -y libdc1394-22-dev 31 | 32 | 33 | echo "\033[32m[INFO]:\033[0m unzip opencv-4.7.0.zip ..." 34 | unzip -q -o $package_dir/opencv-4.7.0.zip -d ~/opencv_build 35 | 36 | echo "\033[32m[INFO]:\033[0m unzip opencv_contrib-4.7.0.zip ..." 37 | unzip -q -o $package_dir/opencv_contrib-4.7.0.zip -d ~/opencv_build 38 | 39 | echo "\033[32m[INFO]:\033[0m unzip opencv_cache_x86-4.7.0.zip ..." 40 | unzip -q -o $package_dir/opencv_cache_x86-4.7.0.zip -d ~/opencv_build 41 | 42 | 43 | sudo rm opencv-4.7.0.zip 44 | sudo rm opencv_contrib-4.7.0.zip 45 | sudo rm opencv_cache_x86-4.7.0.zip 46 | 47 | cd ~/opencv_build/opencv-4.7.0 48 | mkdir .cache 49 | 50 | cp -r ~/opencv_build/opencv_cache_x86-4.7.0/* ~/opencv_build/opencv-4.7.0/.cache/ 51 | 52 | mkdir build 53 | cd build 54 | 55 | cmake -D CMAKE_BUILD_TYPE=Release \ 56 | -D WITH_CUDA=ON \ 57 | -D WITH_CUDNN=ON \ 58 | -D OPENCV_DNN_CUDA=ON \ 59 | -D WITH_CUBLAS=ON \ 60 | -D CUDA_TOOLKIT_ROOT_DIR=/usr/local/cuda \ 61 | -D OPENCV_ENABLE_NONFREE=ON \ 62 | -D CMAKE_INSTALL_PREFIX=/usr/local \ 63 | -D OPENCV_EXTRA_MODULES_PATH=../../opencv_contrib-4.7.0/modules .. 64 | 65 | make -j2 66 | sudo make install 67 | 68 | cd 69 | sudo rm -r ~/opencv_build 70 | cd ${current_dir} 71 | -------------------------------------------------------------------------------- /scripts/x86-cuda/opencv470-install.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | 4 | wget https://download.amovlab.com/model/deps/opencv-4.7.0.zip 5 | wget https://download.amovlab.com/model/deps/opencv_contrib-4.7.0.zip 6 | wget https://download.amovlab.com/model/deps/opencv_cache_x86-4.7.0.zip 7 | 8 | current_dir=$(pwd) 9 | package_dir="." 10 | mkdir ~/opencv_build 11 | 12 | 13 | if [ ! -d ""$package_dir"" ];then 14 | echo "\033[31m[ERROR]: $package_dir not exist!: \033[0m" 15 | exit 1 16 | fi 17 | 18 | # sudo add-apt-repository "deb http://security.ubuntu.com/ubuntu xenial-security main" 19 | # sudo add-apt-repository "deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu-ports/ xenial main multiverse restricted universe" 20 | sudo apt update 21 | sudo apt install -y build-essential 22 | sudo apt install -y cmake git libgtk2.0-dev pkg-config libavcodec-dev libavformat-dev libswscale-dev 23 | 24 | sudo add-apt-repository "deb http://security.ubuntu.com/ubuntu xenial-security main" 25 | sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 3B4FE6ACC0B21F32 26 | sudo apt update 27 | sudo apt install -y libjasper1 libjasper-dev 28 | 29 | sudo apt install -y python3-dev python3-numpy libtbb2 libtbb-dev libjpeg-dev libpng-dev libtiff-dev 30 | sudo apt install -y libdc1394-22-dev 31 | sudo apt install -y libcurl4 build-essential pkg-config cmake libopenblas-dev libeigen3-dev \ 32 | libtbb-dev libavcodec-dev libavformat-dev libgstreamer-plugins-base1.0-dev \ 33 | libgstreamer1.0-dev libswscale-dev libgtk-3-dev libpng-dev libjpeg-dev \ 34 | libcanberra-gtk-module libcanberra-gtk3-module 35 | 36 | 37 | echo "\033[32m[INFO]:\033[0m unzip opencv-4.7.0.zip ..." 38 | unzip -q -o $package_dir/opencv-4.7.0.zip -d ~/opencv_build 39 | 40 | echo "\033[32m[INFO]:\033[0m unzip opencv_contrib-4.7.0.zip ..." 41 | unzip -q -o $package_dir/opencv_contrib-4.7.0.zip -d ~/opencv_build 42 | 43 | echo "\033[32m[INFO]:\033[0m unzip opencv_cache_x86-4.7.0.zip ..." 44 | unzip -q -o $package_dir/opencv_cache_x86-4.7.0.zip -d ~/opencv_build 45 | 46 | 47 | sudo rm opencv-4.7.0.zip 48 | sudo rm opencv_contrib-4.7.0.zip 49 | sudo rm opencv_cache_x86-4.7.0.zip 50 | 51 | cd ~/opencv_build/opencv-4.7.0 52 | mkdir .cache 53 | 54 | cp -r ~/opencv_build/opencv_cache_x86-4.7.0/* ~/opencv_build/opencv-4.7.0/.cache/ 55 | 56 | mkdir build 57 | cd build 58 | 59 | cmake -D CMAKE_BUILD_TYPE=Release \ 60 | -D WITH_CUDA=OFF \ 61 | -D OPENCV_ENABLE_NONFREE=ON \ 62 | -D CMAKE_INSTALL_PREFIX=/usr/local \ 63 | -D OPENCV_EXTRA_MODULES_PATH=../../opencv_contrib-4.7.0/modules .. 64 | 65 | make -j2 66 | sudo make install 67 | 68 | cd 69 | sudo rm -r ~/opencv_build 70 | cd ${current_dir} 71 | -------------------------------------------------------------------------------- /scripts/x86-cuda/ubuntu2004-cudnn-12-0-for40series.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | echo -e "\033[32m[INFO]:\033[0m Please enter the folder path of the installation package: " 4 | # package_dir="/home/jario/Downloads/nv" 5 | 6 | wget https://download.amovlab.com/model/install/x86-nvidia/cuda_12.0.0_525.60.13_linux.run 7 | wget https://download.amovlab.com/model/install/x86-nvidia/cudnn-linux-x86_64-8.9.7.29_cuda12-archive.tar.xz 8 | wget https://download.amovlab.com/model/install/x86-nvidia/TensorRT-8.6.1.6.Linux.x86_64-gnu.cuda-12.0.tar.gz 9 | 10 | 11 | #cudnn安装 12 | package_dir="." 13 | cudnn_fn= $package_dir"/cudnn-linux-x86_64-8.9.7.29_cuda12-archive" 14 | tmp_dir= "/tmp" 15 | echo -e "\033[32m[INFO]:CUDNN installing ...\033[0m" 16 | tar -xvf $cudnn_fn -C $tmp_dir 17 | sudo cp $tmp_dir/cudnn-linux-86_64-8.9.7.29_cuda12-archive/include/cudnn* /usr/local/cuda/include/ 18 | sudo cp $tmp_dir/cudnn-linux-86_64-8.9.7.29_cuda12-archive/lib/libcudnn* /usr/local/cuda/lib64/ 19 | sudo chmod a+r /usr/local/cuda/include/cudnn* /usr/local/cuda/lib64/libcudnn* 20 | 21 | sudo ln -sf /usr/local/cuda/targets/x86_64-linux/lib/libcudnn_cnn_infer.so.8.9.7 /usr/local/cuda/targets/x86_64-linux/lib/libcudnn_cnn_infer.so.8 22 | sudo ln -sf /usr/local/cuda/targets/x86_64-linux/lib/libcudnn.so.8.9.7 /usr/local/cuda/targets/x86_64-linux/lib/libcudnn.so.8 23 | sudo ln -sf /usr/local/cuda/targets/x86_64-linux/lib/libcudnn_ops_train.so.8.9.7 /usr/local/cuda/targets/x86_64-linux/lib/libcudnn_ops_train.so.8 24 | sudo ln -sf /usr/local/cuda/targets/x86_64-linux/lib/libcudnn_adv_train.so.8.9.7 /usr/local/cuda/targets/x86_64-linux/lib/libcudnn_adv_train.so.8 25 | sudo ln -sf /usr/local/cuda/targets/x86_64-linux/lib/libcudnn_ops_infer.so.8.9.7 /usr/local/cuda/targets/x86_64-linux/lib/libcudnn_ops_infer.so.8 26 | sudo ln -sf /usr/local/cuda/targets/x86_64-linux/lib/libcudnn_cnn_train.so.8.9.7 /usr/local/cuda/targets/x86_64-linux/lib/libcudnn_cnn_train.so.8 27 | sudo ln -sf /usr/local/cuda/targets/x86_64-linux/lib/libcudnn_adv_infer.so.8.9.7 /usr/local/cuda/targets/x86_64-linux/lib/libcudnn_adv_infer.so.8 28 | 29 | #tensorrt安装 30 | tensorrt_fn="$package_dir/TensorRT-8.6.1.6.Linux.x86_64-gnu.cuda-12.0.tar.gz" 31 | echo -e "\033[32m[INFO]:Tensorrt installing ...\033[0m" 32 | # 获取 Python 版本 33 | python_version=$(python3 --version | awk '{print $2}') 34 | python_major=$(echo $python_version | cut -d '.' -f 2) 35 | 36 | # 解压 TensorRT 文件 37 | tar -xzvf $tensorrt_fn -C $HOME 38 | 39 | # 设置环境变量 40 | echo "export TENSORRT_DIR=\$HOME/TensorRT-8.6.1.6" >> ~/.bashrc 41 | echo "export LD_LIBRARY_PATH=\$TENSORRT_DIR/lib:\$LD_LIBRARY_PATH" >> ~/.bashrc 42 | echo "export LIBRARY_PATH=\$TENSORRT_DIR/lib:\$LIBRARY_PATH" >> ~/.bashrc 43 | 44 | # 切换到 TensorRT Python 目录 45 | cd $HOME/TensorRT-8.6.1.6/python 46 | 47 | # 安装 TensorRT 相关包 48 | python3 -m pip install tensorrt-8.6.1-cp3${python_major}-none-linux_x86_64.whl 49 | python3 -m pip install tensorrt_lean-8.6.1-cp3${python_major}-none-linux_x86_64.whl 50 | python3 -m pip install tensorrt_dispatch-8.6.1-cp3${python_major}-none-linux_x86_64.whl 51 | 52 | # 设置其他 LD_LIBRARY_PATH 环境变量 53 | echo "export PATH=/usr/local/cuda/bin\${PATH:+:\${PATH}}">> ~/.bashrc 54 | echo "export LD_LIBRARY_PATH=/usr/local/cuda/lib64\${LD_LIBRARY_PATH:+:\${LD_LIBRARY_PATH}}">> ~/.bashrc 55 | echo "export LD_LIBRARY_PATH=/usr/local/lib:/usr/local/lib:$HOME/TensorRT-8.6.1.6/lib:\$TENSORRT_DIR/lib:/usr/local/cuda/lib64" >> ~/.bashrc 56 | echo "export LD_LIBRARY_PATH=$HOME/TensorRT-8.6.1.6/targets/x86_64-linux-gnu/lib:\$LD_LIBRARY_PATH">> ~/.bashrc 57 | echo "export LD_LIBRARY_PATH=$HOME/.local/lib/python3.${python_major}/site-packages/nvidia/cusparse/lib:\$LD_LIBRARY_PATH" >> ~/.bashrc 58 | echo "export LD_LIBRARY_PATH=$HOME/.local/lib/python3.${python_major}/site-packages/nvidia/cudnn/lib:\$LD_LIBRARY_PATH" >> ~/.bashrc 59 | 60 | sudo rm $cudnn_fn 61 | sudo rm $tensorrt_fn 62 | 63 | # 结束 64 | echo "Cudnn与Tensorrt安装完毕。" 65 | 66 | -------------------------------------------------------------------------------- /scripts/x86-intel/configs-downloading.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash -e 2 | 3 | root_dir=${HOME}"/SpireCV/models" 4 | root_server="https://download.amovlab.com/model" 5 | 6 | sv_params1=${HOME}"/SpireCV/sv_algorithm_params.json" 7 | sv_params2=${HOME}"/SpireCV/sv_algorithm_params_coco_640.json" 8 | sv_params3=${HOME}"/SpireCV/sv_algorithm_params_coco_1280.json" 9 | camera_params1=${HOME}"/SpireCV/calib_webcam_640x480.yaml" 10 | camera_params2=${HOME}"/SpireCV/calib_webcam_1280x720.yaml" 11 | 12 | 13 | if [ ! -d ${root_dir} ]; then 14 | echo -e "\033[32m[INFO]: ${root_dir} not exist, creating it ... \033[0m" 15 | mkdir -p ${root_dir} 16 | fi 17 | 18 | if [ ! -f ${sv_params1} ]; then 19 | echo -e "\033[32m[INFO]: ${sv_params1} not exist, downloading ... \033[0m" 20 | wget -O ${sv_params1} ${root_server}/install/a-params/sv_algorithm_params.json 21 | fi 22 | if [ ! -f ${sv_params2} ]; then 23 | echo -e "\033[32m[INFO]: ${sv_params2} not exist, downloading ... \033[0m" 24 | wget -O ${sv_params2} ${root_server}/install/a-params/sv_algorithm_params_coco_640.json 25 | fi 26 | if [ ! -f ${sv_params3} ]; then 27 | echo -e "\033[32m[INFO]: ${sv_params3} not exist, downloading ... \033[0m" 28 | wget -O ${sv_params3} ${root_server}/install/a-params/sv_algorithm_params_coco_1280.json 29 | fi 30 | 31 | if [ ! -f ${camera_params1} ]; then 32 | echo -e "\033[32m[INFO]: ${camera_params1} not exist, downloading ... \033[0m" 33 | wget -O ${camera_params1} ${root_server}/install/c-params/calib_webcam_640x480.yaml 34 | fi 35 | if [ ! -f ${camera_params2} ]; then 36 | echo -e "\033[32m[INFO]: ${camera_params2} not exist, downloading ... \033[0m" 37 | wget -O ${camera_params2} ${root_server}/install/c-params/calib_webcam_1280x720.yaml 38 | fi 39 | 40 | -------------------------------------------------------------------------------- /scripts/x86-intel/ffmpeg-install.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | sudo apt install -y v4l-utils build-essential yasm cmake libtool libc6 libc6-dev unzip wget libeigen3-dev libfmt-dev libnuma1 libnuma-dev libx264-dev libx265-dev libfaac-dev libssl-dev v4l-utils 4 | wget https://ffmpeg.org/releases/ffmpeg-4.2.5.tar.bz2 5 | tar -xjf ffmpeg-4.2.5.tar.bz2 6 | cd ffmpeg-4.2.5 7 | ./configure \ 8 | --arch=x86_64 \ 9 | --disable-x86asm \ 10 | --enable-vaapi \ 11 | --enable-libmfx \ 12 | --enable-nonfree \ 13 | --enable-shared \ 14 | --enable-ffmpeg \ 15 | --enable-ffplay \ 16 | --enable-ffprobe \ 17 | --enable-libx264 \ 18 | --enable-libx265 \ 19 | --enable-gpl 20 | 21 | make -j8 22 | sudo make install 23 | cd .. 24 | sudo rm -r ffmpeg-4.2.5 25 | sudo rm ffmpeg-4.2.5.tar.bz2 26 | 27 | -------------------------------------------------------------------------------- /scripts/x86-intel/gst-install.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | sudo apt install -y libgstreamer1.0-dev libgstreamer-plugins-base1.0-dev 4 | sudo apt install -y libgstreamer-plugins-bad1.0-dev gstreamer1.0-plugins-base 5 | sudo apt install -y gstreamer1.0-plugins-good gstreamer1.0-plugins-bad 6 | sudo apt install -y gstreamer1.0-plugins-ugly gstreamer1.0-libav gstreamer1.0-doc 7 | sudo apt install -y gstreamer1.0-tools gstreamer1.0-x gstreamer1.0-alsa 8 | sudo apt install -y gstreamer1.0-gl gstreamer1.0-gtk3 gstreamer1.0-qt5 9 | sudo apt install -y gstreamer1.0-pulseaudio 10 | sudo apt install -y gtk-doc-tools 11 | sudo apt install -y libeigen3-dev libfmt-dev v4l-utils 12 | 13 | git clone https://gitee.com/jario-jin/gst-rtsp-server-b18.git 14 | cd gst-rtsp-server-b18 15 | ./autogen.sh 16 | make 17 | sudo make install 18 | cd .. 19 | sudo rm -r gst-rtsp-server-b18 20 | 21 | -------------------------------------------------------------------------------- /scripts/x86-intel/libva-install-gst.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | sudo apt-get install -y libmfx1 libmfx-tools libva-dev libmfx-dev intel-media-va-driver-non-free vainfo va-driver-all vdpau-va-driver 4 | echo "export LIBVA_DRIVER_NAME=i965" >> ~/.bashrc 5 | export LIBVA_DRIVER_NAME=i965 6 | 7 | -------------------------------------------------------------------------------- /scripts/x86-intel/libva-install.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | sudo apt-get install -y libmfx1 libmfx-tools libva-dev libmfx-dev intel-media-va-driver-non-free vainfo 4 | 5 | 6 | -------------------------------------------------------------------------------- /scripts/x86-intel/opencl-vaapi-install.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | curl -L https://repositories.intel.com/graphics/intel-graphics.key | sudo apt-key add - 4 | sudo apt-add-repository 'deb [arch=amd64] https://repositories.intel.com/graphics/ubuntu focal main' 5 | sudo apt-get update 6 | sudo apt-get install -y -q --no-install-recommends clinfo intel-opencl-icd intel-media-va-driver-non-free 7 | 8 | -------------------------------------------------------------------------------- /scripts/x86-intel/opencv470-intel-install.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | 4 | wget https://download.amovlab.com/model/deps/opencv-4.7.0.zip 5 | wget https://download.amovlab.com/model/deps/opencv_contrib-4.7.0.zip 6 | wget https://download.amovlab.com/model/deps/opencv_cache_x86-4.7.0.zip 7 | 8 | current_dir=$(pwd) 9 | package_dir="." 10 | mkdir ~/opencv_build 11 | 12 | 13 | if [ ! -d ""$package_dir"" ];then 14 | echo "\033[31m[ERROR]: $package_dir not exist!: \033[0m" 15 | exit 1 16 | fi 17 | 18 | # sudo add-apt-repository "deb http://security.ubuntu.com/ubuntu xenial-security main" 19 | # sudo add-apt-repository "deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu-ports/ xenial main multiverse restricted universe" 20 | sudo apt update 21 | sudo apt install -y build-essential 22 | sudo apt install -y cmake git libgtk2.0-dev pkg-config libavcodec-dev libavformat-dev libswscale-dev 23 | 24 | sudo add-apt-repository "deb http://security.ubuntu.com/ubuntu xenial-security main" 25 | sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 3B4FE6ACC0B21F32 26 | sudo apt update 27 | sudo apt install -y libjasper1 libjasper-dev 28 | 29 | sudo apt install -y python3-dev python3-numpy libtbb2 libtbb-dev libjpeg-dev libpng-dev libtiff-dev 30 | sudo apt install -y libdc1394-22-dev 31 | sudo apt install -y libcurl4 build-essential pkg-config cmake libopenblas-dev libeigen3-dev \ 32 | libtbb-dev libavcodec-dev libavformat-dev libgstreamer-plugins-base1.0-dev \ 33 | libgstreamer1.0-dev libswscale-dev libgtk-3-dev libpng-dev libjpeg-dev \ 34 | libcanberra-gtk-module libcanberra-gtk3-module 35 | 36 | 37 | echo "\033[32m[INFO]:\033[0m unzip opencv-4.7.0.zip ..." 38 | unzip -q -o $package_dir/opencv-4.7.0.zip -d ~/opencv_build 39 | 40 | echo "\033[32m[INFO]:\033[0m unzip opencv_contrib-4.7.0.zip ..." 41 | unzip -q -o $package_dir/opencv_contrib-4.7.0.zip -d ~/opencv_build 42 | 43 | echo "\033[32m[INFO]:\033[0m unzip opencv_cache_x86-4.7.0.zip ..." 44 | unzip -q -o $package_dir/opencv_cache_x86-4.7.0.zip -d ~/opencv_build 45 | 46 | 47 | sudo rm opencv-4.7.0.zip 48 | sudo rm opencv_contrib-4.7.0.zip 49 | sudo rm opencv_cache_x86-4.7.0.zip 50 | 51 | cd ~/opencv_build/opencv-4.7.0 52 | mkdir .cache 53 | 54 | cp -r ~/opencv_build/opencv_cache_x86-4.7.0/* ~/opencv_build/opencv-4.7.0/.cache/ 55 | 56 | mkdir build 57 | cd build 58 | 59 | cmake -D CMAKE_BUILD_TYPE=Release \ 60 | -D WITH_CUDA=OFF \ 61 | -D OPENCV_ENABLE_NONFREE=ON \ 62 | -D CMAKE_INSTALL_PREFIX=/usr/local \ 63 | -D OPENCV_EXTRA_MODULES_PATH=../../opencv_contrib-4.7.0/modules \ 64 | -D BUILD_PNG=ON \ 65 | -D BUILD_JASPER=ON \ 66 | -D BUILD_JPEG=ON \ 67 | -D BUILD_TIFF=ON \ 68 | -D BUILD_ZLIB=ON \ 69 | -D WITH_JPEG=ON \ 70 | -D WITH_PNG=ON \ 71 | -D WITH_JASPER=ON \ 72 | -D WITH_TIFF=ON \ 73 | -D WITH_TBB=ON \ 74 | -D WITH_ZLIB=ON \ 75 | -D WITH_OPENCL=ON .. 76 | 77 | make -j4 78 | sudo make install 79 | 80 | cd 81 | sudo rm -r ~/opencv_build 82 | cd ${current_dir} 83 | -------------------------------------------------------------------------------- /scripts/x86-intel/openvino-install.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | sudo mkdir /opt/intel 4 | 5 | current_dir=$(pwd) 6 | cd ${HOME}/Downloads 7 | 8 | curl -L https://storage.openvinotoolkit.org/repositories/openvino/packages/2022.3.1/linux/l_openvino_toolkit_ubuntu20_2022.3.1.9227.cf2c7da5689_x86_64.tgz --output openvino_2022.3.1.tgz 9 | tar -xf openvino_2022.3.1.tgz 10 | sudo mv l_openvino_toolkit_ubuntu20_2022.3.1.9227.cf2c7da5689_x86_64 /opt/intel/openvino_2022.3.1 11 | 12 | cd /opt/intel/openvino_2022.3.1 13 | sudo -E ./install_dependencies/install_openvino_dependencies.sh 14 | 15 | cd /opt/intel 16 | sudo ln -s openvino_2022.3.1 openvino_2022 17 | 18 | echo "source /opt/intel/openvino_2022/setupvars.sh" >> ~/.bashrc 19 | sh /opt/intel/openvino_2022/setupvars.sh 20 | cd ${current_dir} 21 | -------------------------------------------------------------------------------- /scripts/x86-intel/zlm-server-install.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | 4 | current_dir=$(pwd) 5 | cd ${HOME}/SpireCV 6 | git clone https://gitee.com/jario-jin/ZLMediaKit.git 7 | cd ZLMediaKit 8 | git submodule update --init 9 | mkdir build 10 | cd build 11 | cmake .. 12 | make -j4 13 | cd .. 14 | cd .. 15 | 16 | mkdir ZLM 17 | cd ZLM 18 | cp ../ZLMediaKit/release/linux/Debug/MediaServer . 19 | cp ../ZLMediaKit/release/linux/Debug/config.ini . 20 | 21 | cd ${current_dir} 22 | 23 | -------------------------------------------------------------------------------- /utils/sv_crclib.h: -------------------------------------------------------------------------------- 1 | #ifndef __CRCLIB_H__ 2 | #define __CRCLIB_H__ 3 | 4 | #include 5 | 6 | namespace sv { 7 | 8 | uint8_t crc4_itu(uint8_t *data, uint16_t length); 9 | uint8_t crc5_epc(uint8_t *data, uint16_t length); 10 | uint8_t crc5_itu(uint8_t *data, uint16_t length); 11 | uint8_t crc5_usb(uint8_t *data, uint16_t length); 12 | uint8_t crc6_itu(uint8_t *data, uint16_t length); 13 | uint8_t crc7_mmc(uint8_t *data, uint16_t length); 14 | uint8_t crc8(uint8_t *data, uint16_t length); 15 | uint8_t crc8_itu(uint8_t *data, uint16_t length); 16 | uint8_t crc8_rohc(uint8_t *data, uint16_t length); 17 | uint8_t crc8_maxim(uint8_t *data, uint16_t length);//DS18B20 18 | uint16_t crc16_ibm(uint8_t *data, uint16_t length); 19 | uint16_t crc16_maxim(uint8_t *data, uint16_t length); 20 | uint16_t crc16_usb(uint8_t *data, uint16_t length); 21 | uint16_t crc16_modbus(uint8_t *data, uint16_t length); 22 | uint16_t crc16_ccitt(uint8_t *data, uint16_t length); 23 | uint16_t crc16_ccitt_false(uint8_t *data, uint16_t length); 24 | uint16_t crc16_x25(uint8_t *data, uint16_t length); 25 | uint16_t crc16_xmodem(uint8_t *data, uint16_t length); 26 | uint16_t crc16_dnp(uint8_t *data, uint16_t length); 27 | uint32_t crc32(uint8_t *data, uint16_t length); 28 | uint32_t crc32_mpeg_2(uint8_t *data, uint16_t length); 29 | 30 | } 31 | 32 | #endif // __CRCLIB_H__ 33 | -------------------------------------------------------------------------------- /utils/sv_util.h: -------------------------------------------------------------------------------- 1 | #ifndef __SV_UTIL__ 2 | #define __SV_UTIL__ 3 | 4 | #include 5 | #include 6 | #include 7 | 8 | 9 | namespace sv { 10 | 11 | 12 | struct TimeInfo 13 | { 14 | int year, mon, day, hour, min, sec; 15 | }; 16 | 17 | /************* time-related functions *************/ 18 | void _get_sys_time(TimeInfo& t_info); 19 | std::string _get_time_str(); 20 | 21 | /************* std::string-related functions *************/ 22 | std::vector _split(const std::string& srcstr, const std::string& delimeter); 23 | bool _startswith(const std::string& str, const std::string& start); 24 | bool _endswith(const std::string& str, const std::string& end); 25 | std::string _trim(const std::string& str); 26 | int _comp_str_idx(const std::string& in_str, const std::string* str_list, int len); 27 | bool _comp_str_greater(const std::string& a, const std::string& b); 28 | bool _comp_str_lesser(const std::string& a, const std::string& b); 29 | 30 | /************* file-related functions ***************/ 31 | std::string _get_home(); 32 | bool _is_file_exist(std::string& fn); 33 | void _list_dir(std::string dir, std::vector& files, std::string suffixs="", std::string prefix="", bool r=false); 34 | 35 | } 36 | 37 | #endif // __SV_UTIL__ 38 | -------------------------------------------------------------------------------- /video_io/ffmpeg/x86_cuda/bs_common.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | #include 4 | #include 5 | 6 | // 获取当前系统启动以来的毫秒数 7 | static int64_t getCurTime() 8 | { 9 | // tv_sec (s) tv_nsec (ns-纳秒) 10 | struct timespec now; 11 | clock_gettime(CLOCK_MONOTONIC, &now); 12 | return (now.tv_sec * 1000 + now.tv_nsec / 1000000); 13 | } 14 | 15 | 16 | 17 | struct VideoFrame 18 | { 19 | public: 20 | enum VideoFrameType 21 | { 22 | BGR = 0, 23 | YUV420P, 24 | 25 | }; 26 | // VideoFrame(VideoFrameType type, int width, int height,int size) 27 | VideoFrame(VideoFrameType type, int width, int height) 28 | { 29 | this->type = type; 30 | this->width = width; 31 | this->height = height; 32 | this->size = width*height*3; 33 | this->data = new uint8_t[this->size]; 34 | } 35 | ~VideoFrame() 36 | { 37 | delete[] this->data; 38 | this->data = nullptr; 39 | } 40 | 41 | VideoFrameType type; 42 | int size; 43 | int width; 44 | int height; 45 | uint8_t *data; 46 | }; 47 | 48 | 49 | 50 | -------------------------------------------------------------------------------- /video_io/ffmpeg/x86_cuda/bs_push_streamer.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | #include 6 | 7 | 8 | #include 9 | // #include 10 | 11 | #include 12 | #include 13 | extern "C" 14 | { 15 | #include 16 | #include 17 | #include 18 | #include 19 | // #include 20 | #include 21 | } 22 | 23 | #include 24 | 25 | #include "bs_common.h" 26 | 27 | 28 | class BsPushStreamer 29 | { 30 | public: 31 | BsPushStreamer(); 32 | ~BsPushStreamer(); 33 | 34 | // 用于初始化视频推流,仅调用一次 35 | bool setup(std::string name, int width, int height, int fps, std::string encoder, int bitrate); 36 | // 推流一帧图像,在循环中被调用 37 | void stream(cv::Mat& image); 38 | 39 | 40 | 41 | 42 | // 连接流媒体服务器 43 | bool connect(std::string name, int width, int height, int fps, std::string encoder, int bitrate); 44 | void start(); 45 | void stop(){push_running = false;}; 46 | 47 | // 编码视频帧并推流 48 | static void encodeVideoAndWriteStreamThread(void* arg); 49 | 50 | bool videoFrameQisEmpty(); 51 | 52 | int writePkt(AVPacket *pkt); 53 | 54 | 55 | // 上下文 56 | AVFormatContext *mFmtCtx = nullptr; 57 | // 视频帧 58 | AVCodecContext *mVideoCodecCtx = NULL; 59 | AVStream *mVideoStream = NULL; 60 | 61 | VideoFrame* mVideoFrame = NULL; 62 | 63 | 64 | int mVideoIndex = -1; 65 | 66 | // YAML::Node yaml_cfg; 67 | 68 | private: 69 | 70 | 71 | // 从mRGB_VideoFrameQ里面获取RGBframe 72 | bool getVideoFrame(VideoFrame *&frame, int &frameQSize); 73 | 74 | 75 | // bgr24转yuv420p 76 | unsigned char clipValue(unsigned char x, unsigned char min_val, unsigned char max_val); 77 | bool bgr24ToYuv420p(unsigned char *bgrBuf, int w, int h, unsigned char *yuvBuf); 78 | 79 | 80 | bool push_running = false; 81 | bool nd_push_frame = false; 82 | 83 | // 视频帧 84 | std::queue mRGB_VideoFrameQ; 85 | std::mutex mRGB_VideoFrameQ_mtx; 86 | 87 | 88 | // 推流锁 89 | std::mutex mWritePkt_mtx; 90 | std::thread* mThread; 91 | 92 | 93 | }; -------------------------------------------------------------------------------- /video_io/ffmpeg/x86_cuda/bs_video_saver.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | #include 6 | 7 | 8 | #include 9 | // #include 10 | 11 | #include 12 | #include 13 | extern "C" 14 | { 15 | #include 16 | #include 17 | #include 18 | #include 19 | // #include 20 | #include 21 | } 22 | 23 | #include 24 | 25 | #include "bs_common.h" 26 | 27 | 28 | class BsVideoSaver 29 | { 30 | public: 31 | BsVideoSaver(); 32 | ~BsVideoSaver(); 33 | 34 | // 用于初始化视频推流,仅调用一次 35 | bool setup(std::string name, int width, int height, int fps, std::string encoder, int bitrate); 36 | // 推流一帧图像,在循环中被调用 37 | void write(cv::Mat& image); 38 | 39 | 40 | // 连接流媒体服务器 41 | bool init(std::string name, int width, int height, int fps, std::string encoder, int bitrate); 42 | void start(); 43 | void stop(); 44 | 45 | // 编码视频帧并推流 46 | static void encodeVideoAndSaveThread(void* arg); 47 | 48 | bool videoFrameQisEmpty(); 49 | 50 | int writePkt(AVPacket *pkt); 51 | 52 | 53 | // 上下文 54 | AVFormatContext *mFmtCtx = nullptr; 55 | // 视频帧 56 | AVCodecContext *mVideoCodecCtx = NULL; 57 | AVStream *mVideoStream = NULL; 58 | 59 | 60 | int mVideoIndex = -1; 61 | 62 | 63 | private: 64 | 65 | // 从mRGB_VideoFrameQ里面获取RGBframe 66 | bool getVideoFrame(VideoFrame *&frame, int &frameQSize); 67 | 68 | 69 | // bgr24转yuv420p 70 | unsigned char clipValue(unsigned char x, unsigned char min_val, unsigned char max_val); 71 | bool bgr24ToYuv420p(unsigned char *bgrBuf, int w, int h, unsigned char *yuvBuf); 72 | 73 | int width = -1; 74 | int height = -1; 75 | 76 | 77 | bool push_running = false; 78 | bool nd_push_frame = false; 79 | 80 | // 视频帧 81 | std::queue mRGB_VideoFrameQ; 82 | std::mutex mRGB_VideoFrameQ_mtx; 83 | 84 | 85 | // 推流锁 86 | std::mutex mWritePkt_mtx; 87 | std::thread* mThread = nullptr; 88 | 89 | 90 | }; -------------------------------------------------------------------------------- /video_io/ffmpeg/x86_intel/bs_common.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | #include 4 | #include 5 | 6 | // 获取当前系统启动以来的毫秒数 7 | static int64_t getCurTime() 8 | { 9 | // tv_sec (s) tv_nsec (ns-纳秒) 10 | struct timespec now; 11 | clock_gettime(CLOCK_MONOTONIC, &now); 12 | return (now.tv_sec * 1000 + now.tv_nsec / 1000000); 13 | } 14 | 15 | 16 | 17 | struct VideoFrame 18 | { 19 | public: 20 | enum VideoFrameType 21 | { 22 | BGR = 0, 23 | RGB , 24 | YUV420P, 25 | 26 | }; 27 | // VideoFrame(VideoFrameType type, int width, int height,int size) 28 | VideoFrame(VideoFrameType type, int width, int height) 29 | { 30 | this->type = type; 31 | this->width = width; 32 | this->height = height; 33 | this->size = width*height*3; 34 | this->data = new uint8_t[this->size]; 35 | } 36 | ~VideoFrame() 37 | { 38 | delete[] this->data; 39 | this->data = nullptr; 40 | } 41 | 42 | VideoFrameType type; 43 | int size; 44 | int width; 45 | int height; 46 | uint8_t *data; 47 | }; 48 | 49 | 50 | 51 | -------------------------------------------------------------------------------- /video_io/ffmpeg/x86_intel/bs_push_streamer.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | #include 6 | 7 | // #include 8 | // #include 9 | 10 | #include 11 | #include 12 | extern "C" 13 | { 14 | #include 15 | #include 16 | #include 17 | #include 18 | // #include 19 | #include 20 | 21 | #include 22 | #include 23 | } 24 | 25 | #include 26 | #include 27 | #include "bs_common.h" 28 | 29 | using namespace cv; 30 | 31 | class BsPushStreamer 32 | { 33 | public: 34 | BsPushStreamer(); 35 | ~BsPushStreamer(); 36 | 37 | // 用于初始化视频推流,仅调用一次 38 | bool setup(std::string name, int width, int height, int fps, std::string encoder, int bitrate); 39 | // 推流一帧图像,在循环中被调用 40 | void stream(cv::Mat &image); 41 | 42 | // 连接流媒体服务器 43 | bool connect(std::string name, int width, int height, int fps, std::string encoder, int bitrate); 44 | void start(); 45 | void stop() { push_running = false; }; 46 | 47 | // 编码视频帧并推流 48 | static void encodeVideoAndWriteStreamThread(void *arg); 49 | 50 | bool videoFrameQisEmpty(); 51 | 52 | int writePkt(AVPacket *pkt); 53 | 54 | // 上下文 55 | AVFormatContext *mFmtCtx = nullptr; 56 | // 视频帧 57 | AVCodecContext *mVideoCodecCtx = NULL; 58 | AVStream *mVideoStream = NULL; 59 | 60 | VideoFrame *mVideoFrame = NULL; 61 | AVBufferRef *hw_device_ctx = NULL; 62 | 63 | int err; 64 | 65 | int mVideoIndex = -1; 66 | 67 | // YAML::Node yaml_cfg; 68 | 69 | private: 70 | // 从mRGB_VideoFrameQ里面获取RGBframe 71 | bool getVideoFrame(VideoFrame *&frame, int &frameQSize); 72 | 73 | // bgr24转yuv420p 74 | unsigned char clipValue(unsigned char x, unsigned char min_val, unsigned char max_val); 75 | bool bgr24ToYuv420p(unsigned char *bgrBuf, int w, int h, unsigned char *yuvBuf); 76 | void Rgb2NV12(const unsigned char I[], int step, const int image_width, const int image_height, unsigned char J[]); 77 | 78 | bool push_running = false; 79 | bool nd_push_frame = false; 80 | 81 | // 视频帧 82 | std::queue mRGB_VideoFrameQ; 83 | std::mutex mRGB_VideoFrameQ_mtx; 84 | 85 | // 推流锁 86 | std::mutex mWritePkt_mtx; 87 | std::thread *mThread; 88 | }; 89 | -------------------------------------------------------------------------------- /video_io/ffmpeg/x86_intel/bs_video_saver.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | #include 6 | 7 | 8 | #include 9 | // #include 10 | 11 | #include 12 | #include 13 | extern "C" 14 | { 15 | #include 16 | #include 17 | #include 18 | #include 19 | // #include 20 | #include 21 | 22 | #include 23 | #include 24 | } 25 | 26 | #include 27 | #include 28 | #include "bs_common.h" 29 | 30 | using namespace cv; 31 | class BsVideoSaver 32 | { 33 | public: 34 | BsVideoSaver(); 35 | ~BsVideoSaver(); 36 | 37 | // 用于初始化视频推流,仅调用一次 38 | bool setup(std::string name, int width, int height, int fps, std::string encoder, int bitrate); 39 | // 推流一帧图像,在循环中被调用 40 | void write(cv::Mat& image); 41 | 42 | 43 | // 连接流媒体服务器 44 | bool init(std::string name, int width, int height, int fps, std::string encoder, int bitrate); 45 | void start(); 46 | void stop(); 47 | 48 | // 编码视频帧并推流 49 | static void encodeVideoAndSaveThread(void* arg); 50 | 51 | bool videoFrameQisEmpty(); 52 | 53 | int writePkt(AVPacket *pkt); 54 | 55 | 56 | // 上下文 57 | AVFormatContext *mFmtCtx = nullptr; 58 | // 视频帧 59 | AVCodecContext *mVideoCodecCtx = NULL; 60 | AVStream *mVideoStream = NULL; 61 | 62 | AVBufferRef *hw_device_ctx = NULL; 63 | 64 | int err; 65 | 66 | 67 | int mVideoIndex = -1; 68 | 69 | 70 | private: 71 | 72 | // 从mRGB_VideoFrameQ里面获取RGBframe 73 | bool getVideoFrame(VideoFrame *&frame, int &frameQSize); 74 | 75 | 76 | // bgr24转yuv420p 77 | unsigned char clipValue(unsigned char x, unsigned char min_val, unsigned char max_val); 78 | bool bgr24ToYuv420p(unsigned char *bgrBuf, int w, int h, unsigned char *yuvBuf); 79 | void Rgb2NV12(const unsigned char I[], int step, const int image_width, const int image_height, unsigned char J[]); 80 | // void RGB2YUV_NV12(uint8_t* rgbBufIn, uint8_t* yuvBufOut, int nWidth, int nHeight); 81 | 82 | int width = -1; 83 | int height = -1; 84 | 85 | 86 | 87 | 88 | bool push_running = false; 89 | bool nd_push_frame = false; 90 | 91 | // 视频帧 92 | std::queue mRGB_VideoFrameQ; 93 | std::mutex mRGB_VideoFrameQ_mtx; 94 | 95 | 96 | // 推流锁 97 | std::mutex mWritePkt_mtx; 98 | std::thread* mThread = nullptr; 99 | 100 | 101 | }; 102 | -------------------------------------------------------------------------------- /video_io/gstreamer/streamer_gstreamer_impl.h: -------------------------------------------------------------------------------- 1 | #ifndef __SV_STREAM_GSTREAMER_IMPL__ 2 | #define __SV_STREAM_GSTREAMER_IMPL__ 3 | 4 | #include "sv_core.h" 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | 11 | #ifdef WITH_GSTREAMER 12 | #include 13 | #include 14 | #include 15 | #include // for sockaddr_in 16 | #endif 17 | 18 | 19 | namespace sv { 20 | 21 | 22 | class VideoStreamerGstreamerImpl 23 | { 24 | public: 25 | VideoStreamerGstreamerImpl(); 26 | ~VideoStreamerGstreamerImpl(); 27 | 28 | bool gstreamerSetup(VideoStreamerBase* base_); 29 | bool gstreamerIsOpened(); 30 | void gstreamerWrite(cv::Mat img_); 31 | void gstreamerRelease(); 32 | 33 | int _rtsp_port; 34 | std::string _url; 35 | int _bitrate; 36 | cv::Size _stream_size; 37 | 38 | #ifdef WITH_GSTREAMER 39 | cv::VideoWriter _stream_writer; 40 | GstRTSPServer *_server; 41 | GstRTSPMountPoints *_mounts; 42 | GstRTSPMediaFactory *_factory; 43 | #endif 44 | }; 45 | 46 | 47 | } 48 | #endif 49 | -------------------------------------------------------------------------------- /video_io/gstreamer/writer_gstreamer_impl.cpp: -------------------------------------------------------------------------------- 1 | #include "writer_gstreamer_impl.h" 2 | #include 3 | #include 4 | 5 | 6 | 7 | namespace sv { 8 | 9 | 10 | VideoWriterGstreamerImpl::VideoWriterGstreamerImpl() 11 | { 12 | } 13 | VideoWriterGstreamerImpl::~VideoWriterGstreamerImpl() 14 | { 15 | } 16 | 17 | bool VideoWriterGstreamerImpl::gstreamerSetup(VideoWriterBase* base_, std::string file_name_) 18 | { 19 | this->_file_path = base_->getFilePath(); 20 | this->_fps = base_->getFps(); 21 | this->_image_size = base_->getSize(); 22 | 23 | #ifdef WITH_GSTREAMER 24 | bool opend = false; 25 | #ifdef PLATFORM_JETSON 26 | std::string pipeline = "appsrc ! videoconvert ! nvvidconv ! video/x-raw(memory:NVMM) ! nvv4l2h264enc ! h264parse ! matroskamux ! filesink location=" + this->_file_path + file_name_ + ".avi"; 27 | opend = this->_writer.open(pipeline, cv::VideoWriter::fourcc('m','p','4','v'), this->_fps, this->_image_size); 28 | #endif 29 | #ifdef PLATFORM_X86_INTEL 30 | std::string pipeline = "appsrc ! videoconvert ! vaapipostproc ! vaapih264enc ! h264parse ! matroskamux ! filesink location=" + this->_file_path + file_name_ + ".avi"; 31 | opend = this->_writer.open(pipeline, cv::VideoWriter::fourcc('m','p','4','v'), this->_fps, this->_image_size); 32 | #else 33 | opend = this->_writer.open(this->_file_path + file_name_ + ".avi", cv::VideoWriter::fourcc('x','v','i','d'), this->_fps, this->_image_size); 34 | #endif 35 | return opend; 36 | #endif 37 | return false; 38 | } 39 | 40 | bool VideoWriterGstreamerImpl::gstreamerIsOpened() 41 | { 42 | #ifdef WITH_GSTREAMER 43 | return this->_writer.isOpened(); 44 | #endif 45 | return false; 46 | } 47 | 48 | void VideoWriterGstreamerImpl::gstreamerWrite(cv::Mat img_) 49 | { 50 | #ifdef WITH_GSTREAMER 51 | this->_writer << img_; 52 | #endif 53 | } 54 | 55 | void VideoWriterGstreamerImpl::gstreamerRelease() 56 | { 57 | #ifdef WITH_GSTREAMER 58 | if (this->_writer.isOpened()) 59 | this->_writer.release(); 60 | #endif 61 | } 62 | 63 | 64 | } 65 | 66 | -------------------------------------------------------------------------------- /video_io/gstreamer/writer_gstreamer_impl.h: -------------------------------------------------------------------------------- 1 | #ifndef __SV_WRITER_GSTREAMER_IMPL__ 2 | #define __SV_WRITER_GSTREAMER_IMPL__ 3 | 4 | #include "sv_core.h" 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | 11 | 12 | namespace sv { 13 | 14 | 15 | class VideoWriterGstreamerImpl 16 | { 17 | public: 18 | VideoWriterGstreamerImpl(); 19 | ~VideoWriterGstreamerImpl(); 20 | 21 | bool gstreamerSetup(VideoWriterBase* base_, std::string file_name_); 22 | bool gstreamerIsOpened(); 23 | void gstreamerWrite(cv::Mat img_); 24 | void gstreamerRelease(); 25 | 26 | std::string _file_path; 27 | double _fps; 28 | cv::Size _image_size; 29 | 30 | #ifdef WITH_GSTREAMER 31 | cv::VideoWriter _writer; 32 | #endif 33 | }; 34 | 35 | 36 | } 37 | #endif 38 | --------------------------------------------------------------------------------