std::cout << "***************************" <<std::endl; yolov5trt->detect_api(color_img, conf_thre, is_seg); res_boxes = yolov5trt->res; boxes.clear(); for (int id = 0; id < res_boxes.size(); id++) { this->Draw_mask_bbox(res_boxes[id]); // int dist = yolov5trt->get_distance(resized_box, depth_img, 24); int dist = -1; b.cls = all_classes[class_names[res_boxes[id].class_id]]; b.box = resized_box; b.conf = res_boxes[id].conf; // b.dist = (dist / 1000); b.dist = dist; boxes.push_back(b); std::cout << "class_name: " << class_names[res_boxes[id].class_id] << " conf: " << res_boxes[id].conf << " dist: " << dist << std::endl; }
时间: 2024-04-21 12:24:13 浏览: 49
这段代码包含了一系列操作,用于进行目标检测并处理检测结果。
首先,使用`std::cout`打印一条分隔线。
然后,调用`yolov5trt->detect_api()`函数进行目标检测。`color_img`是输入的彩色图像,`conf_thre`是置信度阈值,`is_seg`表示是否进行语义分割。检测结果存储在`res_boxes`中。
接下来,清空`boxes`容器,并通过遍历`res_boxes`中的每个检测结果,调用`this->Draw_mask_bbox()`函数绘制目标框。
在每次循环中,获取目标类别的名称,并将其存储在变量`b.cls`中。将调整大小后的框坐标存储在`b.box`中,将置信度存储在`b.conf`中。
注释掉的代码行`int dist = yolov5trt->get_distance(resized_box, depth_img, 24);`是计算目标距离的操作,这里将其设置为-1。
将`b.dist`设置为距离值(这里为-1)。
将结构体`b`存储在容器`boxes`中。
最后,使用`std::cout`打印出目标类别、置信度和距离的信息。
这段代码的作用是将目标检测结果处理成一组结构体,并输出每个目标的类别、置信度和距离信息。
相关问题
std::string轉char*
要将`std::string`转换为`char*`,你可以使用`c_str()`函数。这个函数返回一个指向`std::string`内部字符数组的指针。
以下是一个示例代码:
```cpp
#include <iostream>
#include <string>
int main() {
std::string str = "Hello, World!";
const char* charPtr = str.c_str();
std::cout << "转换后的char*:" << charPtr << std::endl;
return 0;
}
```
在上述代码中,我们使用`c_str()`函数将`std::string`对象转换为`const char*`类型的指针。然后,我们将这个指针打印出来。
需要注意的是,`c_str()`函数返回的指针指向的是`std::string`内部字符数组的首地址。因此,当`std::string`对象被销毁或者修改时,这个指针将变得无效。确保在使用指向`c_str()`返回的指针之前,`std::string`对象仍然有效。
std::string 转 char*
可以使用`c_str()`函数将`std::string`转换为`const char*`,然后再将其转换为`char*`,示例代码如下:
```cpp
#include <iostream>
#include <cstring>
int main() {
std::string str = "Hello World!";
char* charStr = new char[str.length() + 1];
std::strcpy(charStr, str.c_str());
std::cout << charStr << std::endl;
delete[] charStr;
return 0;
}
```
注意,使用完`char*`之后,需要手动释放内存。