enum ObjectType { UNKNOWN = 0, UNKNOWN_MOVABLE = 1, UNKNOWN_UNMOVABLE = 2, PEDESTRIAN = 3, BICYCLE = 4, VEHICLE = 5, MAX_OBJECT_TYPE = 6 }; double dist[MAX_OBJECT_TYPE][MAX_OBJECT_TYPE] = { {0.2, 0.3, 0.4, 0.5, 0.6, 1}, {0.3, 0.2, 0.3, 0.4, 0.5, 0.6}, {0.4, 0.3, 0.2, 0.3, 0.4, 0.5}, {0.5, 0.4, 0.3, 0.2, 0.3, 0.4}, {0.6, 0.5, 0.3, 0.4, 0.2, 0.3}, {1 , 0.6, 0.5, 0.4, 0.3, 0.2} }; int main() { int x, y; cout << ""; cin >> x >> y; if (x < 0 || x >= MAX_OBJECT_TYPE || y < 0 || y >= MAX_OBJECT_TYPE) { cout << "Invalid coordinates!" << endl; return 0; } cout << "dist[" << x << "][" << y << "] = " << dist[x][y] << endl; AINFO << "ComputeDIFOBJcameracamera distance: " << dist;//计算两个物体之间的距离 return dist[x][y]; }改写为读取相机目标类别输出表格对应值
时间: 2024-03-11 21:50:39 浏览: 53
EnumTools_v1_3_Ninject_dependency_enumtools_
你可以尝试以下代码来读取相机目标类别并输出对应值:
```
#include <iostream>
#include <string>
#include <map>
using namespace std;
enum ObjectType { UNKNOWN = 0, UNKNOWN_MOVABLE = 1, UNKNOWN_UNMOVABLE = 2, PEDESTRIAN = 3, BICYCLE = 4, VEHICLE = 5, MAX_OBJECT_TYPE = 6 };
double dist[MAX_OBJECT_TYPE][MAX_OBJECT_TYPE] = { {0.2, 0.3, 0.4, 0.5, 0.6, 1},
{0.3, 0.2, 0.3, 0.4, 0.5, 0.6},
{0.4, 0.3, 0.2, 0.3, 0.4, 0.5},
{0.5, 0.4, 0.3, 0.2, 0.3, 0.4},
{0.6, 0.5, 0.3, 0.4, 0.2, 0.3},
{1 , 0.6, 0.5, 0.4, 0.3, 0.2} };
map<string, int> objectTypeMap = {{"UNKNOWN", UNKNOWN},
{"UNKNOWN_MOVABLE", UNKNOWN_MOVABLE},
{"UNKNOWN_UNMOVABLE", UNKNOWN_UNMOVABLE},
{"PEDESTRIAN", PEDESTRIAN},
{"BICYCLE", BICYCLE},
{"VEHICLE", VEHICLE}};
int main() {
string xStr, yStr;
cout << "Enter object type names (e.g. 'PEDESTRIAN BICYCLE'): ";
cin >> xStr >> yStr;
if (objectTypeMap.find(xStr) == objectTypeMap.end() || objectTypeMap.find(yStr) == objectTypeMap.end()) {
cout << "Invalid object type!" << endl;
return 0;
}
int x = objectTypeMap[xStr];
int y = objectTypeMap[yStr];
cout << "dist[" << xStr << "][" << yStr << "] = " << dist[x][y] << endl;
return 0;
}
```
这段代码首先定义了一个 `objectTypeMap` 映射,用于将物体类型的字符串表示映射为枚举类型的数值。然后通过 `cin` 读取用户输入的物体类型字符串,并使用 `objectTypeMap` 将其映射为枚举类型的数值。最后输出对应的距离值。
阅读全文