فهرست منبع

修改tensorrt检测代码

Jeston 1 سال پیش
والد
کامیت
a913e833c0
4فایلهای تغییر یافته به همراه32 افزوده شده و 5413 حذف شده
  1. 0 2573
      communication/communication.pb.cc
  2. 0 2824
      communication/communication.pb.h
  3. 1 4
      detect/tensorrt/wheel-detector.cpp
  4. 31 12
      vzense/device_tof3d.cpp

تفاوت فایلی نمایش داده نمی شود زیرا این فایل بسیار بزرگ است
+ 0 - 2573
communication/communication.pb.cc


تفاوت فایلی نمایش داده نمی شود زیرا این فایل بسیار بزرگ است
+ 0 - 2824
communication/communication.pb.h


+ 1 - 4
detect/tensorrt/wheel-detector.cpp

@@ -57,15 +57,12 @@ std::vector<cv::Point> TensorrtWheelDetector::getPointsFromObj(Object obj){
     int width=int(obj.rect.width);
     int height=int(obj.rect.height);
     
-    printf("mask type:%d\n",obj.boxMask.type());
     for(int i=0;i<height;++i){
         for(int j=0;j<width;++j){
-            //printf("%d    ",obj.boxMask.at<uchar>(i,j));
             if(obj.boxMask.at<uchar>(i,j)!=0){
-                ret.push_back(cv::Point(x+j,y+i));
+                ret.push_back(cv::Point((x+j),y+i));
             }
         }
     }
-    //printf("\n");
     return ret;
 }

+ 31 - 12
vzense/device_tof3d.cpp

@@ -453,6 +453,22 @@ void DeviceTof3D::receiveFrameThread(const std::string &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()) {
@@ -465,17 +481,20 @@ void DeviceTof3D::receiveFrameThread(const std::string &ip) {
                 if (getDepthFrame(ip, depthFrame) == SUCCESS) {
                     segment_results.clear();
                     if (Frame2Mat(depthFrame, depthMat) == SUCCESS) {
-                        detector->detect(depthMat, segment_results);
-                        // cv::imshow("ret", depthMat);
-                        // cv::waitKey(100);
+                        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<uchar>(pt) = 255 - depthMat.at<uchar>(pt);
+                                depthMat.at<cv::Vec3b>(pt) = cv::Vec3b(255, 255, 255) - depthMat.at<cv::Vec3b>(pt);
                             }
                             cv::imshow("ret", depthMat);
                             cv::waitKey(1);
@@ -513,14 +532,14 @@ 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>);