소스 검색

mask float to int

syyxsxx 5 년 전
부모
커밋
9f187e9c3e
3개의 변경된 파일13개의 추가작업 그리고 6개의 파일을 삭제
  1. 2 2
      deploy/cpp/include/paddlex/results.h
  2. 10 2
      deploy/cpp/src/paddlex.cpp
  3. 1 2
      deploy/cpp/src/visualize.cpp

+ 2 - 2
deploy/cpp/include/paddlex/results.h

@@ -37,7 +37,7 @@ struct Mask {
 };
 
 /*
- * @brief 
+ * @brief
  * This class represents target box in detection or instance segmentation tasks.
  * */
 struct Box {
@@ -47,7 +47,7 @@ struct Box {
   // confidence score
   float score;
   std::vector<float> coordinate;
-  Mask<float> mask;
+  Mask<int> mask;
 };
 
 /*

+ 10 - 2
deploy/cpp/src/paddlex.cpp

@@ -11,6 +11,8 @@
 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 // See the License for the specific language governing permissions and
 // limitations under the License.
+
+#include <math.h>
 #include <omp.h>
 #include <algorithm>
 #include <fstream>
@@ -346,7 +348,10 @@ bool Model::predict(const cv::Mat& im, DetResult* result) {
       auto begin_mask =
           output_mask.begin() + (i * classes + box->category_id) * mask_pixels;
       auto end_mask = begin_mask + mask_pixels;
-      box->mask.data.assign(begin_mask, end_mask);
+      for (auto iter = begin_mask; iter != end_mask; iter++) {
+        int mask_int = floor((*iter) + 0.5);
+        box->mask.push_back(mask_int);
+      }
       box->mask.shape = {static_cast<int>(box->coordinate[2]),
                          static_cast<int>(box->coordinate[3])};
     }
@@ -520,7 +525,10 @@ bool Model::predict(const std::vector<cv::Mat>& im_batch,
         auto begin_mask = output_mask.begin() +
                           (mask_idx * classes + category_id) * mask_pixels;
         auto end_mask = begin_mask + mask_pixels;
-        box->mask.data.assign(begin_mask, end_mask);
+        for (auto iter = begin_mask; iter != end_mask; iter++) {
+          int mask_int = floor((*iter) + 0.5);
+          box->mask.push_back(mask_int);
+        }
         box->mask.shape = {static_cast<int>(box->coordinate[2]),
                            static_cast<int>(box->coordinate[3])};
         mask_idx++;

+ 1 - 2
deploy/cpp/src/visualize.cpp

@@ -86,12 +86,11 @@ cv::Mat Visualize(const cv::Mat& img,
     }
     cv::Mat bin_mask(result.mask_resolution,
                      result.mask_resolution,
-                     CV_32FC1,
+                     CV_8UC1,
                      boxes[i].mask.data.data());
     cv::resize(bin_mask,
                bin_mask,
                cv::Size(boxes[i].mask.shape[0], boxes[i].mask.shape[1]));
-    cv::threshold(bin_mask, bin_mask, 0.5, 1, cv::THRESH_BINARY);
     cv::Mat full_mask = cv::Mat::zeros(vis_img.size(), CV_8UC1);
     bin_mask.copyTo(full_mask(roi));
     cv::Mat mask_ch[3];