|
@@ -18,6 +18,8 @@ Error_manager DeviceTof3D::Init(const VzEtcMap &tp_tof3d, bool search) {
|
|
|
SearchDevice(5);
|
|
|
}
|
|
|
|
|
|
+ // 启动grpc服务
|
|
|
+ m_grpc_server.Listenning("192.168.2.55", 9876);
|
|
|
cv::namedWindow("ret", cv::WINDOW_AUTOSIZE);
|
|
|
|
|
|
ConnectAllEtcDevices();
|
|
@@ -443,72 +445,46 @@ Error_manager DeviceTof3D::IrFrame2Mat(VzFrame &frame, cv::Mat &mat) {
|
|
|
return {};
|
|
|
}
|
|
|
|
|
|
-#include <sys/stat.h>
|
|
|
+#include "file/pathcreator.h"
|
|
|
|
|
|
void DeviceTof3D::receiveFrameThread(const std::string &ip) {
|
|
|
LOG(INFO) << ip << " in thread " << std::this_thread::get_id();
|
|
|
auto iter = mp_device_info.find(ip);
|
|
|
auto t_iter = mp_thread_info.find(ip);
|
|
|
|
|
|
- pcl::PointCloud<pcl::PointXYZ>::Ptr t_car_cloud(new pcl::PointCloud<pcl::PointXYZ>);
|
|
|
- pcl::PointCloud<pcl::PointXYZ>::Ptr t_wheel_cloud(new pcl::PointCloud<pcl::PointXYZ>);
|
|
|
- std::vector<Object> segment_results;
|
|
|
-
|
|
|
- const std::string path = ETC_PATH PROJECT_NAME "/image/";
|
|
|
- std::vector<std::string> imagePathList;
|
|
|
- int image_index = 0;
|
|
|
- if (IsFile(path)) {
|
|
|
- std::string suffix = path.substr(path.find_last_of('.') + 1);
|
|
|
- if (suffix == "jpg" || suffix == "jpeg" || suffix == "png") {
|
|
|
- imagePathList.push_back(path);
|
|
|
- } else {
|
|
|
- printf("suffix %s is wrong !!!\n", suffix.c_str());
|
|
|
- std::abort();
|
|
|
- }
|
|
|
- } else if (IsFolder(path)) {
|
|
|
- cv::glob(path + "/*.jpg", imagePathList);
|
|
|
- }
|
|
|
-
|
|
|
while (t_iter->second.condit->is_alive()) {
|
|
|
t_iter->second.condit->wait();
|
|
|
if (t_iter->second.condit->is_alive()) {
|
|
|
Error_manager ret;
|
|
|
if (iter->second->handle) {
|
|
|
- t_car_cloud->clear();
|
|
|
- t_wheel_cloud->clear();
|
|
|
+ DeviceMat depthInfo;
|
|
|
VzFrame depthFrame = {0};
|
|
|
- cv::Mat depthMat(480, 640, CV_16UC1);
|
|
|
- if (getDepthFrame(ip, depthFrame) == SUCCESS) {
|
|
|
- segment_results.clear();
|
|
|
- if (Frame2Mat(depthFrame, depthMat) == SUCCESS) {
|
|
|
- image_index = (image_index + 1) > (imagePathList.size() - 1) ? 0 : image_index + 1;
|
|
|
- depthMat = cv::imread(imagePathList[image_index]);
|
|
|
- detector->detect(depthMat, segment_results, depthMat);
|
|
|
- cv::imshow("ret", depthMat);
|
|
|
- cv::waitKey(1);
|
|
|
- }
|
|
|
|
|
|
- std::vector<cv::Point> mat_seg_ret;
|
|
|
- for (auto &result: segment_results) {
|
|
|
- LOG(INFO) << result.prob;
|
|
|
- if (result.prob > 0.5) {
|
|
|
- mat_seg_ret = detector->getPointsFromObj(result);
|
|
|
- for (auto &pt: mat_seg_ret) {
|
|
|
- depthMat.at<cv::Vec3b>(pt) = cv::Vec3b(255, 255, 255) - depthMat.at<cv::Vec3b>(pt);
|
|
|
- }
|
|
|
- cv::imshow("ret", depthMat);
|
|
|
- cv::waitKey(1);
|
|
|
+ // 图像获取
|
|
|
+ if (getDepthFrame(ip, depthFrame) == SUCCESS && Frame2Mat(depthFrame, depthInfo.depthMat) == SUCCESS) {
|
|
|
+ // 点云转换
|
|
|
+ VzSensorIntrinsicParameters cameraParam = {};
|
|
|
+ VZ_GetSensorIntrinsicParameters(iter->second->handle, VzToFSensor, &cameraParam);
|
|
|
+
|
|
|
+ const uint16_t *pDepthFrameData = (uint16_t *) depthFrame.pFrameData;
|
|
|
+ for (int cols = 0; cols < depthInfo.pointMat.cols; cols++) {
|
|
|
+ for (int rows = 0; rows < depthInfo.pointMat.rows; rows++) {
|
|
|
+ VzDepthVector3 depthPoint = {cols, rows, pDepthFrameData[rows * depthInfo.pointMat.cols + cols]};
|
|
|
+ VzVector3f worldV = {};
|
|
|
+ VZ_ConvertDepthToPointCloud(iter->second->handle, &depthPoint, &worldV, 1, &cameraParam);
|
|
|
+ depthInfo.pointMat.at<cv::Vec4f>(rows, cols)[0] = worldV.x * 0.001;
|
|
|
+ depthInfo.pointMat.at<cv::Vec4f>(rows, cols)[1] = worldV.y * 0.001;
|
|
|
+ depthInfo.pointMat.at<cv::Vec4f>(rows, cols)[2] = worldV.z * 0.001;
|
|
|
+// if (depthInfo.pointMat.at<cv::Vec4f>(rows, cols)[0] > 1) {
|
|
|
+// LOG(INFO) << depthInfo.pointMat.at<cv::Vec4f>(rows, cols)[0];
|
|
|
+// }
|
|
|
+ depthInfo.pointMat.at<cv::Vec4f>(rows, cols)[3] = 0;
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
- if (!mat_seg_ret.empty()) {
|
|
|
- segFrame2CarAndWheel(depthFrame, mat_seg_ret, t_car_cloud, t_wheel_cloud);
|
|
|
- // viewer.removeAllPointClouds(view_port[0]);
|
|
|
- // viewer.removeAllPointClouds(view_port[1]);
|
|
|
- // viewer.addPointCloud(t_car_cloud, "car_cloud_", view_port[0]);
|
|
|
- // viewer.addPointCloud(t_wheel_cloud, "wheel_cloud_", view_port[1]);
|
|
|
- // viewer.spinOnce();
|
|
|
- }
|
|
|
+// cv::imshow(iter->first, depthInfo.pointMat);
|
|
|
+// cv::waitKey(1);
|
|
|
+ // 将图片和点云存储起来
|
|
|
+ m_device_mat[iter->second->etc.azimuth()].reset(depthInfo, 1);
|
|
|
} else {
|
|
|
ret.compare_and_merge_up({FAILED, MINOR_ERROR, "Device %s VZ_GetFrame failed.", ip.c_str()});
|
|
|
}
|
|
@@ -532,20 +508,35 @@ void DeviceTof3D::receiveFrameThread(const std::string &ip) {
|
|
|
void DeviceTof3D::detectThread() {
|
|
|
LOG(INFO) << "detect thread running in " << std::this_thread::get_id();
|
|
|
|
|
|
- // int view_port[2];
|
|
|
- // pcl::visualization::PCLVisualizer viewer("viewer_0");
|
|
|
- // viewer.createViewPort(0.0, 0.0, 0.5, 1, view_port[0]);
|
|
|
- // viewer.createViewPort(0.5, 0.0, 1, 1, view_port[1]);
|
|
|
- // viewer.addText("car_cloud", 10, 10, 20, 0, 1, 0, "car_cloud", view_port[0]);
|
|
|
- // viewer.addText("wheel_cloud", 10, 10, 20, 0, 1, 0, "wheel_cloud", view_port[1]);
|
|
|
- // viewer.addCoordinateSystem(1, "car_axis", view_port[0]);
|
|
|
- // viewer.addCoordinateSystem(1, "wheel_axis", view_port[1]);
|
|
|
+ int view_port[2];
|
|
|
+ pcl::visualization::PCLVisualizer viewer("viewer_0");
|
|
|
+ viewer.createViewPort(0.0, 0.0, 0.5, 1, view_port[0]);
|
|
|
+ viewer.createViewPort(0.5, 0.0, 1, 1, view_port[1]);
|
|
|
+ viewer.addText("car_cloud", 10, 10, 20, 0, 1, 0, "car_cloud", view_port[0]);
|
|
|
+ viewer.addText("wheel_cloud", 10, 10, 20, 0, 1, 0, "wheel_cloud", view_port[1]);
|
|
|
+ viewer.addCoordinateSystem(1, "car_axis", view_port[0]);
|
|
|
+ viewer.addCoordinateSystem(1, "wheel_axis", view_port[1]);
|
|
|
|
|
|
pcl::PointCloud<pcl::PointXYZ>::Ptr t_car_cloud(new pcl::PointCloud<pcl::PointXYZ>);
|
|
|
pcl::PointCloud<pcl::PointXYZ>::Ptr t_wheel_cloud(new pcl::PointCloud<pcl::PointXYZ>);
|
|
|
auto t_start_time = std::chrono::steady_clock::now();
|
|
|
std::chrono::duration<double> cost = std::chrono::steady_clock::now() - t_start_time;
|
|
|
|
|
|
+ const std::string path = ETC_PATH PROJECT_NAME "/image/";
|
|
|
+ std::vector<std::string> imagePathList;
|
|
|
+ int image_index = 0;
|
|
|
+ if (PathCreator::IsFile(path)) {
|
|
|
+ std::string suffix = path.substr(path.find_last_of('.') + 1);
|
|
|
+ if (suffix == "jpg" || suffix == "jpeg" || suffix == "png") {
|
|
|
+ imagePathList.push_back(path);
|
|
|
+ } else {
|
|
|
+ printf("suffix %s is wrong !!!\n", suffix.c_str());
|
|
|
+ std::abort();
|
|
|
+ }
|
|
|
+ } else if (PathCreator::IsFolder(path)) {
|
|
|
+ cv::glob(path + "/*.jpg", imagePathList);
|
|
|
+ }
|
|
|
+
|
|
|
while (detect_thread.condit->is_alive()) {
|
|
|
// detect_thread.condit->wait();
|
|
|
t_car_cloud->clear();
|
|
@@ -556,15 +547,72 @@ void DeviceTof3D::detectThread() {
|
|
|
// LOG(INFO) << "last wheel cost time is " << cost.count() * 1000 << " ms";
|
|
|
|
|
|
if (detect_thread.condit->is_alive()) {
|
|
|
+ DetectResult result;
|
|
|
+ ::JetStream::ResFrame frame;
|
|
|
+ t_car_cloud->clear();
|
|
|
+ t_wheel_cloud->clear();
|
|
|
+ DeviceMat t_device_mat[DeviceAzimuth::MAX];
|
|
|
+ for (int device_index = 0; device_index < DeviceAzimuth::MAX; device_index++) {
|
|
|
+ if (!m_device_mat[device_index].timeout()) {
|
|
|
+ t_device_mat[device_index].empty = false;
|
|
|
+ t_device_mat[device_index] = m_device_mat[device_index].Get();
|
|
|
+ grpcVzenseMat(frame, (DeviceAzimuth)device_index, t_device_mat[device_index].depthMat);
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
+ for (int device_index = 0; device_index < DeviceAzimuth::MAX; device_index++) {
|
|
|
+ if (t_device_mat[device_index].empty) {continue;}
|
|
|
+
|
|
|
+ std::vector<Object> objs;
|
|
|
+// detector->detect(t_device_mat[device_index].depthMat, objs);
|
|
|
+ image_index = image_index > imagePathList.size() - 2 ? 0 : image_index + 1;
|
|
|
+ t_device_mat[device_index].depthMat = cv::imread(imagePathList[image_index]);
|
|
|
+ detector->detect(t_device_mat[device_index].depthMat, objs);
|
|
|
+ if (objs.size() == 1 && objs[0].prob > 0.5 ) {
|
|
|
+ LOG(INFO) << device_index << " objs[0].prob " << objs[0].prob;
|
|
|
+ auto seg_points = detector->getPointsFromObj(objs[0]);
|
|
|
+ for (auto &pt: seg_points) {
|
|
|
+ t_device_mat[device_index].pointMat.at<cv::Vec4f>(pt)[3] = objs[0].prob;
|
|
|
+ }
|
|
|
+ LOG(INFO) << device_index << " grpcVzensePointMat";
|
|
|
+ grpcVzensePointMat(frame, (DeviceAzimuth)device_index, t_device_mat[device_index].pointMat);
|
|
|
+ LOG(INFO) << device_index << " grpcVzensePointMat";
|
|
|
+
|
|
|
+ for (int rows = 0; rows < t_device_mat[device_index].pointMat.rows; rows++) {
|
|
|
+ for (int cols = 0; cols < t_device_mat[device_index].pointMat.cols; cols++) {
|
|
|
+ t_car_cloud->emplace_back(
|
|
|
+ t_device_mat[device_index].pointMat.at<cv::Vec4f>(rows, cols)[0],
|
|
|
+ t_device_mat[device_index].pointMat.at<cv::Vec4f>(rows, cols)[1],
|
|
|
+ t_device_mat[device_index].pointMat.at<cv::Vec4f>(rows, cols)[2]);
|
|
|
+ if (t_device_mat[device_index].pointMat.at<cv::Vec4f>(rows, cols)[3] > 0) {
|
|
|
+ t_wheel_cloud->emplace_back(
|
|
|
+ t_device_mat[device_index].pointMat.at<cv::Vec4f>(rows, cols)[0],
|
|
|
+ t_device_mat[device_index].pointMat.at<cv::Vec4f>(rows, cols)[1],
|
|
|
+ t_device_mat[device_index].pointMat.at<cv::Vec4f>(rows, cols)[2]);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
+ viewer.removeAllPointClouds(view_port[0]);
|
|
|
+ viewer.removeAllPointClouds(view_port[1]);
|
|
|
+ viewer.addPointCloud(t_car_cloud, "t_car_cloud", view_port[0]);
|
|
|
+ viewer.addPointCloud(t_wheel_cloud, "t_wheel_cloud", view_port[1]);
|
|
|
+ viewer.spinOnce();
|
|
|
// cost = std::chrono::steady_clock::now() - t_start_time;
|
|
|
// LOG(INFO) << "cost time is " << cost.count() * 1000 << " ms";
|
|
|
- if (!t_car_cloud->empty() && !t_wheel_cloud->empty()) {
|
|
|
- CarPoseOptimize(t_car_cloud);
|
|
|
- WheelCloudOptimize(t_wheel_cloud);
|
|
|
- }
|
|
|
+// if (!t_car_cloud->empty() && !t_wheel_cloud->empty()) {
|
|
|
+// CarPoseOptimize(t_car_cloud);
|
|
|
+// WheelCloudOptimize(t_wheel_cloud);
|
|
|
+// }
|
|
|
|
|
|
+ frame.mutable_measure_info()->set_x(1);
|
|
|
+ frame.mutable_measure_info()->set_y(1);
|
|
|
+ frame.mutable_measure_info()->set_width(1);
|
|
|
+ frame.mutable_measure_info()->set_wheelbase(1);
|
|
|
+ frame.mutable_measure_info()->set_error("Just test.");
|
|
|
+ m_grpc_server.ResetData(frame);
|
|
|
}
|
|
|
}
|
|
|
LOG(INFO) << "detect thread " << std::this_thread::get_id() << " closed.";
|
|
@@ -827,7 +875,7 @@ Error_manager DeviceTof3D::segFrame2CarAndWheel(VzFrame &depth_frame, std::vecto
|
|
|
VZ_ConvertDepthToPointCloud(iter->second->handle, &depthPoint, &worldV, 1, &cameraParam);
|
|
|
wheel_cloud->emplace_back(worldV.x, worldV.y, worldV.z);
|
|
|
}
|
|
|
- LOG(INFO) << wheel_cloud->size();
|
|
|
+// LOG(INFO) << wheel_cloud->size();
|
|
|
|
|
|
VzFrame &srcFrame = depth_frame;
|
|
|
const int len = srcFrame.width * srcFrame.height;
|
|
@@ -846,7 +894,7 @@ Error_manager DeviceTof3D::segFrame2CarAndWheel(VzFrame &depth_frame, std::vecto
|
|
|
}
|
|
|
delete[] worldV;
|
|
|
worldV = nullptr;
|
|
|
- LOG(INFO) << "Save point cloud successful to cloud: " << car_cloud->size();
|
|
|
+// LOG(INFO) << "Save point cloud successful to cloud: " << car_cloud->size();
|
|
|
}
|
|
|
|
|
|
// for (int i = (depth_frame.height - WINDOW_SIZE)/2, offset = i * depth_frame.width; i < (depth_frame.height + WINDOW_SIZE)/2; i++)
|
|
@@ -874,3 +922,71 @@ Error_manager DeviceTof3D::WheelCloudOptimize(pcl::PointCloud<pcl::PointXYZ>::Pt
|
|
|
Error_manager DeviceTof3D::CarPoseOptimize(pcl::PointCloud<pcl::PointXYZ>::Ptr &car_cloud) {
|
|
|
return Error_manager();
|
|
|
}
|
|
|
+
|
|
|
+Error_manager DeviceTof3D::grpcVzenseMat(JetStream::ResFrame &frame, const DeviceAzimuth &azimuth,cv::Mat &mat) {
|
|
|
+ switch (azimuth) {
|
|
|
+ case LF:
|
|
|
+ frame.mutable_images()->mutable_img1()->CopyFrom(StreamRpcServer::cvMat2JetImage(mat));
|
|
|
+ break;
|
|
|
+ case RF:
|
|
|
+ frame.mutable_images()->mutable_img2()->CopyFrom(StreamRpcServer::cvMat2JetImage(mat));
|
|
|
+ break;
|
|
|
+ case LR:
|
|
|
+ frame.mutable_images()->mutable_img3()->CopyFrom(StreamRpcServer::cvMat2JetImage(mat));
|
|
|
+ break;
|
|
|
+ case RR:
|
|
|
+ frame.mutable_images()->mutable_img4()->CopyFrom(StreamRpcServer::cvMat2JetImage(mat));
|
|
|
+ break;
|
|
|
+ default:
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ return {};
|
|
|
+}
|
|
|
+
|
|
|
+Error_manager DeviceTof3D::grpcVzensePointMat(JetStream::ResFrame &frame, const DeviceAzimuth &azimuth,cv::Mat &mat) {
|
|
|
+ switch (azimuth) {
|
|
|
+ case LF:
|
|
|
+ frame.mutable_clouds()->mutable_cloud1()->CopyFrom(StreamRpcServer::cvPointMat2JetPointCloud(mat));
|
|
|
+ LOG(INFO) << "frame.clouds().cloud1().size(): " << frame.clouds().cloud1().size();
|
|
|
+ break;
|
|
|
+ case RF:
|
|
|
+ frame.mutable_clouds()->mutable_cloud2()->CopyFrom(StreamRpcServer::cvPointMat2JetPointCloud(mat));
|
|
|
+ LOG(INFO) << "frame.clouds().cloud2().size(): " << frame.clouds().cloud2().size();
|
|
|
+ break;
|
|
|
+ case LR:
|
|
|
+ frame.mutable_clouds()->mutable_cloud3()->CopyFrom(StreamRpcServer::cvPointMat2JetPointCloud(mat));
|
|
|
+ LOG(INFO) << "frame.clouds().cloud3().size(): " << frame.clouds().cloud3().size();
|
|
|
+ break;
|
|
|
+ case RR:
|
|
|
+ frame.mutable_clouds()->mutable_cloud4()->CopyFrom(StreamRpcServer::cvPointMat2JetPointCloud(mat));
|
|
|
+ LOG(INFO) << "frame.clouds().cloud4().size(): " << frame.clouds().cloud4().size();
|
|
|
+ break;
|
|
|
+ default:
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ return {};
|
|
|
+}
|
|
|
+
|
|
|
+Error_manager DeviceTof3D::grpcCloud(JetStream::ResFrame &frame, const DeviceAzimuth &azimuth, pcl::PointCloud<pcl::PointXYZI>::Ptr &cloud) {
|
|
|
+ // 传递识别结果
|
|
|
+ switch (azimuth) {
|
|
|
+ case LF:
|
|
|
+ frame.mutable_clouds()->mutable_cloud1()->CopyFrom(StreamRpcServer::pcl2JetPointCloud(cloud));
|
|
|
+ break;
|
|
|
+ case RF:
|
|
|
+ frame.mutable_clouds()->mutable_cloud2()->CopyFrom(StreamRpcServer::pcl2JetPointCloud(cloud));
|
|
|
+ break;
|
|
|
+ case LR:
|
|
|
+ frame.mutable_clouds()->mutable_cloud3()->CopyFrom(StreamRpcServer::pcl2JetPointCloud(cloud));
|
|
|
+ break;
|
|
|
+ case RR:
|
|
|
+ frame.mutable_clouds()->mutable_cloud4()->CopyFrom(StreamRpcServer::pcl2JetPointCloud(cloud));
|
|
|
+ break;
|
|
|
+ default:
|
|
|
+ break;
|
|
|
+ }
|
|
|
+
|
|
|
+ return {};
|
|
|
+}
|
|
|
+
|
|
|
+
|