@@ -283,14 +283,16 @@ std::unique_ptr<ResultBase> SegmentationModel::postprocess(InferenceResult& infR
283283 return std::unique_ptr<ResultBase>(result);
284284}
285285
286- std::vector<Contour> SegmentationModel::getContours (const ImageResultWithSoftPrediction& imageResult) {
286+ std::vector<Contour> SegmentationModel::getContours (const ImageResultWithSoftPrediction& imageResult,
287+ bool include_nested_contours) {
287288 if (imageResult.soft_prediction .channels () == 1 ) {
288289 throw std::runtime_error{" Cannot get contours from soft prediction with 1 layer" };
289290 }
290291
291292 std::vector<Contour> combined_contours = {};
292293 cv::Mat label_index_map;
293294 cv::Mat current_label_soft_prediction;
295+ int find_contours_mode = include_nested_contours ? cv::RETR_CCOMP : cv::RETR_EXTERNAL ;
294296 for (int index = 1 ; index < imageResult.soft_prediction .channels (); index++) {
295297 cv::extractChannel (imageResult.soft_prediction , current_label_soft_prediction, index);
296298 cv::inRange (imageResult.resultImage ,
@@ -299,7 +301,7 @@ std::vector<Contour> SegmentationModel::getContours(const ImageResultWithSoftPre
299301 label_index_map);
300302 std::vector<std::vector<cv::Point>> contours;
301303 std::vector<cv::Vec4i> hierarchy;
302- cv::findContours (label_index_map, contours, hierarchy, cv:: RETR_CCOMP , cv::CHAIN_APPROX_NONE );
304+ cv::findContours (label_index_map, contours, hierarchy, find_contours_mode , cv::CHAIN_APPROX_NONE );
303305
304306 std::string label = getLabelName (index - 1 );
305307
0 commit comments