Prechádzať zdrojové kódy

1、添加识别框;

LiuZe 1 rok pred
rodič
commit
7507c918a0
2 zmenil súbory, kde vykonal 19 pridanie a 10 odobranie
  1. 6 2
      proto/def.grpc.proto
  2. 13 8
      yolo_seg_mqtt_async.cpp

+ 6 - 2
proto/def.grpc.proto

@@ -28,8 +28,12 @@ message Line{
   int32 end=2;
 }
 message SegBox{
-  float confidence = 1;
-  repeated Line lines= 2;
+  int32 x = 1;
+  int32 y = 2;
+  int32 width = 3;
+  int32 height = 4;
+  float confidence = 5;
+  repeated Line lines= 6;
 }
 message LabelYolo{
   int32 label=1;

+ 13 - 8
yolo_seg_mqtt_async.cpp

@@ -15,8 +15,8 @@ void YoloSegmentMqttAsyncClient::init(const std::string &file) {
 
 // 识别结果数据包含识别结果、时间序号、具体识别信息
 int YoloSegmentMqttAsyncClient::CloudDataArrived(void *client, char *topicName, int topicLen,
-                                           MQTTAsync_message *message) {
-    auto *tof_client = (YoloSegmentMqttAsyncClient *)client;
+                                                 MQTTAsync_message *message) {
+    auto *tof_client = (YoloSegmentMqttAsyncClient *) client;
     // TODO:测试
     std::string topic = topicName;
     if (topic == "tof/ir") {
@@ -46,19 +46,24 @@ int YoloSegmentMqttAsyncClient::CloudDataArrived(void *client, char *topicName,
             auto seg_points = tof_client->detector->getPointsFromObj(*iter);
             int device_index = (int(iter->rect.x / 640) * 0x01) | (int(iter->rect.y / 480) << 1);
             // 校验识别矩形框是否越界
-            int device_index_check = (int((iter->rect.x + iter->rect.width) / 640) * 0x01) | (int((iter->rect.y + iter->rect.height) / 480) << 1);
+            int device_index_check = (int((iter->rect.x + iter->rect.width) / 640) * 0x01) |
+                                     (int((iter->rect.y + iter->rect.height) / 480) << 1);
             if (device_index != device_index_check) {
                 // TODO:存图
                 objs.erase(iter);
                 iter--;
                 continue;
             }
-
+            int x_alpha = (device_index & 0x1);
+            int y_alpha = ((device_index & 0x2) >> 1);
+            seg_results.mutable_boxes(device_index)->set_x(iter->rect.x - x_alpha * merge_mat.cols / 2);
+            seg_results.mutable_boxes(device_index)->set_y(iter->rect.y - y_alpha * merge_mat.rows / 2);
+            seg_results.mutable_boxes(device_index)->set_width(iter->rect.width);
+            seg_results.mutable_boxes(device_index)->set_height(iter->rect.height);
             seg_results.mutable_boxes(device_index)->set_confidence(iter->prob);
             if (iter->prob > 0.6) {
+                // LOG(INFO) << device_index << ": " << iter->prob;
                 int box_contour[480][2] = {0};
-                int x_alpha = (device_index & 0x1);
-                int y_alpha = ((device_index & 0x2) >> 1);
                 for (auto &pt: seg_points) {    // use 7.5~9ms
                     pt.x -= x_alpha * merge_mat.cols / 2;
                     pt.y -= y_alpha * merge_mat.rows / 2;
@@ -70,7 +75,7 @@ int YoloSegmentMqttAsyncClient::CloudDataArrived(void *client, char *topicName,
                         box_contour[pt.y][1] = MAX(pt.x, box_contour[pt.y][1]);
                     }
                 }
-                for (auto & ends : box_contour) {
+                for (auto &ends: box_contour) {
                     auto line = seg_results.mutable_boxes(device_index)->add_lines();
                     line->set_begin(ends[0]);
                     line->set_end(ends[1]);
@@ -79,7 +84,7 @@ int YoloSegmentMqttAsyncClient::CloudDataArrived(void *client, char *topicName,
         }
 
         char data[seg_results.ByteSizeLong()];
-        seg_results.SerializeToArray((void *)data, seg_results.ByteSizeLong());
+        seg_results.SerializeToArray((void *) data, seg_results.ByteSizeLong());
         tof_client->SendMessage("tof/seg", data, seg_results.ByteSizeLong());
     }
     return 1;