参考:链接:https://www.freesion.com/article/3585644384/,根据内参获取真实位置
/// https://blog.youkuaiyun.com/SFM2020/article/details/84591758
yolov3-tiny下载:GitHub - smarthomefans/darknet-test: darknet 测试
文件结构

.h文件
#include <iostream>
#include <string>
#include <vector>
#include <chrono>
#include <mutex> //定义了C++11标准中的一些互斥访问的类与方法
#include <thread> //线程头文件
#include <opencv2/opencv.hpp>
#include <opencv2/core/core.hpp>
#include <opencv2/imgproc/types_c.h>
#include <opencv2/imgproc/imgproc.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/objdetect/objdetect.hpp>
#include <opencv2/dnn.hpp>
#include <algorithm>
#include<librealsense2/rs.hpp>
#include<librealsense2/rsutil.h>
using namespace std;
using namespace cv;
using namespace dnn;
#define limit_L(a,b) (a-b>0)?(a-b):(0)
#define limit_H(a,b,max) (a+b>max)?(max):(a+b)
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
#define STREAM RS2_STREAM_DEPTH // rs2_stream is a types of data provided by RealSense device //
#define FORMAT RS2_FORMAT_Z16 // rs2_format identifies how binary data is encoded within a frame //
#define WIDTH 640 // Defines the number of columns for each frame or zero for auto resolve//
#define HEIGHT 480 // Defines the number of lines for each frame or zero for auto resolve //
#define FPS 30 // Defines the rate of frames per second //
#define STREAM_INDEX 0 // Defines the stream index, used for multiple streams of the same type //
#define HEIGHT_RATIO 20 // Defines the height ratio between the original frame to the new frame //
#define WIDTH_RATIO 10 // Defines the width ratio between the original frame to the new frame //
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
#define STREAM1 RS2_STREAM_COLOR // rs2_stream is a types of data provided by RealSense device //
#define FORMAT1 RS2_FORMAT_RGB8 // rs2_format identifies how binary data is encoded within a frame //
#define FPS1 30 // Defines the rate of frames per second //
#define STREAM_INDEX 0 // Defines the stream index, used for multiple streams of the same type //
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Remove the bounding boxes with low confidence using non-maxima suppression
void postprocess(Mat& frame, const vector<Mat>& out);
// Draw the predicted bounding box
void drawPred(int classId, float conf, int left, int top, int right, int bottom, Mat& frame);
// Get the names of the output layers
vector<String> getOutputsNames(const Net& net);
void detect_camera(string modelWeights, string modelConfiguration, string classesFile);
void postprocess(Mat& frame, const vector<Mat>& outs);
void drawPred(int classId, float conf, int left, int top, int right, int bottom, Mat& frame);
vector<String> getOutputsNames(const Net& net);
float get_depth_unit_value(const rs2_device* const dev);
uint16_t get_color_depth(Mat color_c,rs2_intrinsics color_intri,Mat depth_c,int color_cols,int color_ro

该博客介绍了一种结合RealSense深度相机和YOLOv3目标检测算法的方法。首先,通过OpenCV加载YOLOv3模型并进行目标检测,然后利用RealSense库获取深度信息。通过深度信息,可以对检测到的目标进行3D定位。此外,还展示了如何处理和显示检测结果,并提供了C++代码示例。
最低0.47元/天 解锁文章
1291





