提交 9f187e9c 编写于 作者: S syyxsxx

mask float to int

上级 3201bc6a
......@@ -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;
};
/*
......
......@@ -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++;
......
......@@ -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];
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册