1、实现demo效果
源码参考:GitHub - TixiaoShan/autoware_tracker:运行 Autoware 多对象跟踪所需的最少代码
该文已将autoware检测跟踪模块剥离出来,感谢作者的贡献!
1.1 编译
按照作者步骤进行,过程中遇到如下问题依依解决。
问题1
在opencv2中确实没有找到contrib库,在Google中搜索得到解释, opencv3中已经没有了contrib这个模块,特别指出不是编译opencv_contrib的问题,而是opencv_contrib中也没有contrib模块,所以再怎么重装opencv3+opencv_contrib也是无效的,但是解决这个问题比较简单,只需要修改对应位置代码即可。
#if (CV_MAJOR_VERSION >= 3)
#include "gencolors.cpp"
#else
#include <opencv2/contrib/contrib.hpp>
#include <autoware_tracker/DetectedObjectArray.h>
#endif
问题2
只需要修改对应位置代码即可
reduce(activedDists, minDists, 0, cv::REDUCE_MIN);
由于demo太大了懒得下了。。。直接开始修改吧
2、修改源码
我们只需要用到跟踪模块,所以必须要搞清楚跟踪模块的接口格式是什么,有两个思路,从检测发出的话题中寻找或者从跟踪订阅处寻找,经过比较,从检测发出的部分找起来比较容易,在lidar_euclidean_cluster_detect.cpp文件中有个函数专门负责发送检测目标
void publishDetectedObjects(const autoware_tracker::CloudClusterArray &in_clusters)
{
autoware_tracker::DetectedObjectArray detected_objects;
detected_objects.header = in_clusters.header;
for (size_t i = 0; i < in_clusters.clusters.size(); i++)
{
autoware_tracker::DetectedObject detected_object;
detected_object.header = in_clusters.header;
detected_object.label = "unknown";
detected_object.score = 1.;
detected_object.space_frame = in_clusters.header.frame_id;
detected_object.pose = in_clusters.clusters[i].bounding_box.pose;
detected_object.dimensions = in_clusters.clusters[i].dimensions;
detected_object.pointcloud = in_clusters.clusters[i].cloud;
detected_object.convex_hull = in_clusters.clusters[i].convex_hull;
detected_object.valid = true;
detected_objects.objects.push_back(detected_object);
}
_pub_detected_objects.publish(detected_objects);
}
比较msg/DetectedObject.msg
std_msgs/Header header
uint32 id
string label
float32 score #Score as defined by the detection, Optional
std_msgs/ColorRGBA color # Define this object specific color
bool valid # Defines if this object is valid, or invalid as defined by the filtering
################ 3D BB
string space_frame #3D Space coordinate frame of the object, required if pose and dimensions are defines
geometry_msgs/Pose pose
geometry_msgs/Vector3 dimensions
geometry_msgs/Vector3 variance
geometry_msgs/Twist velocity
geometry_msgs/Twist acceleration
sensor_msgs/PointCloud2 pointcloud
geometry_msgs/PolygonStamped convex_hull
# autoware_msgs/LaneArray candidate_trajectories
bool pose_reliable
bool velocity_reliable
bool acceleration_reliable
############### 2D Rect
string image_frame # Image coordinate Frame, Required if x,y,w,h defined
int32 x # X coord in image space(pixel) of the initial point of the Rect
int32 y # Y coord in image space(pixel) of the initial point of the Rect
int32 width # Width of the Rect in pixels
int32 height # Height of the Rect in pixels
float32 angle # Angle [0 to 2*PI), allow rotated rects
sensor_msgs/Image roi_image
############### Indicator information
uint8 indicator_state # INDICATOR_LEFT = 0, INDICATOR_RIGHT = 1, INDICATOR_BOTH = 2, INDICATOR_NONE = 3
############### Behavior State of the Detected Object
uint8 behavior_state # FORWARD_STATE = 0, STOPPING_STATE = 1, BRANCH_LEFT_STATE = 2, BRANCH_RIGHT_STATE = 3, YIELDING_STATE = 4, ACCELERATING_STATE = 5, SLOWDOWN_STATE = 6
#
string[] user_defined_info
可以知道,其实msg/DetectedObject.msg不是每一项都被赋值,有效值列在下面
std_msgs/Header header
string label
bool valid################ 3D BB
string space_frame
geometry_msgs/Pose pose
geometry_msgs/Vector3 dimensionssensor_msgs/PointCloud2 pointcloud
geometry_msgs/PolygonStamped convex_hull
然后可以在跟踪模块中的回调函数中发现
transformPoseToGlobal(input, transformed_input);
tracker(transformed_input, detected_objects_output);
transformPoseToLocal(detected_objects_output);
输入进来的点云信息是逐级处理的,因此只需要修改第一个函数中input相关值即可,我们再具体看看第一个函数是怎么定义的
这个函数简而言之就是把input的每个object赋给了transformed_input,并且进行了坐标转换,这里要注意一点,因为我的工程是基于路侧系统而不是雷达本身,所以这里后面会涉及到坐标转换的问题,等最后再修改
现在我们根据检测发出来的话题,对我们的检测话题进行修改
因为每个人的项目不同,这里不一一列举修改处,没啥意义。
在启动launch前要记得关掉原来的聚类,否则会冲突,最后启动launch
roslaunch autoware_tracker run.launch
效果如下
暂时还看不出效果好不好,有待后续测试