|
| 1 | +// This file is part of OpenCV project. |
| 2 | +// It is subject to the license terms in the LICENSE file found in the top-level directory |
| 3 | +// of this distribution and at http://opencv.org/license.html. |
| 4 | + |
| 5 | + |
| 6 | +#include <opencv2/core.hpp> |
| 7 | +#include <opencv2/imgproc.hpp> |
| 8 | +#include <opencv2/highgui.hpp> |
| 9 | +#include <opencv2/saliency.hpp> |
| 10 | +#include <vector> |
| 11 | +#include <string> |
| 12 | +#include <iostream> |
| 13 | +#include <fstream> |
| 14 | + |
| 15 | +using namespace std; |
| 16 | +using namespace cv; |
| 17 | +using namespace saliency; |
| 18 | + |
| 19 | + |
| 20 | +int main(int argc, char* argv[]) |
| 21 | +{ |
| 22 | + const char *keys = |
| 23 | + "{ help h usage ? | | show this message }" |
| 24 | + "{ start_frame |0 | start frame index }" |
| 25 | + "{ length |12 | # of frames video contain }" |
| 26 | + "{ default |1 | use default deep net(AlexNet) and default weights }" |
| 27 | + "{ video_name |skiing| the name of video in UCSD background subtraction }" |
| 28 | + "{ img_folder_path|JPEGS| path to folder with frames }" |
| 29 | + "{ res_level | 3 | resolution level of output saliency map. Suggested Range [0, 4]. The higher the level is, the fast the processing is, the lower the resolution is }"; |
| 30 | + |
| 31 | + CommandLineParser parser(argc, argv, keys); |
| 32 | + if (parser.has("help")) |
| 33 | + { |
| 34 | + parser.printMessage(); |
| 35 | + return 0; |
| 36 | + } |
| 37 | + vector<Mat> img_sq; |
| 38 | + DiscriminantSaliency t; |
| 39 | + if ( parser.get<bool>( "default" ) ) |
| 40 | + { |
| 41 | + t = DiscriminantSaliency(); |
| 42 | + } |
| 43 | + else |
| 44 | + { |
| 45 | + t = DiscriminantSaliency(parser.get<int>( "res_level" )); |
| 46 | + } |
| 47 | + for ( unsigned i = 1; i < parser.get<unsigned>( "length" ); i++ ) |
| 48 | + { |
| 49 | + char index[256] = {0}; |
| 50 | + sprintf(index, "%d", i + parser.get<int>( "start_frame" )); |
| 51 | + Mat temp = imread(parser.get<string>("img_folder_path") + "/" + parser.get<string>("video_name") + "/frame_" + index + ".jpg", 0); |
| 52 | + //Mat temp = imread(string("JPEGS/traffic/frame_") + index + ".jpg", 0); |
| 53 | + //resize(temp, temp, Size(127, 127)); |
| 54 | + img_sq.push_back(temp); |
| 55 | + } |
| 56 | + vector<Mat> saliency_sq; |
| 57 | + t.computeSaliency(img_sq, saliency_sq); |
| 58 | + for ( unsigned i = 0; i < saliency_sq.size(); i++ ) |
| 59 | + { |
| 60 | + resize(saliency_sq[i], saliency_sq[i], Size(1024, 768)); |
| 61 | + t.saliencyMapVisualize(saliency_sq[i]); |
| 62 | + } |
| 63 | + return 0; |
| 64 | +} //main |
0 commit comments