diff --git a/contrib/RealTimeHumanSeg/humanseg.cc b/contrib/RealTimeHumanSeg/humanseg.cc index 39eed08bc4005110188b0030ace7ddb38c1c9364..988742bee10f67f696283d5a63d5223ccc14449d 100644 --- a/contrib/RealTimeHumanSeg/humanseg.cc +++ b/contrib/RealTimeHumanSeg/humanseg.cc @@ -87,8 +87,8 @@ cv::Mat HumanSeg::Postprocess(const cv::Mat& im) { im_scoremap.convertTo(im_scoremap, CV_32FC1, 1 / 255.0); float* pblob = reinterpret_cast(im_scoremap.data); - int out_buff_len = im.cols * im.rows * sizeof(uchar); - segout_data_.resize(out_buff_len); + int out_buff_capacity = 10 * im.cols * im.rows * sizeof(float); + segout_data_.resize(out_buff_capacity); unsigned char* seg_result = segout_data_.data(); MergeProcess(im.data, pblob, im.rows, im.cols, seg_result); cv::Mat seg_mat(im.rows, im.cols, CV_8UC1, seg_result); diff --git a/contrib/RealTimeHumanSeg/humanseg_postprocess.cc b/contrib/RealTimeHumanSeg/humanseg_postprocess.cc index dec44ea4533721c15a2b896465be30c8194e392e..a373df3985b5bd72d05145d2c6d106043b5303ff 100644 --- a/contrib/RealTimeHumanSeg/humanseg_postprocess.cc +++ b/contrib/RealTimeHumanSeg/humanseg_postprocess.cc @@ -254,7 +254,7 @@ cv::Mat MergeSegMat(const cv::Mat& seg_mat, int ThresholdMask(const cv::Mat &fg_cfd, const float fg_thres, const float bg_thres, - cv::Mat fg_mask) { + cv::Mat& fg_mask) { if (fg_cfd.type() != CV_32FC1) { printf("ThresholdMask: type is not CV_32FC1.\n"); return -1; diff --git a/contrib/RealTimeHumanSeg/humanseg_postprocess.h b/contrib/RealTimeHumanSeg/humanseg_postprocess.h index 7cbac388a5daf605c0413058d31b59cdb0e14cae..f5059857c0108c600a6bd98bcaa355647fdc21e2 100644 --- a/contrib/RealTimeHumanSeg/humanseg_postprocess.h +++ b/contrib/RealTimeHumanSeg/humanseg_postprocess.h @@ -22,7 +22,7 @@ int ThresholdMask(const cv::Mat &fg_cfd, const float fg_thres, const float bg_thres, - cv::Mat fg_mask); + cv::Mat& fg_mask); cv::Mat MergeSegMat(const cv::Mat& seg_mat, const cv::Mat& ori_frame); diff --git a/contrib/RealTimeHumanSeg/main.cc b/contrib/RealTimeHumanSeg/main.cc index a430669f716b98645648ad91b16c218055a70fbe..fea3a548dd1ef556066d5985c114226f6da6dca5 100644 --- a/contrib/RealTimeHumanSeg/main.cc +++ b/contrib/RealTimeHumanSeg/main.cc @@ -41,13 +41,16 @@ int VideoPredict(const std::string& video_path, HumanSeg& seg) printf("create video writer failed!\n"); return -1; } - cv::Mat frame; while (capture.read(frame)) { + if (frame.empty()) { + break; + } cv::Mat out_im = seg.Predict(frame); video_out.write(out_im); } capture.release(); + video_out.release(); return 0; } @@ -79,10 +82,10 @@ int main(int argc, char* argv[]) { // Call ImagePredict while input_path is a image file path // The output will be saved as result.jpeg - ImagePredict(input_path, seg); + // ImagePredict(input_path, seg); // Call VideoPredict while input_path is a video file path // The output will be saved as result.avi - // VideoPredict(input_path, seg); + VideoPredict(input_path, seg); return 0; }