From 88e0f9393a175b5f10139d67edc162f5ae0c5825 Mon Sep 17 00:00:00 2001 From: Davide Sapienza Date: Tue, 3 Sep 2019 19:03:55 +0200 Subject: [PATCH] Include flag to save preprocessed images --- include/BoxDetection.h | 8 ++- src/BoxDetection.cpp | 144 ++++++++++++++++++++--------------------- 2 files changed, 77 insertions(+), 75 deletions(-) diff --git a/include/BoxDetection.h b/include/BoxDetection.h index c4b8aef..f1e985a 100644 --- a/include/BoxDetection.h +++ b/include/BoxDetection.h @@ -22,6 +22,12 @@ #include #include +#define SAVE false +#define SAVE_TO(name, fn, i, var) {sprintf(buf_frame_crop_name,name,fn,i);\ + cv::imwrite(buf_frame_crop_name, var);} + + + // cv::Mat img_threshold(cv::Mat frame_crop); // cv::Mat img_background(cv::Mat frame_crop); // cv::Mat img_dist_transform(cv::Mat frame_crop); @@ -35,4 +41,4 @@ void segmentation(cv::Mat pre_frame, cv::Mat frame_crop, int frame_nbr, int i, i //canny cv::Mat img_laplacian(cv::Mat frame_crop, int ret); -void frame_disparity(cv::Mat pre_frame, cv::Mat frame, int frame_nbr, int i, int ret); \ No newline at end of file +cv::Mat frame_disparity(cv::Mat pre_frame, cv::Mat frame, int frame_nbr, int i, int ret); \ No newline at end of file diff --git a/src/BoxDetection.cpp b/src/BoxDetection.cpp index b8310d3..0ce26bb 100644 --- a/src/BoxDetection.cpp +++ b/src/BoxDetection.cpp @@ -1,6 +1,6 @@ #include "BoxDetection.h" #include - +char buf_frame_crop_name [200]; cv::Mat img_threshold(cv::Mat frame_crop) { @@ -258,67 +258,73 @@ void image_segmentation(cv::Mat frame_crop, int frame_nbr, int i) { // Watershed Algorithm // https://docs.opencv.org/3.4/d7/d1c/tutorial_js_watershed.html - char buf_frame_crop_name [200]; + auto step_t_segmentation = std::chrono::steady_clock::now(); auto end_t_segmentation = std::chrono::steady_clock::now(); - - sprintf(buf_frame_crop_name,"../demo/demo/data/img_crop/%d_%d_imgthr.jpg",frame_nbr, i); - cv::imwrite(buf_frame_crop_name, img_threshold(frame_crop)); + cv::Mat ret; + // ret = img_threshold(frame_crop); + if(SAVE) SAVE_TO("../demo/demo/data/img_crop/%d_%d_imgthr.jpg", frame_nbr, i, img_threshold(frame_crop)); end_t_segmentation = std::chrono::steady_clock::now(); std::cout << " - TIME imgthr ("<(end_t_segmentation - step_t_segmentation).count() << " ms"<(end_t_segmentation - step_t_segmentation).count() << " ms"<(end_t_segmentation - step_t_segmentation).count() << " ms"<(end_t_segmentation - step_t_segmentation).count() << " ms"<(end_t_segmentation - step_t_segmentation).count() << " ms"<(end_t_segmentation - step_t_segmentation).count() << " ms"<(end_t_segmentation - step_t_segmentation).count() << " ms"<(end_t_segmentation - step_t_segmentation).count() << " ms"<(end_t_segmentation - step_t_segmentation).count() << " ms"<(end_t_segmentation - step_t_segmentation).count() << " ms"<(end_t_segmentation - step_t_segmentation).count() << " ms"<(end_t_segmentation - step_t_segmentation).count() << " ms"<(end_t_segmentation - step_t_segmentation).count() << " ms"<(end_t_segmentation - step_t_segmentation).count() << " ms"<(end_t_segmentation - step_t_segmentation).count() << " ms"<(end_t_segmentation - step_t_segmentation).count() << " ms"< saliencyAlgorithm; - char buf_frame_crop_name [200]; + int const_molt_mat = 0; auto step_t_segmentation = std::chrono::steady_clock::now(); auto end_t_segmentation = std::chrono::steady_clock::now(); @@ -425,9 +434,7 @@ void image_saliency(cv::Mat frame_crop, int frame_nbr, int i) cv::Mat spect_res = compute_saliency(frame_crop, saliencyAlgorithm, const_molt_mat, 0); if(!spect_res.empty()) { - sprintf(buf_frame_crop_name,"../demo/demo/data/img_crop/%d_%d_saliency_SpectralResidual.jpg",frame_nbr, i); - cv::imwrite(buf_frame_crop_name, spect_res); - + if(SAVE) SAVE_TO("../demo/demo/data/img_crop/%d_%d_saliency_SpectralResidual.jpg", frame_nbr, i, spect_res); } else { @@ -442,9 +449,7 @@ void image_saliency(cv::Mat frame_crop, int frame_nbr, int i) spect_res = compute_saliency(frame_crop, saliencyAlgorithm, const_molt_mat, 1); if(!spect_res.empty()) { - sprintf(buf_frame_crop_name,"../demo/demo/data/img_crop/%d_%d_saliency_BinarySpectralResidual.jpg",frame_nbr, i); - cv::imwrite(buf_frame_crop_name, spect_res); - + if(SAVE) SAVE_TO("../demo/demo/data/img_crop/%d_%d_saliency_BinarySpectralResidual.jpg", frame_nbr, i, spect_res); } else { @@ -460,9 +465,7 @@ void image_saliency(cv::Mat frame_crop, int frame_nbr, int i) spect_res = compute_saliency(frame_crop, saliencyAlgorithm, const_molt_mat, 0); if(!spect_res.empty()) { - sprintf(buf_frame_crop_name,"../demo/demo/data/img_crop/%d_%d_saliency_FineGrained.jpg",frame_nbr, i); - cv::imwrite(buf_frame_crop_name, spect_res); - + if(SAVE) SAVE_TO("../demo/demo/data/img_crop/%d_%d_saliency_FineGrained.jpg", frame_nbr, i, spect_res); } else { @@ -506,17 +509,16 @@ void image_saliency(cv::Mat frame_crop, int frame_nbr, int i) saliencyAlgorithm.dynamicCast()->init(); cvtColor( frame_sal, frame_sal, cv::COLOR_BGR2GRAY ); saliencyAlgorithm->computeSaliency( frame_sal, saliencyMap); - sprintf(buf_frame_crop_name,"../demo/demo/data/img_crop/%d_%d_saliency_BinWangApr.jpg",frame_nbr, i); - cv::imwrite(buf_frame_crop_name, saliencyMap); + if(SAVE) SAVE_TO("../demo/demo/data/img_crop/%d_%d_saliency_BinWangApr.jpg", frame_nbr, i, saliencyMap); + end_t_segmentation = std::chrono::steady_clock::now(); std::cout << " - TIME BING WANG APR 2014("<(end_t_segmentation - step_t_segmentation).count() << " ms"< pre_rois, int frame_nbr) @@ -562,7 +562,6 @@ void frame_box_disparity(cv::Mat pre_frame, cv::Mat frame, std::vector = frame.rows)? (frame.rows-1-r.y) : (r.height+dy+dy); // std::cout<<"disp: w "<