|
@@ -6,7 +6,8 @@
|
|
|
|
|
|
Error_manager DetectManager::Init(const google::protobuf::RepeatedPtrField<tof3dVzenseEtc> &tof_devices) {
|
|
Error_manager DetectManager::Init(const google::protobuf::RepeatedPtrField<tof3dVzenseEtc> &tof_devices) {
|
|
for (int device_index = 0; device_index < DeviceAzimuth::DEVICE_AZIMUTH_MAX; device_index++) {
|
|
for (int device_index = 0; device_index < DeviceAzimuth::DEVICE_AZIMUTH_MAX; device_index++) {
|
|
- updateTrans((DeviceAzimuth)device_index, tof_devices[device_index].trans());
|
|
|
|
|
|
+ TofTransformationManager::iter()->set((DeviceAzimuth)device_index, tof_devices[device_index].trans());
|
|
|
|
+ updateTrans((DeviceAzimuth) device_index, tof_devices[device_index].trans());
|
|
}
|
|
}
|
|
|
|
|
|
m_thread = new std::thread(&DetectManager::run, this);
|
|
m_thread = new std::thread(&DetectManager::run, this);
|
|
@@ -31,13 +32,63 @@ Error_manager DetectManager::updateTrans(const DeviceAzimuth &azimuth, const Coo
|
|
move << trans.x(), trans.y(), trans.z();
|
|
move << trans.x(), trans.y(), trans.z();
|
|
rotaition.block<3, 3>(0, 0) = rotation_matrix3;
|
|
rotaition.block<3, 3>(0, 0) = rotation_matrix3;
|
|
rotaition.col(3) << move;
|
|
rotaition.col(3) << move;
|
|
- LOG(INFO) << "device " << azimuth << " update rotation info: \n" << rotaition;
|
|
|
|
rotation_matrix4[azimuth] = rotaition;
|
|
rotation_matrix4[azimuth] = rotaition;
|
|
return {};
|
|
return {};
|
|
}
|
|
}
|
|
|
|
|
|
#include "tool/time.hpp"
|
|
#include "tool/time.hpp"
|
|
|
|
|
|
|
|
+bool boxIsValid(const JetStream::SegBox& box, int min ,bool reverse=false){
|
|
|
|
+ if(box.confidence()<0.8){
|
|
|
|
+ return false;
|
|
|
|
+ }
|
|
|
|
+ int left_side = box.x();
|
|
|
|
+ if(reverse){
|
|
|
|
+ left_side=640-(box.x()+box.width());
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ return left_side > min;
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+int IsInImageValidRegion(const JetStream::LabelYolo &labels) {
|
|
|
|
+ if(labels.boxes_size()!=4){
|
|
|
|
+ return -1; //没有识别框
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ for (int device_index = 0; device_index < 4; device_index++) {
|
|
|
|
+ // LOG(INFO) << device_index << ": "<< labels.boxes(device_index).confidence() << " " << labels.boxes(device_index).x();
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ JetStream::SegBox box2=labels.boxes(1);
|
|
|
|
+ JetStream::SegBox box4=labels.boxes(3);
|
|
|
|
+ bool frontExsit = labels.boxes(0).confidence() > 0.8 || labels.boxes(1).confidence() > 0.8;
|
|
|
|
+ bool backExist = labels.boxes(2).confidence() > 0.8 || labels.boxes(3).confidence() > 0.8;
|
|
|
|
+ if(!frontExsit){
|
|
|
|
+ if(backExist){ //后有前没有
|
|
|
|
+ return 1; //往前
|
|
|
|
+ }else{ //前后都没有
|
|
|
|
+ return -1;
|
|
|
|
+ }
|
|
|
|
+ }else{
|
|
|
|
+ if(backExist){
|
|
|
|
+ bool front_OK = boxIsValid(labels.boxes(1), 20) || boxIsValid(labels.boxes(0), 20,true);
|
|
|
|
+ bool back_OK = boxIsValid(labels.boxes(2), 20,true) || boxIsValid(labels.boxes(3), 20);
|
|
|
|
+ if(front_OK && back_OK){
|
|
|
|
+ return 0;
|
|
|
|
+ }else{
|
|
|
|
+ return 1;
|
|
|
|
+ }
|
|
|
|
+ }else{ // 前有后没有
|
|
|
|
+ bool front_OK=boxIsValid(labels.boxes(1),320) || boxIsValid(labels.boxes(0),320,true);
|
|
|
|
+ if(!front_OK){
|
|
|
|
+ return 1;
|
|
|
|
+ }else{
|
|
|
|
+ return -1;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+}
|
|
|
|
+
|
|
void DetectManager::run() {
|
|
void DetectManager::run() {
|
|
LOG(INFO) << "detect thread running in " << std::this_thread::get_id();
|
|
LOG(INFO) << "detect thread running in " << std::this_thread::get_id();
|
|
|
|
|
|
@@ -49,7 +100,6 @@ void DetectManager::run() {
|
|
|
|
|
|
auto t_start_time = std::chrono::steady_clock::now();
|
|
auto t_start_time = std::chrono::steady_clock::now();
|
|
std::chrono::duration<double> cost = std::chrono::steady_clock::now() - t_start_time;
|
|
std::chrono::duration<double> cost = std::chrono::steady_clock::now() - t_start_time;
|
|
- RecordImages record_images;
|
|
|
|
|
|
|
|
while (m_condit.is_alive()) {
|
|
while (m_condit.is_alive()) {
|
|
m_condit.wait();
|
|
m_condit.wait();
|
|
@@ -68,46 +118,18 @@ void DetectManager::run() {
|
|
if (!LabelYoloDataBuffer::iter()->lock_exe(&LabelYoloDataBuffer::get, seg_results, 10)) {
|
|
if (!LabelYoloDataBuffer::iter()->lock_exe(&LabelYoloDataBuffer::get, seg_results, 10)) {
|
|
continue;
|
|
continue;
|
|
}
|
|
}
|
|
- int lable = TimeTool::timeDropoutLL(TimeTool::TemporalPrecision::TemporalPrecisionMs, TimeTool::TemporalPrecision::TemporalPrecisionHour);
|
|
|
|
- LOG(INFO) << "after " << (lable - seg_results.label()) << "ms";
|
|
|
|
// 判断识别结果数量以及是否存图
|
|
// 判断识别结果数量以及是否存图
|
|
int seg_num = 0;
|
|
int seg_num = 0;
|
|
for (int device_index = 0; device_index < DeviceAzimuth::DEVICE_AZIMUTH_MAX; device_index++) {
|
|
for (int device_index = 0; device_index < DeviceAzimuth::DEVICE_AZIMUTH_MAX; device_index++) {
|
|
|
|
+ // LOG(INFO) << device_index << ": " << seg_results.boxes(device_index).confidence();
|
|
if (seg_results.boxes(device_index).confidence() > 0.7) {
|
|
if (seg_results.boxes(device_index).confidence() > 0.7) {
|
|
seg_num++;
|
|
seg_num++;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
- if (seg_num == 1 && record_images.name_1.empty()) {
|
|
|
|
- if (MatDataBuffer::iter()->lock_exe(&MatDataBuffer::getIr, seg_results.label(), record_images.img_1, 10)) {
|
|
|
|
- record_images.name_1 = TimeTool::timeDropoutStr();
|
|
|
|
- } else {
|
|
|
|
- record_images.name_1.clear();
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- }
|
|
|
|
- if (seg_num == 2 && record_images.name_2.empty()) {
|
|
|
|
- if (MatDataBuffer::iter()->lock_exe(&MatDataBuffer::getIr, seg_results.label(), record_images.img_2, 10)) {
|
|
|
|
- record_images.name_2 = TimeTool::timeDropoutStr();
|
|
|
|
- } else {
|
|
|
|
- record_images.name_2.clear();
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- }
|
|
|
|
- if (seg_num == 3 && record_images.name_3.empty()) {
|
|
|
|
- if (MatDataBuffer::iter()->lock_exe(&MatDataBuffer::getIr, seg_results.label(), record_images.img_3, 10)) {
|
|
|
|
- record_images.name_3 = TimeTool::timeDropoutStr();
|
|
|
|
- } else {
|
|
|
|
- record_images.name_3.clear();
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- }
|
|
|
|
- if (seg_num == 4 && record_images.name_4.empty()) {
|
|
|
|
- if (MatDataBuffer::iter()->lock_exe(&MatDataBuffer::getIr, seg_results.label(), record_images.img_4, 10)) {
|
|
|
|
- record_images.name_4 = TimeTool::timeDropoutStr();
|
|
|
|
- } else {
|
|
|
|
- record_images.name_4.clear();
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
|
|
+ if (seg_num == 0) {
|
|
|
|
+ detect_statu = MeasureStatu::Measure_Empty_Clouds;
|
|
|
|
+ m_detect_result_record.reset();
|
|
|
|
+ continue;
|
|
}
|
|
}
|
|
// 取高置信度识别结果
|
|
// 取高置信度识别结果
|
|
for (int device_index = 0; device_index < DeviceAzimuth::DEVICE_AZIMUTH_MAX; device_index++) {
|
|
for (int device_index = 0; device_index < DeviceAzimuth::DEVICE_AZIMUTH_MAX; device_index++) {
|
|
@@ -117,21 +139,39 @@ void DetectManager::run() {
|
|
}
|
|
}
|
|
cv::Mat pointMat;
|
|
cv::Mat pointMat;
|
|
//LOG(INFO) << "b get data" << " empty";
|
|
//LOG(INFO) << "b get data" << " empty";
|
|
- if (MatDataBuffer::iter()->lock_exe(&MatDataBuffer::get, device_index, seg_results.label(), pointMat, 10)) {
|
|
|
|
- cv::imshow(std::to_string(device_index), pointMat);
|
|
|
|
- cv::waitKey(1);
|
|
|
|
|
|
+ if (MatDataBuffer::iter()->lock_exe(&MatDataBuffer::get, device_index, seg_results.label(), pointMat,
|
|
|
|
+ 10)) {
|
|
have_cloud.push_back(device_index);
|
|
have_cloud.push_back(device_index);
|
|
|
|
+ std::vector<cv::Point> seg_points;
|
|
for (int row = 0; row < 480; row++) {
|
|
for (int row = 0; row < 480; row++) {
|
|
- for (int col = seg_results.boxes(device_index).lines(row).begin(); col < seg_results.boxes(device_index).lines(row).end(); col++) {
|
|
|
|
|
|
+ for (int col = seg_results.boxes(device_index).lines(row).begin();
|
|
|
|
+ col < seg_results.boxes(device_index).lines(row).end(); col++) {
|
|
|
|
+ seg_points.emplace_back(col, row);
|
|
vct_wheel_cloud[device_index]->emplace_back(pointMat.at<cv::Vec3f>(row, col)[0] * 0.001,
|
|
vct_wheel_cloud[device_index]->emplace_back(pointMat.at<cv::Vec3f>(row, col)[0] * 0.001,
|
|
pointMat.at<cv::Vec3f>(row, col)[1] * 0.001,
|
|
pointMat.at<cv::Vec3f>(row, col)[1] * 0.001,
|
|
pointMat.at<cv::Vec3f>(row, col)[2] * 0.001);
|
|
pointMat.at<cv::Vec3f>(row, col)[2] * 0.001);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
- pcl::transformPointCloud(*vct_wheel_cloud[device_index], *vct_wheel_cloud[device_index], rotation_matrix4[device_index]());
|
|
|
|
|
|
+ TransitData::get_instance_pointer()->setMask(seg_points, device_index);
|
|
|
|
+ CoordinateTransformation3D device_trans;
|
|
|
|
+ // 更新旋转坐标
|
|
|
|
+ if (TofTransformationManager::iter()->get((DeviceAzimuth)device_index, device_trans)) {
|
|
|
|
+ updateTrans((DeviceAzimuth)device_index, device_trans);
|
|
|
|
+ }
|
|
|
|
+ pcl::transformPointCloud(*vct_wheel_cloud[device_index], *vct_wheel_cloud[device_index],
|
|
|
|
+ rotation_matrix4[device_index]());
|
|
// Point3D_tool::WriteTxtCloud(ETC_PATH PROJECT_NAME "/data/cloud_" + std::to_string(device_index) + ".txt", vct_wheel_cloud[device_index]);
|
|
// Point3D_tool::WriteTxtCloud(ETC_PATH PROJECT_NAME "/data/cloud_" + std::to_string(device_index) + ".txt", vct_wheel_cloud[device_index]);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
+ int flag = IsInImageValidRegion(seg_results);
|
|
|
|
+ if (flag == 1) {
|
|
|
|
+ LOG(INFO) << "向前";
|
|
|
|
+ detect_statu = MeasureStatu::Measure_Border;
|
|
|
|
+ continue;
|
|
|
|
+ } else if (flag == -1){
|
|
|
|
+ LOG(WARNING) << "缺少轮子";
|
|
|
|
+ continue;
|
|
|
|
+ }
|
|
|
|
|
|
// 点云处理
|
|
// 点云处理
|
|
if (!have_cloud.empty()) {
|
|
if (!have_cloud.empty()) {
|
|
@@ -152,13 +192,19 @@ void DetectManager::run() {
|
|
|
|
|
|
// 根据车轮数采用不同的优化方式
|
|
// 根据车轮数采用不同的优化方式
|
|
if (m_detect_result_record.car.wheel_width < 1.0 || m_detect_result_record.car.wheel_base < 2.0 ||
|
|
if (m_detect_result_record.car.wheel_width < 1.0 || m_detect_result_record.car.wheel_base < 2.0 ||
|
|
- have_cloud.size() > 2) {
|
|
|
|
- ceres_detect_ret = wheel_detect->detect_2Step(vct_wheel_cloud[DeviceAzimuth::DEVICE_AZIMUTH_LF], vct_wheel_cloud[DeviceAzimuth::DEVICE_AZIMUTH_RF],
|
|
|
|
- vct_wheel_cloud[DeviceAzimuth::DEVICE_AZIMUTH_LR], vct_wheel_cloud[DeviceAzimuth::DEVICE_AZIMUTH_RR],
|
|
|
|
- detect_result.car.wheels_center_x, detect_result.car.wheels_center_y,
|
|
|
|
- detect_result.car.theta, detect_result.car.wheel_base,
|
|
|
|
- detect_result.car.wheel_width,detect_result.car.front_wheels_theta, detect_result.car.loss);
|
|
|
|
- if ((m_detect_result_record.car.wheel_width < 1.0 && m_detect_result_record.car.wheel_base < 1.0 && have_cloud.size() == 2) || have_cloud.size() < 2) {
|
|
|
|
|
|
+ have_cloud.size() > 2) {
|
|
|
|
+ ceres_detect_ret = wheel_detect->detect_2Step(vct_wheel_cloud[DeviceAzimuth::DEVICE_AZIMUTH_LF],
|
|
|
|
+ vct_wheel_cloud[DeviceAzimuth::DEVICE_AZIMUTH_RF],
|
|
|
|
+ vct_wheel_cloud[DeviceAzimuth::DEVICE_AZIMUTH_LR],
|
|
|
|
+ vct_wheel_cloud[DeviceAzimuth::DEVICE_AZIMUTH_RR],
|
|
|
|
+ detect_result.car.wheels_center_x,
|
|
|
|
+ detect_result.car.wheels_center_y,
|
|
|
|
+ detect_result.car.theta, detect_result.car.wheel_base,
|
|
|
|
+ detect_result.car.wheel_width,
|
|
|
|
+ detect_result.car.front_wheels_theta,
|
|
|
|
+ detect_result.car.loss);
|
|
|
|
+ if ((m_detect_result_record.car.wheel_width < 1.0 && m_detect_result_record.car.wheel_base < 1.0 &&
|
|
|
|
+ have_cloud.size() == 2) || have_cloud.size() < 2) {
|
|
detect_result.car.wheel_width = m_detect_result_record.car.wheel_width;
|
|
detect_result.car.wheel_width = m_detect_result_record.car.wheel_width;
|
|
detect_result.car.wheel_base = m_detect_result_record.car.wheel_base;
|
|
detect_result.car.wheel_base = m_detect_result_record.car.wheel_base;
|
|
} else if (have_cloud.size() == 2) {
|
|
} else if (have_cloud.size() == 2) {
|
|
@@ -168,18 +214,24 @@ void DetectManager::run() {
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
- if (have_cloud[0] % 2 == have_cloud[1] %2 ) {
|
|
|
|
|
|
+ if (have_cloud[0] % 2 == have_cloud[1] % 2) {
|
|
detect_result.car.wheel_width = m_detect_result_record.car.wheel_width;
|
|
detect_result.car.wheel_width = m_detect_result_record.car.wheel_width;
|
|
} else {
|
|
} else {
|
|
detect_result.car.wheel_base = m_detect_result_record.car.wheel_base;
|
|
detect_result.car.wheel_base = m_detect_result_record.car.wheel_base;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
} else {
|
|
} else {
|
|
- ceres_detect_ret = wheel_detect->detect_dynP(vct_wheel_cloud[DeviceAzimuth::DEVICE_AZIMUTH_LF], vct_wheel_cloud[DeviceAzimuth::DEVICE_AZIMUTH_RF],
|
|
|
|
- vct_wheel_cloud[DeviceAzimuth::DEVICE_AZIMUTH_LR], vct_wheel_cloud[DeviceAzimuth::DEVICE_AZIMUTH_RR],
|
|
|
|
- detect_result.car.wheels_center_x, detect_result.car.wheels_center_y,
|
|
|
|
- detect_result.car.theta, m_detect_result_record.car.wheel_base,
|
|
|
|
- m_detect_result_record.car.wheel_width,detect_result.car.front_wheels_theta, detect_result.car.loss);
|
|
|
|
|
|
+ ceres_detect_ret = wheel_detect->detect_dynP(vct_wheel_cloud[DeviceAzimuth::DEVICE_AZIMUTH_LF],
|
|
|
|
+ vct_wheel_cloud[DeviceAzimuth::DEVICE_AZIMUTH_RF],
|
|
|
|
+ vct_wheel_cloud[DeviceAzimuth::DEVICE_AZIMUTH_LR],
|
|
|
|
+ vct_wheel_cloud[DeviceAzimuth::DEVICE_AZIMUTH_RR],
|
|
|
|
+ detect_result.car.wheels_center_x,
|
|
|
|
+ detect_result.car.wheels_center_y,
|
|
|
|
+ detect_result.car.theta,
|
|
|
|
+ m_detect_result_record.car.wheel_base,
|
|
|
|
+ m_detect_result_record.car.wheel_width,
|
|
|
|
+ detect_result.car.front_wheels_theta,
|
|
|
|
+ detect_result.car.loss);
|
|
detect_result.car.wheel_base = m_detect_result_record.car.wheel_base;
|
|
detect_result.car.wheel_base = m_detect_result_record.car.wheel_base;
|
|
detect_result.car.wheel_width = m_detect_result_record.car.wheel_width;
|
|
detect_result.car.wheel_width = m_detect_result_record.car.wheel_width;
|
|
}
|
|
}
|
|
@@ -221,13 +273,14 @@ void DetectManager::stop() {
|
|
m_thread = nullptr;
|
|
m_thread = nullptr;
|
|
}
|
|
}
|
|
|
|
|
|
-Error_manager DetectManager::WheelCloudOptimize(std::vector<pcl::PointCloud<pcl::PointXYZ>::Ptr> &vct_wheel_cloud, DetectResult &result) {
|
|
|
|
|
|
+Error_manager DetectManager::WheelCloudOptimize(std::vector<pcl::PointCloud<pcl::PointXYZ>::Ptr> &vct_wheel_cloud,
|
|
|
|
+ DetectResult &result) {
|
|
//下采样
|
|
//下采样
|
|
pcl::VoxelGrid<pcl::PointXYZ> vox; //创建滤波对象
|
|
pcl::VoxelGrid<pcl::PointXYZ> vox; //创建滤波对象
|
|
vox.setLeafSize(0.03f, 0.03f, 0.03f); //设置滤波时创建的体素体积为1cm的立方体
|
|
vox.setLeafSize(0.03f, 0.03f, 0.03f); //设置滤波时创建的体素体积为1cm的立方体
|
|
pcl::PointCloud<pcl::PointXYZ>::Ptr filtered_cloud(new pcl::PointCloud<pcl::PointXYZ>);
|
|
pcl::PointCloud<pcl::PointXYZ>::Ptr filtered_cloud(new pcl::PointCloud<pcl::PointXYZ>);
|
|
for (int device_index = 0; device_index < DeviceAzimuth::DEVICE_AZIMUTH_MAX; device_index++) {
|
|
for (int device_index = 0; device_index < DeviceAzimuth::DEVICE_AZIMUTH_MAX; device_index++) {
|
|
- if (vct_wheel_cloud[device_index]->empty()) { continue;}
|
|
|
|
|
|
+ if (vct_wheel_cloud[device_index]->empty()) { continue; }
|
|
|
|
|
|
vox.setInputCloud(vct_wheel_cloud[device_index]); //设置需要过滤的点云给滤波对象
|
|
vox.setInputCloud(vct_wheel_cloud[device_index]); //设置需要过滤的点云给滤波对象
|
|
vox.filter(*vct_wheel_cloud[device_index]); //执行滤波处理,存储输出
|
|
vox.filter(*vct_wheel_cloud[device_index]); //执行滤波处理,存储输出
|