|
@@ -4,7 +4,11 @@
|
|
|
|
|
|
#include "detect_manager.h"
|
|
|
|
|
|
-Error_manager DetectManager::Init() {
|
|
|
+Error_manager DetectManager::Init(const google::protobuf::RepeatedPtrField<tof3dVzenseEtc> &tof_devices) {
|
|
|
+ for (int device_index = 0; device_index < DeviceAzimuth::DEVICE_AZIMUTH_MAX; device_index++) {
|
|
|
+ updateTrans((DeviceAzimuth)device_index, tof_devices[device_index].trans());
|
|
|
+ }
|
|
|
+
|
|
|
m_thread = new std::thread(&DetectManager::run, this);
|
|
|
m_condit.notify_all(true);
|
|
|
|
|
@@ -16,6 +20,24 @@ Error_manager DetectManager::Release() {
|
|
|
return {};
|
|
|
}
|
|
|
|
|
|
+Error_manager DetectManager::updateTrans(const DeviceAzimuth &azimuth, const CoordinateTransformation3D &trans) {
|
|
|
+ Eigen::Matrix4f rotaition = Eigen::Matrix4f::Identity();
|
|
|
+ Eigen::Matrix3f rotation_matrix3 = Eigen::Matrix3f::Identity();
|
|
|
+ rotation_matrix3 =
|
|
|
+ Eigen::AngleAxisf(trans.yaw() * M_PI / 180.f, Eigen::Vector3f::UnitZ()) *
|
|
|
+ Eigen::AngleAxisf(trans.pitch() * M_PI / 180.f, Eigen::Vector3f::UnitY()) *
|
|
|
+ Eigen::AngleAxisf(trans.roll() * M_PI / 180.f, Eigen::Vector3f::UnitX());
|
|
|
+ Eigen::Vector3f move;
|
|
|
+ move << trans.x(), trans.y(), trans.z();
|
|
|
+ rotaition.block<3, 3>(0, 0) = rotation_matrix3;
|
|
|
+ rotaition.col(3) << move;
|
|
|
+ LOG(INFO) << "device " << azimuth << " update rotation info: \n" << rotaition;
|
|
|
+ rotation_matrix4[azimuth] = rotaition;
|
|
|
+ return {};
|
|
|
+}
|
|
|
+
|
|
|
+#include "tool/time.hpp"
|
|
|
+
|
|
|
void DetectManager::run() {
|
|
|
LOG(INFO) << "detect thread running in " << std::this_thread::get_id();
|
|
|
|
|
@@ -27,45 +49,89 @@ void DetectManager::run() {
|
|
|
|
|
|
auto t_start_time = std::chrono::steady_clock::now();
|
|
|
std::chrono::duration<double> cost = std::chrono::steady_clock::now() - t_start_time;
|
|
|
+ RecordImages record_images;
|
|
|
|
|
|
while (m_condit.is_alive()) {
|
|
|
m_condit.wait();
|
|
|
// 参数初始化
|
|
|
cost = std::chrono::steady_clock::now() - t_start_time;
|
|
|
- std::this_thread::sleep_for(std::chrono::milliseconds(100 - std::min<int>(99, cost.count() * 1000)));
|
|
|
+ std::this_thread::sleep_for(std::chrono::milliseconds(50 - std::min<int>(49, cost.count() * 1000)));
|
|
|
t_start_time = std::chrono::steady_clock::now();
|
|
|
|
|
|
if (m_condit.is_alive()) {
|
|
|
std::vector<int> have_cloud;
|
|
|
DetectResult detect_result;
|
|
|
JetStream::LabelYolo seg_results;
|
|
|
+ for (int i = 0; i < DeviceAzimuth::DEVICE_AZIMUTH_MAX; i++) {
|
|
|
+ vct_wheel_cloud[i]->clear();
|
|
|
+ }
|
|
|
if (!LabelYoloDataBuffer::iter()->lock_exe(&LabelYoloDataBuffer::get, seg_results, 10)) {
|
|
|
continue;
|
|
|
}
|
|
|
- LOG(INFO) << seg_results.label() << " " << seg_results.boxes(0).lines_size();
|
|
|
+ int lable = TimeTool::timeDropoutLL(TimeTool::TemporalPrecision::TemporalPrecisionMs, TimeTool::TemporalPrecision::TemporalPrecisionHour);
|
|
|
+ LOG(INFO) << "after " << (lable - seg_results.label()) << "ms";
|
|
|
+ // 判断识别结果数量以及是否存图
|
|
|
+ int seg_num = 0;
|
|
|
+ for (int device_index = 0; device_index < DeviceAzimuth::DEVICE_AZIMUTH_MAX; device_index++) {
|
|
|
+ if (seg_results.boxes(device_index).confidence() > 0.7) {
|
|
|
+ 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();
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ // 取高置信度识别结果
|
|
|
for (int device_index = 0; device_index < DeviceAzimuth::DEVICE_AZIMUTH_MAX; device_index++) {
|
|
|
- if (seg_results.boxes(device_index).lines().empty()) {
|
|
|
- LOG(INFO) << device_index << " empty";
|
|
|
+ if (seg_results.boxes(device_index).confidence() < 0.9) {
|
|
|
+ DLOG(INFO) << device_index << " empty";
|
|
|
continue;
|
|
|
}
|
|
|
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);
|
|
|
- }
|
|
|
- LOG(INFO) << "e get data" << " empty";
|
|
|
- continue;
|
|
|
- have_cloud.push_back(device_index);
|
|
|
- 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++) {
|
|
|
- vct_wheel_cloud[device_index]->emplace_back(pointMat.at<cv::Vec3f>(row, col)[0],
|
|
|
- pointMat.at<cv::Vec3f>(row, col)[1],
|
|
|
- pointMat.at<cv::Vec3f>(row, col)[2]);
|
|
|
+ have_cloud.push_back(device_index);
|
|
|
+ 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++) {
|
|
|
+ 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)[2] * 0.001);
|
|
|
+ }
|
|
|
}
|
|
|
+ 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]);
|
|
|
}
|
|
|
}
|
|
|
- continue;
|
|
|
|
|
|
// 点云处理
|
|
|
if (!have_cloud.empty()) {
|
|
@@ -84,12 +150,6 @@ void DetectManager::run() {
|
|
|
detect_result.car.wheel_base = 2.7;
|
|
|
}
|
|
|
|
|
|
- // TODO:测试功能
|
|
|
- wheel_detect->detect_fall(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 < 2.0 ||
|
|
|
have_cloud.size() > 2) {
|
|
@@ -193,3 +253,18 @@ Error_manager DetectManager::carMoveStatus() {
|
|
|
}
|
|
|
return {};
|
|
|
}
|
|
|
+
|
|
|
+Error_manager DetectManager::Stop() {
|
|
|
+ m_condit.kill_all();
|
|
|
+ m_thread->join();
|
|
|
+ delete m_thread;
|
|
|
+ m_thread = nullptr;
|
|
|
+ return {};
|
|
|
+}
|
|
|
+
|
|
|
+Error_manager DetectManager::Continue() {
|
|
|
+ m_condit.reset();
|
|
|
+ m_thread = new std::thread(&DetectManager::run, this);
|
|
|
+ m_condit.notify_all(true);
|
|
|
+ return {};
|
|
|
+}
|